Reputation: 8487
.block
{
width:540px;
margin:20px;
padding:10px;
border:1px solid Gray;
}
<div id="header" class="block">
<div id="pe" class="text">
<b>Name :</b> <span>King</span><br />
<b>Surname :</b> <span>Kong</span>
</div>
<div id="area" class="text">
<span id="city">Abcs</span><b>/</b>
<span id="state">Bcsdf</span>
</div>
</div>
If u run the above code in Jsfiddle, then it shows a border around the text
and the important thing is that
the height of the block class is auto
, so it automatically adjust its height.
But the problem comes when i added the following css :
#pe
{
float:left;
}
#area
{
float:right;
}
Now the height of div.block
is not set automatically. Can anybody tell me the problem?
Upvotes: 1
Views: 149
Reputation: 539
Now You need a Clearfix for it
.clearfix:after{
clear:both;
line-height:0;
height:0;
display:block;
background-color:transparent;
border:none;
content: ".";
visibility:hidden;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
you add it like this
"<div id = "header" class="block clearfix"></div>"
Upvotes: 1
Reputation: 3216
Although a bit dirtier, you can also add something that clears both after the floated elements.
<div id="header" class="block">
<div id="pe" class="text"> ... </div>
<div id="area" class="text"> ... </div>
<div style="clear:both;"></div>
</div>
There are also cleaner "clearfix" variations of this as well, that will let you clear:both without adding non-semantic markup. http://www.positioniseverything.net/easyclearing.html
Upvotes: 0
Reputation: 13517
I would add overflow:hidden
to the containing element (#header
). That should fix it.
Upvotes: 1
Reputation: 4275
Just add overflow:hidden to class "block".
.block{
width:540px;
margin:20px;
padding:10px;
border:1px solid Gray;
overflow:hidden;
}
Here is the fiddle: http://jsfiddle.net/rWuBF/
Upvotes: 1
Reputation: 3904
That's because they're not part of the common flow of the document anymore.
The solution could be to set display: block
in the block class and then use position: absolute
to position the element within that block by using left: 0
and right: 0
Upvotes: 1
Reputation: 1990
You can use absolute positioning where by the outer element is set to height:auto and the inner #pe and #area are set to height:100%.
Have a look at this answer: How to make a floated div 100% height of its parent?
Upvotes: 1
Reputation: 8465
because float takes them out of the current flow. They are not inside the block div in the same way they where, use positioning and display:inline to get them to line up the way you want
Upvotes: 1