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

  其中:class优先级关系: div5>div4>div3>div2>div1

  所以,呈现出下图情况:

  

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

  比如下面的代码:

<html>
<head>
<style type="text/css"> .div1
{
height:40px;
width:40px;
background-color:red;
position:releative;
float:left;
clear:left;
}
.div2
{
height:40px;
width:40px;
background-color:green;
position:relative;
float:left;
clear:left;
}
.div3
{
height:40px;
width:40px;
background-color:yellow;
position:relative;
float:left;
clear:left;
}
.div4
{
height:40px;
width:40px;
background-color:black;
position:relative;
float:left;
clear:left;
}
.div5
{
height:40px;
width:40px;
background-color:blue;
position:relative;
float:left;
clear:left;
}
</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-left

  其中:class优先级关系: div5>div4>div3>div2>div1 。

  所以,呈现出下图情况:

  我有时偶尔还是会绕晕。。反正,了解了css优先级问题,就容易理解了。

对css中clear元素的理解的更多相关文章

  1. HTML和CSS设置动态导航以及CSS中伪元素的简单说明

    HTML页面代码: <!DOCTYPE html> <html> <head> <title>Test</title> <meta c ...

  2. tomcat的配置文件server.conf中的元素的理解

    tomcat的配置文件server.conf中的元素的理解 tomcat作为一个servlet服务器本身的配置文件是tomcat_home/conf/server.conf,这个配置文件中有很多元素, ...

  3. CSS中的元素分类

    CSS中的元素分类 元素是文档结构的基础,在CSS中,每个元素生成了一个包含了元素内容的框(box,也译为"盒子").但是不同的元素显示的方式会有所不同,例如<div> ...

  4. CSS中盒模型的理解

    今天突然看到一篇关于CSS中盒模型的文章,忽然觉得自己竟然遗忘了很多小的地方,所以写一篇文章来记忆一下 (摘抄于千与千寻写的CSS盒子模型理解,并在自己基础上添加了一些东西,希望更完善,对大家有帮助) ...

  5. CSS中box-sizing属性的理解与部分用法

    今天看了一些关于box-sizing的一些资料,在这里整理一下,希望也能对大家有所帮助. box-sizing是CSS的一个属性,很好的解决了盒模型的相关问题.CSS中的盒模型(Box model)分 ...

  6. css中clear属性的认识

    今天在看博客园的页面布局时发现有不少空白的div只有css属性:clear:both. 然后去W3C文档里和百度补脑了一下,总结如下: 这是之前我写的一段测试代码: <div style=&qu ...

  7. 关于CSS中的元素定位

    ---恢复内容开始--- CSS 定位和浮动 CSS 为定位和浮动提供了一些属性,利用这些属性,可以建立列式布局,将布局的一部分与另一部分重叠,还可以完成多年来通常需要使用多个表格才能完成的任务. 定 ...

  8. CSS中设置元素的圆角矩形

    圆角矩形介绍 在CSS中通过border-radius属性可以实现元素的圆角矩形. border-radius属性值一共有4个,左上.右上.左下.右下. border-radius属性值规则如下:第一 ...

  9. CSS中 隐藏元素的常用方法

    在CSS中,使某个元素在页面中消失的方法有很多,今天为大家介绍几种我常用的方式 . 一.display:none;   让元素直接从页面消失,不占用尺寸,会改变页面布局. 代码演示: 页面演示:在页面 ...

随机推荐

  1. CCF关于NOIP2014复赛报名的通知

    CCF关于NOIP2014复赛报名的通知   CCF NOIP2014复赛全部实行网上注册.报名.未通过网上报名的选手将不具备参赛和申诉资格. 系统注册须知: NOIP2014复赛注册时间:2014年 ...

  2. 除了白名单外的IP每秒最多处理 8 个请求 limit_conn_zone

    防止黑客知道你的源服务器真实IP进行并发攻击,通常只需要保护动态文件请求,�php. 添加文件 nginx/conf/limit/whiteip.conf 里面是你要忽略限制的 白名单 IP地址,通常 ...

  3. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  4. swift 2.x学习笔记(二)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p2 { margin: 0.0px 0. ...

  5. javaWeb中servlet开发(4)——servlet跳转

    servlet跳转 1.跳转类型 客户端跳转:跳转后地址栏改变,无法传递request范围内属性,是在所有的操作都执行完毕之后才发生跳转的操作,跳转语法是,response.sendRedict() ...

  6. http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluster.html

    http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluste ...

  7. py操作mysql

    1.操作mysql的标准流程 import pymysql conn = pymysql.connect(host = "127.0.0.1", port = 3306,user ...

  8. TCP/IP协议 三次握手与四次挥手

    一.TCP报文格式 TCP/IP协议的详细信息参看<TCP/IP协议详解>三卷本.下面是TCP报文格式图: 图1 TCP报文格式 上图中有几个字段需要重点介绍下:        (1)序号 ...

  9. IEnumerable和IEnumerator

    概述 IEnumerable和IEnumerator接口存在的意义:用来实现迭代的功能! public interface IEnumerable { IEnumerator GetEnumerato ...

  10. MySQL学习笔记——ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) Enter password: E ...