cssclear(css中clear属性有什么用)

发布时间:2025-12-11 00:46:02 浏览次数:2

说明

1、用于规定元素哪一侧不允许浮动元素,默认值为none,表示不清除,左右两侧允许浮动元素。

2、确保当前元素的左右两侧没有浮动元素。clear只对元素本身的布局起作用。

可选值

left清除左侧浮动元素对当前元素的影响

right清除右侧浮动元素对当前元素的影响

both清除左/右两侧浮动元素对当前元素的影响

实例

<!DOCTYPEhtml><html><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equiv="X-UA-Compatible"content="ie=edge"><title>clear属性</title><style>.box1{width:200px;height:200px;background-color:cadetblue;/*设置向左浮动*/float:left;}.box2{width:400px;height:400px;background-color:crimson;float:right;}.box3{width:200px;height:200px;background-color:chartreuse;/*设置clear属性:使其位置不受左侧浮动元素的影响*//*clear:left;*//*设置clear属性:使其位置不受右侧浮动元素的影响*//*clear:right;*//*clear:both;*/}</style></head><body><p>1</p><p>2</p><p>3</p></body></html>
cssclear
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477