实例解析clear属性在CSS中的妙用

开发 前端
CSS中的属性有很多值得学习的地方,这里通过实例向大家描述一下在CSS中clear属性的妙用,相信本文介绍一定会让你有所收获。

本文和大家重点讨论一下在CSS中clear属性的妙用,这里通过实例来向大家解析,希望对你的学习有所帮助。

在CSS中clear属性妙用

在DIV+CSS设计网页中,经常需要设置多个DIV并列排列,往往是使用float:left或float:right来实现,但问题出现了,当前面并列的多个DIV总宽度不足100%,下面的的DIV就很可能向上提,和上一行的并列的DIV在同一行,这不是我们想要的结果。使用Clear属性正好可以解决这一问题,下面引用帮助的介绍:

CSS clear属性

Imageandtextelementsthatappearinanotherel  
ementarecalledfloatingelements.  
Theclearpropertysetsthesideso  
fanelementwhereotherfloatingelementsarenotallowed.  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

图片和文字元素出现在另外元素中,那么它们(图片和文字)可称为浮动元素(floatingelement)。使用clear属性可以让元素边上不出现其它浮动元素。

Note:Thispropertydoesnotalwaysworkasexpectedifitisusedalongwiththe"float"property.
注意:当这个属性随着"float"属性一起使用的话,那么结果可能会不尽如人意

Inherited:No

◆继承性:无

◆可用值

举例


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<metahttp-equivmetahttp-equiv="Content-Type"
content="text/html;charset=utf-8"/> 
<title>无标题文档title> 
<styletypestyletype="text/css"> 
.LeftText{  
margin:3px;  
float:left;  
height:180px;  
width:170px;  
border:1pxsolid#B1D1CE;  
background-color:#F3F3F3;  
}  
 
.FootText{  
height:180px;  
}  
 
.Clear  
{  
clear:both;  
}  
style> 
head> 
 
<body> 
<divclassdivclass="LeftText">区块1div> 
<divclassdivclass="LeftText">区块2div> 
<divclassdivclass="Clear">div> 
<divclassdivclass="FootText">区块3div> 
body> 
html> 
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.

 ◆代码说明:

如果没有Clear这一层,“区块3”会紧接区块2并列在同一行。

加了Clear这一层后,会把上面的浮动DIV的影响清除,使其不至影响下面DIV的布局

【编辑推荐】

  1. DIV+CSS网页布局五大误区
  2. 十大CSS使用经典技巧
  3. CSS属性font-size用法详解
  4. 探究采用DIV+CSS框架的利与弊
  5. DIV CSS网页布局需要掌握的八大技巧

 

责任编辑:佚名 来源: css3-html5.com
相关推荐

2010-09-09 16:54:05

CSSclear

2010-09-08 15:16:46

clearCSS

2010-09-10 15:16:51

CSSdisplay

2010-09-08 12:37:27

displayCSS

2010-09-09 15:08:40

CSSfloatclear

2010-09-08 11:06:49

CSSpaddingmargin

2010-08-20 14:58:26

CSSpadding

2010-09-03 10:18:06

CSSdisplay:inl

2010-08-26 09:58:01

CSS clear

2010-08-27 10:04:33

borderclearCSS

2010-09-10 09:42:37

borderclearCSS

2010-09-03 10:31:31

CSSmargin

2010-08-19 11:22:19

marginpadding

2010-08-23 11:16:25

padding-lef

2010-08-23 09:16:21

CSSpadding-bot

2010-08-16 10:18:53

DivCSS

2010-08-25 13:48:51

CSSlist-style-

2010-09-07 08:54:18

CSSbackground-

2009-09-11 13:03:48

Scope属性

2022-02-17 20:34:12

Python短路机制开发
点赞
收藏

51CTO技术栈公众号