css clear属性怎样用?
clear 属性划定元素的哪一侧不许可其他浮动元素。
语法:
clear:left|right|both|none|inherit;
属性值:
● left:在左侧不许可浮动元素。
● right:在右侧不许可浮动元素。
● both:在摆布两侧均不许可浮动元素。
● none:默认值。许可浮动元素涌现在两侧。
● inherit:划定应当从父元素继续 clear 属性的值。
申明:
clear 属性定义了元素的哪边上不许可涌现浮动元素。在 CSS1 和 CSS2 中,这是经由过程自动为消灭元素(即设置了 clear 属性的元素)增添上外边距完成的。在 CSS2.1 中,会在元素上外边距之上增添消灭空间,而外边距自身并不转变。
不管哪种转变,终究效果都一样,假如声明为左侧或右侧消灭,会使元素的上外边框边境刚好在该边上浮动元素的下外边距边境之下。
解释:一切主流浏览器都支撑 clear 属性。任何版本的 Internet Explorer (包含 IE8)都不支撑属性值 "inherit"。
css clear属性 示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> img { float:left; } p.clear { clear:both; } </style> </head> <body> <img src="logocss.gif" width="95" height="84" /> <p>This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p> <p>This is also some text. This is also some text. This is also some text. This is also some text. This is also some text.</p> <br> <p>运用clear:both消灭浮动:</p> <img src="logocss.gif" width="95" height="84" /> <p>This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p> <p class="clear">This is also some text. This is also some text. This is also some text. This is also some text. This is also some text. </p> </body> </html>
效果图:
以上就是css clear属性怎样用的细致内容,更多请关注ki4网别的相干文章!