1

I am struggling to implement the following page layout. My entire page gets horizontal scrollbar due to the wide <div> element containing "Content". I would, instead, like to have a horizontal scrollbar only on the red <div> element that is wrapping it. I can't seem to make flexbox expand elements to the width of the page, but then to stop at the end and let the scrollbar take over the wide element overflow.

I cannot afford to set fixed widths on any of the elements.

<!-- Must maintain display: flex; -->
<div style="display: flex; flex-direction: row; height: 100%;">

   <div style="background-color: pink;">
      <div style="padding: 20px; background-color: blue;">Menu Item A</div>
      <div style="padding: 20px; background-color: purple;">Menu Item B</div>
      <div style="padding: 20px; background-color: violet;">Menu Item C</div>
   </div>

   <div style="background-color: yellow; flex-grow: 1;">
    
      <div style="margin: 20px;">
         <!-- The following red div should have horizontal scrollbar -->
         <div style="background-color: red; padding: 20px; overflow-x: auto;">
            <div style="width: 5000px; background-color: beige;">
               Content
            </div>
         </div>
      </div>
    
   </div>
</div>

Is it possible to achieve this without setting fixed widths? I would much prefer to use flexbox over tabled page layout.

1 Answer 1

2

Set the div which you don't want to have an overflow for to

overflow-x:hidden;

That should help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.