For the last two days I have read most of the questions here and much more about “filling the remaining width” and “overflow shielding: hidden”, but I can’t solve my problem. At the moment, I seriously doubt that this is possible at all.
I have a scrollable box with full body width. In addition, I have an absolute positioned title, which I need to make the same width as the scroll. I intend to make the header 0px or (if necessary) 1px in height and allow the content to overflow.
Here is the fiddle .
There is a scroll bar (always visible) in the scroll, but there is clearly no title. To compensate for this, I float the fake scroll bar to the right inside the header container, and to the left of it a <div> fills the remaining width (just like the inner scroll width).
HTML
//THE SCROLLBOX <div id="scrollbox"> <div id="center2"> content<br>content<br>... </div> </div> // THE HEADER <div id="header_box"> <div id="scroller"> <div></div> </div> // REMAINING WIDTH <div id="container"> <div id="FIRST"> <div id="FIRST_banner"></div> </div> </div> <div id="SECOND"> <div id="SECOND_banner"></div> </div> </div> </div>
CSS
#header_box { background: yellow; position: absolute; left: 0; top: 0; right: 0; height: 25px; width: 100%; overflow: visible; } #scroller { float: right; overflow-x: hidden; overflow-y: scroll; height: 50px; width: auto; } #scroller>div { width: 0px; height: 101%; } #container { display: inline; width: auto; height: 50px; overflow: visible; } #FIRST { position: relative; overflow: hidden; height: 25px; background: pink; } #FIRST_banner { position: absolute; top: 0; left: 50%; height: 220px; width: 30px; background: crimson; } #SECOND { background: darkcyan; position: relative; height: 5px; } #SECOND_banner { position: absolute; top: 0; left: 50%; height: 220px; width: 30px; background: blue; }
The problem is the div ( #FIRST ) with the remaining width . Of all the solutions that I read only with
position: relative; overflow: hidden;
works for me. It gives an exact width, aligning the center of the title and scroll well. But I can not escape from overflow: hidden , so it cuts off the content.
So, my second thought: wrap #FIRST in #container and let the child determine the width of the parent. After that, I can put another div ( #SECOND ) with the width of the parent in the container. It works partially. #container has the specified width, and the #SECOND div #SECOND very full, but accepts the #header_box width, since the width of the width itself is not set for the parent itself.
So my questions are:
- Is it possible to somehow escape from
overflow: hidden from a FIRST div? (In this case, the container and the second div can be removed). - Is there a way to allow the SECOND div to obey the width of its parent.
- Some completely different solutions.
Unfortunately, there’s a trick for all of this:
- Css only
- no javascript
- no flexbox
Thanks for any stuff.