Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set width of inner div on scrollable element to 100% of scrollable width

Tags:

html

css

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.

like image 658
magritte Avatar asked Jul 01 '13 13:07

magritte


People also ask

How do I make my Div overflow scroll?

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;.

How is scrollbar width calculated?

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.

What is scrollWidth?

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.

How do I reduce the scrollbar width in HTML?

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.


1 Answers

You can use display: table-row; for nested divs. Look at jsfiddle

like image 158
YD1m Avatar answered Oct 25 '22 19:10

YD1m