Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

100% width div gets cut off when I scroll right if my browser window is smaller than div's content

I had a problem on my own site with a <div> that is supposed to have 100% width. The code for it is shown below.

#myDiv {
    width: 100%;
    height: 160px;
    background: #f48;
}

This works great except for the following issue:

When my browser window is smaller than the <div>'s content, and I scroll to the right then my <div> will move left with the rest of the page rather than occupying 100% of the width of the page's scrollable area.

This issue has been bugging me for a few hours and just recently I realized that many other sites have the same issue. Including Facebook.com and Stackoverflow.com just take a look at my snapshots below.

Facebook's Bug:

Facebook's 100% width bug

Stackoverflow's Bug:

Stackoverflow's 100% width bug

like image 873
Web_Designer Avatar asked Jul 02 '11 02:07

Web_Designer


1 Answers

Ok, solved it! I just have to set the min-width property to the width of that <div>'s content.

Thanks anyways guys!

like image 104
Web_Designer Avatar answered Sep 26 '22 23:09

Web_Designer