
|
网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立在超文本基础之上的。超级文本标记语言之所以称为超文本标记语言,是因为文本中包含了所谓“超级链接”点。 这次给大家带来网页的布局方式之清除浮动, 清除浮动的注意事项有哪些,下面就是实战案例,一起来看一下。盒子的高度问题 1.标准流中盒子的高度可以被内容高度撑起来; 为什么要清楚浮动? 相邻的盒子之间,如果前面的盒子没有高度,那么后面盒子中的浮动元素就会去找前面盒子中的浮动元素,这样会导致界面混乱,所以需要清除浮动; 清除浮动方式一: 解决方案: 给前面一个父元素设置高度 注意点: 在企业开发中, 我们能不写高度就不写高度, 所以这种方式用得很少; CSS: <style>
*{
margin: 0;
padding: 0;
}
.box1{
height: 20px; //给前面盒子设置高度
background-color: red;
}
.box2{
background-color: green;
}
.box1 p{
width: 100px;
background-color: blue;
}
.box2 p{
width: 100px;
background-color: yellow;
}
p{
float: left;
} </style>body: <div class="box1">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p></div><div class="box2">
<p>我是文字2</p>
<p>我是文字2</p>
<p>我是文字2</p>
</div>清除浮动方式二: 解决方案: 给后面的盒子添加clear:both;属性 clear属性取值: none: 默认取值, 按照浮动元素的排序规则来排序(左浮动找左浮动, 右浮动找右浮动) 注意点: 当我们给某个元素添加clear属性之后, 那么这个属性的margin属性就会失效;所以不推荐使用 CSS: <style>
*{
margin: 0;
padding: 0;
}
body{
border: 1px solid #000;
}
.box1{
background-color: red;
}
.box2{
background-color: green;
clear: both; //给后面的盒子添加clear:both;属性
margin-top: 28px;
}
.box1 p{
width: 100px;
background-color: blue;
}
.box2 p{
width: 100px;
background-color: yellow;
}
p{
float: left;
} </style>清除浮动方式三: 解决方案: 外墙法:在两个有浮动子元素的盒子之间添加一个额外的块级元素;并且设置clear: both;属性; 注意点: 外墙法它可以让第二个盒子使用margin-top属性, CSS: <style>
*{
margin: 0;
padding: 0;
}
.box1{
background-color: red; /*margin-bottom: 10px;*/ //外墙法不可以让第一个盒子使用margin-bottom属性,
}
.box2{
background-color: green; /*margin-top: 10px;*/ //外墙法它可以让第二个盒子使用margin-top属性,
}
.box1 p{
width: 100px;
background-color: blue;
}
.box2 p{
width: 100px;
background-color: yellow;
}
p{
float: left;
}
.wall{
clear: both; //设置clear: both;属性;
}
.h20{
height: 20px; //设置额外标签的高度来实现margin效果;
background-color: skyblue;
}
</style>
<div class="box1">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p></div><div class="wall h20"></div> //外墙法:在两个有浮动子元素的盒子之间添加一个额外的块级元素;<div class="box2">
<p>我是文字2</p>
<p>我是文字2</p>
<p>我是文字2</p></div>清除浮动方式四: 解决方案: 内墙法: 注意点: 内墙法它可以让第二个盒子使用margin-top属性 <a>内墙法会自动撑起盒子的高度,所以可以直接设置margin属性</a> 外墙法和内墙法区别? 外墙法不能撑起第一个盒子的高度, 而内墙法可以撑起第一个盒子的高度 在企业开发中<a>不常用隔墙法</a>来清除浮动 (隔墙法:外墙法和内墙法) CSS: <style>
*{ margin: 0; padding: 0;
} .box1{ background-color: red; /*margin-bottom: 10px;*/
} .box2{ background-color: green; /*margin-top: 10px;*/
} .box1 p{ width: 100px; background-color: blue;
} .box2 p{ width: 100px; background-color: yellow;
} p{ float: left;
} .wall{ clear: both;
} .h20{ height: 20px; background-color: skyblue;
} </style></head>
<div class="box1">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p>
<div class="wall h20"></div> //设置内墙</div><div class="box2">
<p>我是文字2</p>
<p>我是文字2</p>
<p>我是文字2</p></div>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章! 推荐阅读: 以上就是 网页的布局方式之清除浮动的详细内容,更多请关注php中文网其它相关文章! 网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。 |
温馨提示:喜欢本站的话,请收藏一下本站!