How do I get the width of this inner content div to be equal to the width of the scrollable area?
<div class="scrollable">
<div class="content">short</div>
<div class="content">very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</div>
</div>
with CSS:
.scrollable {
width: 300px;
height: 300px;
overflow: auto;
}
.content {
background-color: lightblue;
white-space: nowrap;
}
jsFiddle: http://jsfiddle.net/XBVsR/12/
PROBLEM: if you scroll across you can see that the background does not go all the way across as it should.
I've tried setting width: 100%, overflow: visible, etc, to no avail.
EDIT: I've updated to make clear that I don't want the text to wrap - I want the horizontal scroll on the whole thing.
Making a div vertically scrollable is easy by using CSS overflow property. There are different values in overflow property. For example: overflow:auto; and the axis hiding procedure like overflow-x:hidden; and overflow-y:auto;.
To get the width of the scrollbar, you use the offsetWidth and clientWidth of the Element : The offsetWidth returns the width of the Element in pixels including the scrollbar. The clientWidth returns the with of the Element in pixels without the scrollbar.
scrollWidth read-only property is a measurement of the width of an element's content, including content not visible on the screen due to overflow. The scrollWidth value is equal to the minimum width the element would require in order to fit all the content in the viewport without using a horizontal scrollbar.
scrollbar-width accepts the following values: auto is the default value and will render the standard scrollbars for the user agent. thin will tell the user agent to use thinner scrollbars, when applicable. none will hide the scrollbar completely, without affecting the element's scrollability.
You can use display: table-row;
for nested divs. Look at jsfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With