redarrow
Expert Member
- Joined
- Dec 30, 2005
- Messages
- 2,411
This is really giving me a headache, basically viewing the code below, I cannot understand why div2 breaks out of div1? 
Div2 not only breaks out of div 1, but it also expands beyond the end of browsers window.
I've tried using "width: auto;" for either one or the other, but cannot get the desired result that way either.
What I want: div1 should expand to the maximum window width and div2 should expand to the maximum width it can without breaking out of div1. In other words it should have a spacing of 10px all around as specified in div1's padding..
My understanding was that a floated element will not break out of a parent element which is also floated - am I wrong?
Any ideas on what I'm doing incorrectly or how to get the result I'm looking for?
Thanks.
Code:
<html>
<head>
<title>Bla bla bla</title>
<style type="text/css">
.div1 {
float: left;
width: 100%;
padding: 10px;
border: 1px solid red;
}
.div2 {
float: left;
width: 100%;
padding: 10px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div class="div1">
Some stuff, bla bla bla
<div class="div2">
More stuff
</div>
</div>
</body>
</html>
I've tried using "width: auto;" for either one or the other, but cannot get the desired result that way either.
What I want: div1 should expand to the maximum window width and div2 should expand to the maximum width it can without breaking out of div1. In other words it should have a spacing of 10px all around as specified in div1's padding..
My understanding was that a floated element will not break out of a parent element which is also floated - am I wrong?
Any ideas on what I'm doing incorrectly or how to get the result I'm looking for?
Thanks.