Reputation: 4007
So I don't want any horisontal scrollbars but I want the div to fill 100% of it's parent. The code works in FF and IE8 but not for IE7 and below. How can I solve this preferably with CSS only?
<html>
<body>
<div style="width:100%; overflow:auto; height:200px;">
<div style="width:100%; height:400px; background:red;">
</div>
</div>
</body>
</html>
Doctype is set to Transitional
Upvotes: 1
Views: 2472
Reputation: 966
The second div
automatically uses border, which contains 2px
:
<div style="width:100%; border:none; height:400px; background:red;">
Upvotes: 0
Reputation: 21209
I think this sounds too simple, but you could set the height
to 100%
:
<div style="width:100%; height:100%; background:red;">
Upvotes: 2
Reputation: 10635
A div will automatically fill the width of it's parent unless specified otherwise.
Strip out the inner width style and the problem will go away.
<html>
<body>
<div style="width:100%; overflow:auto; height:200px;">
<div style="height:400px; background:red;">
</div>
</div>
</body>
</html>
On a side note. Unless you're building an email you really should be assigning style in an external css file.
Upvotes: 3