CSS Containing Floats
ÔÎÄÍøÖ·£ºhttp://www.complexspiral.com/publications
Containing Floats
As powerful and useful as they are, floats can make for tricky layout tools. Chances are that you may have seen something like the situation shown in Figure 1, which is accomplished with just two div elements, each with a floated image inside it.
Figure 1. That's not right!
This is probably not what the author had in mind, but given the styles used, it's the correct layout. Here's how we created it:
div.item {border: 1px solid; padding: 5px;}
div.item img {float: left; margin: 5px;}
That's all it takes. The result seen in Figure 1 happens because the div elements don't "stretch" to contain the floated images within them. To look at the situation from the reverse angle, it happens because the floated images "stick out" of the bottom of the div elements.
This is not a bug. It's also not a flaw in CSS. It is, in fact, the behavior that most authors will want most of the time. It's just not what they would want in the example shown in Figure 1.
Understanding the Problem
So when in the name of all that's good and right would authors want floats to stick out of their containing elements? Simple: in what is historically the most common case for float use. Consider Figure 2, and the basic markup structure that produced it.
Figure 2. Floating an image, flowing the text.
<p>
...text...
<img src="jul31-03-sm.jpg" height="200" border="0" class="picture">
...text...
</p>
<p>
...text...
</p>
The practice of flowing text around an image goes back a long, long time. That's why the ability was added to the Web starting with Netscape 1.1, and why CSS makes it possible using the property float.[1] But look closely at Figure 2. The floated image is sticking out of its containing element. We can see this more clearly by adding borders to the paragraphs, as shown in Figure 3.
Figure 3. Adding borders to the paragraphs.
So now we can se
Ïà¹ØÎĵµ£º
Èç¹ûÁé»îÓ¦ÓÃCSS¸÷ÖÖÂ˾µµÄÌص㲢¼ÓÒÔ×éºÏ£¬ÎÒÃÇ¿ÉÒԵõ½Ðí¶àÒâÏë²»µ½µÄЧ¹û¡£ÕâÊÇһЩЧ¹ûʾ·¶£¬¹©¸÷λ²Î¿¼¡£
ÍøÒ³ÌØЧAbc
ÓÃblurÂ˾µ×ö³öµÄЧ¹û£¬´úÂëÈçÏ£º
FILTER: blur(direction=135,strength=8)
ÍøÒ³ÌØЧAbc
ÓÃdropshadowÂ˾µ×ö³öµÄЧ¹û£¬´úÂëÈçÏ£º
FILTER: dropshadow(color=#B4BBCF,offx=6,offy=6,positi ......
¼ä϶ÊôÐÔÊÇÓÃÀ´ÉèÖÃÔªËØÄÚÈݵ½ÔªËر߽çµÄ¾àÀë¡£°üÀ¨£º
1£©×ó¼ä϶ÊôÐÔ£¨padding-left£©
Õâ¸öÊôÐÔÓÃÀ´É趨×ó¼ä϶µÄ¿í¶È¡£ÀýÈ磺
.d1{padding-left:1cm}
2£©ÓÒ¼ä϶ÊôÐÔ£¨padding-right£©
Õâ¸öÊôÐÔÓÃÀ´É趨ÓÒ¼ä϶µÄ¿í¶È¡£ÀýÈ磺
.d1 {padding-right:1cm}
3£©Éϼä϶ÊôÐÔ£¨padding-top£©
Õâ¸öÊôÐÔÓÃÀ´É趨Éϼä϶µÄ¿í¶È¡£À ......
<div class="llist" >
<div class="lbar">¶¨ÏòÓªÏú</div>
<ul class="lbox01" style="height: auto;min-height: 100px;">
<c:forEach var="item" items="${marketInfos.results}">
<li><div style="overflow:hidden; text-overfl ......
IE6 IE7 IE8 Firefox Opera Google
·¶Àý
>
Y
Y
N
N
N
N
.type { >color: #F00; }
.
Y
Y
N
N
N
N
.type { .color: #F00; }
*
Y
Y
N
N
N
N
.type { *color: #F00; }
_
Y
N
N
N
N
N
.type { _color: #F00; }
!important
N
Y
Y
Y
......
<div style="padding-top:5px;width:200px;height:15px;background-color:#ffeeee"> test </div>
ÒÔÉÏ´úÂëÔÚIEÖкÍfirefox»áÓв»Í¬µÄЧ¹û.×îÖ÷ÒªÔÒòÊÇfirefox½âÊÍpadding-topÓëIEµÄЧ¹û²»Í¬
fixfox¶ÔDIV×ܸ߶ÈÊÇpadding-top+heightµÄ,¶øIEÖÐ,padding-topÊÇ°üº¬ÔÚheightÖеÄ,
Òª½â¾öÕâÒ»¸öì¶Ü,¿ÉÒÔÀûÓÃ!imp ......