Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically change width of Div1 inside a scrollable Div2 to Div2's width

Tags:

html

css

How to dynamically change width of Div1 inside a scrollable Div2 to Div2's width. Check this Jsfiddle http://jsfiddle.net/xdKrF/34/ You will see that the green background stops at 1 point(at default width size). I would like to make the div with the green background expand to the whole scrollable div.

Important requirement, TEXT must never be altered and must stay in 1 line.

Does anyone have a simple solution to this? Complex/hacky solution I can think of is scrollable will have 1000% width and when its not scrollable it would be default/100%. Using @media.

HTML

<div id="container" style="overflow:auto">
<div id="content">
    Well hello
</div>
<p>TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT</p>  

CSS

#content{
white-space:nowrap;
background:green;
}
like image 823
Jared Teng Avatar asked Sep 28 '22 05:09

Jared Teng


2 Answers

OK, I have found a solution.

Wrap a container and apply float:left; for it.

http://jsfiddle.net/2ugbkb6r/

like image 154
R Lam Avatar answered Oct 02 '22 07:10

R Lam


May be there is will be better answer, but it's working. Just add display:table; to #container http://jsfiddle.net/xdKrF/36/

like image 25
Ashot Khanamiryan Avatar answered Oct 02 '22 08:10

Ashot Khanamiryan