clear:left;表示左侧不能有浮动元素。

  clear:right;表示右侧不能有浮动元素。
  clear:both;表示左右两侧都不能有浮动元素。

  但在使用时,还得考虑css优先级问题。相同类型选择器制定的样式,在样式表文件中,越靠后的优先级越高 。

  当所有元素的clear属性都设为right时,由于优先级的原因,并不是所想的那样:右侧没有浮动元素,而是右侧出现了浮动元素。

  比如下面的代码:

  
<html>
<head>
<style type="text/css">

.div1
{
height:40px;
width:40px;
background-color:red;
position:releative;
float:left;
clear:right;
}
.div2
{
height:40px;
width:40px;
background-color:green;
position:relative;
float:left;
clear:right;
}
.div3
{
height:40px;
width:40px;
background-color:yellow;
position:relative;
float:left;
clear:right;
}
.div4
{
height:40px;
width:40px;
background-color:black;
position:relative;
float:left;
clear:right;
}
.div5
{
height:40px;
width:40px;
background-color:blue;
position:relative;
float:left;
clear:right;
}
</style>
</head>

<body>
<div class="div1">
</div>
<div class="div2">
</div>
<div class="div3">
</div>
<div class="div4">
</div>
<div class="div5">
</div>
</body>

</html>
clear-right

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2020-11-07
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-10
  • 2021-09-23
  • 2021-10-20
  • 2022-12-23
  • 2022-01-05
  • 2021-07-31
相关资源
相似解决方案