您好,欢迎访问一九零五行业门户网

css clear属性怎么用

css clear属性指定元素的左侧或右侧上不允许出现浮动元素。可用于实现浮动的清除,解决浮动布局带来的一些问题。
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属性怎么用的详细内容。
其它类似信息

推荐信息