Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎĵµ£º

¡¾Õª×ÔÍøÒײ©¿Í¡¿FireFoxÓëIEÖÐCSS¼æÈݼ¼Êõ¼¯ÃàÕûÀí

1.cssÔÚ²»Í¬ä¯ÀÀÆ÷ÏÂÏÔʾЧ¹û²»Í¬
firefoxºÍIE¶ÔijЩcssÑùʽµÄÈ϶¨Óв»ÉÙÇø±ð£¬°üÀ¨£º
·                            ulºÍolµÄĬÈÏpaddingÖµÊDz»Ò»ÑùµÄ£¬ÔÚFirefoxÖУ¬ ......

css:padding

¼ä϶ÊôÐÔÊÇÓÃÀ´ÉèÖÃÔªËØÄÚÈݵ½ÔªËر߽çµÄ¾àÀë¡£°üÀ¨£º
1£©×ó¼ä϶ÊôÐÔ£¨padding-left£©
Õâ¸öÊôÐÔÓÃÀ´É趨×ó¼ä϶µÄ¿í¶È¡£ÀýÈ磺
.d1{padding-left:1cm}
2£©ÓÒ¼ä϶ÊôÐÔ£¨padding-right£©
Õâ¸öÊôÐÔÓÃÀ´É趨ÓÒ¼ä϶µÄ¿í¶È¡£ÀýÈ磺
.d1 {padding-right:1cm}
3£©Éϼä϶ÊôÐÔ£¨padding-top£©
Õâ¸öÊôÐÔÓÃÀ´É趨Éϼä϶µÄ¿í¶È¡£À ......

³¬¼¶Î޵и÷ÖÖä¯ÀÀÆ÷css hack

.styleName{
color
:
#FFF
;
/* FF,OP,IE8 */
[
;
color:
#0F0
;
]
/* Sa,CH */
*
color
:
#FF0
;
/* IE7 */
_color:
#F00
;
/* IE6 */
}
.styleName{
background-color
:
#332200
;
/* FF*/
}
html*
.styleName{
background-color
:
#FF00FF
;
/* Sa IE7 CH */
}
*+
html .style ......

ÔÚfirefoxÓëIEÏÂDIV+CSS PaddingЧ¹û²»Í¬µÄ½â¾ö·½·¨

<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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ