Clear both 的妙用
来源:互联网 发布:宜家代工工厂淘宝 编辑:程序博客网 时间:2024/03/29 13:01
在DIV + CSS设计网页中,经常需要设置多个DIV并列排列,往往是使用float:left或float:right来实现,但问题出现了,当前面并列的多个 DIV总宽度不足100%,下面的的DIV就很可能向上提,和上一行的并列的DIV在同一行,这不是我们想要的结果。使用Clear属性正好可以解决这一问题,下面引用帮助的介绍:
CSS clear属性
Image and text elements that appear in another element are called floating elements. The clear property sets the sides of an element where other floating elements are not allowed.
图片和文字元素出现在另外元素中,那么它们(图片和文字)可称为浮动元素(floating element)。使用clear属性可以让元素边上不出现其它浮动元素。
Note: This property does not always work as expected if it is used along with the "float" property.
注意: 当这个属性随着"float"属性一起使用的话,那么结果可能会不尽如人意
Inherited: No
继承性: 无
可用值
不允许元素左边有浮动的元素rightNo floating elements allowed on the right side
不允许元素的右边有浮动的元素bothNo floating elements allowed on either the left or the right side
元素的两边都不允许有浮动的元素noneAllows floating elements on both sides
允许元素两边都有浮动的元素
举例
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <style type="text/css">
- .LeftText{
- margin: 3px;
- float: left;
- height: 180px;
- width: 170px;
- border: 1px solid #B1D1CE;
- background-color: #F3F3F3;
- }
- .FootText{
- height: 180px;
- }
- .Clear
- {
- clear:both;
- }
- </style>
- </head>
- <body>
- <div class="LeftText">区块1</div>
- <div class="LeftText">区块2</div>
- <div class="Clear"></div>
- <div class="FootText">区块3</div>
- </body>
- </html>
代码说明:
如果没有Clear这一层,“区块3”会紧接区块2并列在同一行。
加了Clear这一层后,会把上面的浮动DIV的影响清除,使其不至影响下面DIV的布局
- Clear both 的妙用
- clear:both 的妙用
- CSS 的 clear:both;
- clear:both的认知
- clear:both的理解
- clear:both的理解
- clear:both的理解
- clear:both的理解
- clear:both 的作用
- clear:both的理解
- clear both 的用法
- clear:both的理解
- clear:both的用法
- clear:both 的作用
- clear:both 的使用
- clear:both
- clear:both
- clear both
- mapinfo自定义符号文件的存放位置
- MyBatis经典入门实例
- 特权级在保护模式下的应用
- 浅析如何使用字符串流进行格式转换
- 特权级在保护模式下的应用
- Clear both 的妙用
- 博文视点大讲堂第33期——如何让你既能干得漂亮又说得清楚?
- 我们要永远在一起
- 今天开始研究用VC开发ocx
- 函数返回对象
- DELPHI调试程序出现“探测到调试器 - 请关闭后重启”
- asp.net中用C#生产验证码
- Windows 7 Media Center 在大陆开通“互联网视频”(上)
- Windows7 看互联网视频的常见问题