Reputation: 5580
Ok So the title is kind've confusing but this is my set up.
<div id="leftPanel">
// blah blah
</div>
<div id="rightPanel">
// blah blah
</div>
I am floating the rightPanel next to the Left Panel. When I apply a background CSS to rightPanel it flows through and also applies to leftPanel. Why is this? Is it because I haven't defined widths? When I do define widths, it behaves as if float-left wasn't in place.
#leftPanel {
float: left;
}
#rightPanel {
background: blue;
}
Upvotes: 0
Views: 28
Reputation: 9923
Right you have an div
with no defined width
this is going to stretch 100% of the window width (by default).
<div id="rightPanel">
// blah blah
</div>
#rightPanel {
background: blue;
}
So what's going to happen when you float a div
in front of it? The floated div
is going to allow the next div
to sit on the same line as it.
<div id="leftPanel">// blah blah</div>
<div id="rightPanel">// blah blah</div>
#leftPanel {
float: left;
}
#rightPanel {
background: blue;
}
Here you can see that the floated div
is just sitting there and the background on the other div
is not 100% any more due to the width we have now given it.
<div id="leftPanel">// blah blah</div>
<div id="rightPanel">// blah blah</div>
#leftPanel {
float: left;
}
#rightPanel {
background: blue;
width: 32px;
}
I would recommend taking a look at this to find more out about how floats works.
Upvotes: 1