Home > 网站建设 > CSS页面中clear:both

CSS页面中clear:both

clear:both;
CSS手册上这样解释的:该属性的值指出了不允许有浮动对象的边。
这个属性是用来控制float属性在文档流的物理位置的。

当属性设置float(浮动)时,他所在的物理位置已经脱离文档流了,但是大多时候我们希望文档流能识别float(浮动),或者是希望float(浮动)后面的元素不被float(浮动)所影响,这个时候我们就需要用clear:both;来清除clear:both;

<div style="float:left;width :200px;height:300px;border:1xp red solid;">这个是第1列,</div>
<div style="float:left;width :400px;height:200px;border:1xp red solid;">这个是第2列,</div>
<div style="border:1px green solid;height:200px;width:180px;">这个是列的下面。</div>

===========================================
如果不用清除浮动,那么第3个的文字框架,就会和第一二行在一起 所以我们在第3个这利加一个清除浮动。

<div style="float:left;width :200px;height:300px;border:1xp red solid;">这个是第1列,</div>
<div style="float:left;width :400px;height:200px;border:1xp red solid;">这个是第2列,</div>
<div style="border:1px green solid;clear:both;height:200px;width:180px;">这个是列的下面。</div>

Categories: 网站建设 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).