I've tried this seven ways from sunday and I keep coming up short.
Bands of color or what have you that extend to the limits of the visible page seem to be a very common request in internet forums / blogs, however for each of the two main scenarios I'm running into equally frustrating issues that render either solution untenable. In my frustration I've turned here.
HTML
<body>
<div class="container"></div>
<div class="content-container">
<div class="content">
Hello, I need some text that extends for a bit, so I'll just write this in the div and all will be good.
</div>
</div>
<div class="container"></div>
Scenario 1 You set a container div at width: 100% and then a child div at a fixed width and margin: 0 auto; this effectively extends that div to the ends of the visibel screen at all times.
html, body {
width: 100%;
}
.container {
height: 20px;
background-color: #377ab7;
margin: 0 auto;
}
.content-container {
height: 100px;
margin: 0 auto;
}
.content {
width: 300px;
}
Scenario 1 issue When the screen is resized so that the child div's fixed width is too big for the window a scroll bar appears. This is absolutely fine and desired, however when you use the scroll bar the extended bands of color only extend as far as 100% of the visible window.
Fiddle 1 (you need to resize the browser window to surpase the size of the fixed width content div and then use the scroll bar, you'll see the blue bands do not extend past 100% of the window size.) https://jsfiddle.net/b1dht69u/2/
Scenario 2 You set the overflow-x: hidden on the body and then run a very high negative margin, with a corresponding positive padding.
body {
overflow-x: hidden;
}
.container {
height: 20px;
background-color: #377ab7;
margin: 0 -9999px;
padding: 0 9999px;
}
.content-container {
height: 100px;
margin: 0 -9999px;
padding: 0 9999px;
}
.content {
width: 300px;
}
This is absolutely great until again you try to resize the screen.
Scenario 2 issue When you resize past the size of a child div's fixed width no scroll bar appears.
Fiddle 2 https://jsfiddle.net/mnodvLvg/1/
What I am looking for is the best of both worlds. I am hoping to have a bar of color that extends to the ends of the visible page at all times, yet when a browser is resized past an inner divs fixed width a scroll bar appears.