手机
当前位置:查字典教程网 >网页设计 > Div+Css教程 >css clear之清除区域
css clear之清除区域
摘要:代码如下:*{margin:0;padding:0;}p{border:1px#66CC00solid;}img{width:40px;he...

 代码如下:

<style type="text/css"> 
*{margin:0;padding:0;} 
p{border: 1px #66CC00 solid;} 
img { 
width:40px; 
height:40px; 
float:left; 
border: 1px #66CC00 solid; 

h3{ 
clear:both; 
border: 1px #66CC00 solid; 

div{padding:20px;width:400px;height:400px;} 
</style> 
</head> 
<body> 
<div> 
<p>我在上面</p> 
<img src="QQ截图未命名.png" /> 
<h3>我在下面</h3> 
</div> 


效果: 


css clear之清除区域1


为h3设置margin-top试试: 

代码如下:

h3{ 
clear:both; 
border: 1px #66CC00 solid; 
margin-top:30px; 


来看看效果: 


css clear之清除区域1


没有变化,清除区域在起作用了,改变一下: 

代码如下:

h3{ 
clear:both; 
border: 1px #66CC00 solid; 
margin-top:60px; 


效果: 


css clear之清除区域2


有了16px的间距了,我们可以理解这个margin是相对于“我在上面”计算的,其实是这个清除区域在作怪,我们可以简单的设置一下: 

代码如下:

<style type="text/css"> 
*{margin:0;padding:0;} 
p{border: 1px #66CC00 solid;} 
img { 
width:40px; 
height:40px; 
float:left; 
border: 1px #66CC00 solid; 
margin-bottom:20px; 

h3{ 
clear:both; 
border: 1px #66CC00 solid; 

div{padding:20px;width:400px;height:400px;} 
</style> 
</head> 
<body> 
<div> 
<p>我在上面</p> 
<img src="QQ截图未命名.png" /> 
<h3>我在下面</h3> 
</div> 


效果:


css clear之清除区域3


效果理想!

为浮动元素设置外边距,而不为“我在下面”(清除元素)设置上外边距,问题就解决了!

【css clear之清除区域】相关文章:

div中class与id的区别及应用

完全css弹出菜单

css代码格式化清理工具

css清除浮动方法和代码

DIV背景图片在Firefox下不显示通过overflow:auto可解决

文字环绕图片的布局效果

css3 border-image使用说明

css书写技巧

css3学习心得分享

用CSS实现段落前面缩进两个字

精品推荐
分类导航