>### float
~~~
目的:為了讓元素并排顯示
~~~
#### 1.子元素float,父元素的高度會坍塌


#### 2.如何清除float
(1)給下面的兄弟元素給clear:both;
(2)給父級加overflow:hidden;
~~~
.parent{
width:200px;
background: red;
overflow: hidden;
}
.child{
width:50px;
height:50px;
background: blue;
float: left;
}
~~~
~~~
<style>
/* 如何讓下面元素不受上面浮動元素的影響
1.clear:both;
2.給float元素父元素設置overflow:hidden
*/
.parent>div {
width: 100px;
height: 100px;
float: left;
}
.one {
background: red;
}
.two {
background: blue;
}
.three {
background: pink;
}
.four {
width: 200px;
height: 200px;
background: gray;
/* 清除float
clear: both; */
}
.parent{
overflow: hidden;
}
</style>
</head>
<body>
<!--
float目的 讓元素并排顯示
-->
<div class="parent">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<p class="four"></p>
</body>
~~~
demo實現導航
~~~
<style>
*{margin:0;padding:0}
.nav{
overflow: hidden;
line-height: 50px;
background: pink;
}
a{
display: block;
float: left;
text-decoration: none;
width: 100px;
text-align: center;
color: #fff;
}
a:hover{
color: green;
border-bottom: 2px solid blue;
}
</style>
</head>
<body>
<div class="nav">
<a href="#">手機</a>
<a href="#">平板</a>
<a href="#">電腦</a>
</div>
</body>
</html>
~~~

內聯塊也可以實現導航,但是有缺點,不推薦使用
~~~
<style>
*{margin:0;padding:0}
.nav{
line-height: 50px;
background: pink;
}
a{
display:inline;
text-decoration: none;
width: 100px;
text-align: center;
color: #fff;
}
a:hover{
color: green;
border-bottom: 2px solid blue;
}
</style>
</head>
<body>
<div class="nav">
<a href="#">手機</a>
<a href="#">平板</a>
<a href="#">電腦</a>
</div>
</body>
~~~
- html-css
- 第一節 外部樣式表
- 第二節 元素選擇器
- 第三章 盒子模型
- 第四章 html標簽的分類
- 第五章 css選擇器
- 第六章 權重
- 第七章 css基本樣式
- 第一節 背景
- 第二節 文本
- 第三節 字體
- 第四節 鏈接
- 第五節 列表(針對ul)
- 第六節 邊框
- 第七節 簡單表格
- 第八節 nvvm
- 第九節 跨越列的表格
- 第十節 跨越行的表格
- 第十一節 有間隔的表格
- 第十二節 opacity透明度
- 第八章 css樣式的繼承
- 進階教程
- 1.flex教程
- flex補充1
- flex補充2
- 2.grid布局
- css
- 第一節 box-sizing
- 第二節 float
- 第三節 position
- 第四節 導航欄
- iconfont的使用
- 第五節 搜索功能的實現