一.盒子模型
1.1
box-sizing:border-box;
————————給元素border缓溅,padding不會(huì)改變它的width,height
div{
width:200px;
height: 200px;
background: red赁温;
box-sizing: border-box;
border:10px solid black;
padding:10px;
}
二.布局
1.1.方框中插入圖片
<style>
div{
box-sizing:border-box;
}
.parent{
width:1000px;
margin-left: auto;
margin-right: auto;
background:white;
}
.parent>div{
/* display: inline-block;*/
float:left;
width:240px;
height: 300px;
border:1px solid #333;
}
.row:after{
content:"";
display:block;
clear:both;
}
.parent>.child{
margin-right: 13.3333px;
}
img{
margin-left: auto;
margin-right: auto;
display: block;
width:238px;
}
</style>
</head>
<body>
<div class="parent row">
<div class="child">
<img src="images/data_image.png"alt="">
</div>
<div class="child">
<img src="images/data_image.png"alt="">
</div>
<div class="child">
<img src="images/data_image.png"alt="">
</div>
<div></div>
<div></div>
</div>
</body>
</html>
font-size: 0坛怪;
當(dāng)使用inline-block布局,給父元素font-size:0
.parent>div------使parent樣式之后的所有div標(biāo)簽改變
.parent>.child-------使parent樣式之后的所有child樣式改變
三.導(dǎo)航條
1.1
.nav{
line-height: 50px;
background: red;
font-size: 0;
}
.nav a{
display:inline-block;
font-size: 16px;
width:100px;
vertical-align: bottom;
text-align: center;
text-decoration: none;
color:aliceblue;
}
a:hover{
background-color:pink;
}
</style>
</head>
<body>
<div class="nav">
<a href="#">手機(jī)</a>
<a href="#">商城</a>
<a href="#">個(gè)人</a>
</div>
設(shè)置div標(biāo)簽股囊,框出范圍酝陈,再設(shè)置a標(biāo)簽樣式
四.浮動(dòng)
1.1
.one{
width:100px;
height: 100px;
background: red;
float:left;
*/
}
.two{
width:200px;
height: 200px;
background: blue;
float:right;
}
.three{
width:100px;
height:100px;
background: green;
float:left
}
</style>
</head>
<body>
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
float的原理是 整個(gè)頁面漂浮起來,下面元素會(huì)被擠上去
/*clear:both; 清除float浮動(dòng)影響
且如果多個(gè)元素都一起浮動(dòng)毁涉,則多個(gè)元素處于并排顯示
且如果前面元素沒有清除浮動(dòng)沉帮,則后面元素會(huì)受到前面的影響
五.繼承
1.1
/*
父元素不設(shè)置高度,若子元素float贫堰,父元素的高度會(huì)坍塌
/*
如何讓父元素重新獲取高度
1 給父元素 overflow:hidden;
2 在浮動(dòng)元素的后面添加一個(gè)元素穆壕,清除浮動(dòng)clear:both;
3 給父元素一個(gè)公共樣式
.row:after{
content:"";
display:table;
clear:both;
}
*/
.parent{
width:400px;
background: green;
overflow: hidden
}
.child{
width:200px;
height:200px;
background: red;
float: left;
}
.two{
width:400px;
height: 400px;
background: blue;
}
/* .three{
clear:both;
}*/
.row::after{
content:"";
display:table;
clear:both;
}
</style>
</head>
<body>
<div class="parent row">
<div class="child"></div>
若子元素浮動(dòng)其屏±可給子元素套一個(gè)父元素,即overflow: hidden;
六.用li標(biāo)簽制作導(dǎo)航nav
1.1
li{
float:left;
list-style: none;
width:100px;
text-align: center;
}
.row:after{
content: "";
display: table;
clear:both;
}
a{
display: block;
color:white;
text-decoration: none;
}
ul{
line-height: 50px;
background: deeppink;
}
a:hover{
background: pink;
}
</style>
</head>
<body>
<ul class="row">
<li><a href="#">手機(jī)</a></li>
<li><a href="#">手機(jī)</a></li>
<li><a href="#">手機(jī)</a></li>
</ul>
</body>
對(duì)ul標(biāo)簽進(jìn)行設(shè)定偎行,設(shè)置范圍川背,在ul標(biāo)簽里設(shè)置li標(biāo)簽的樣式大小
其中運(yùn)用“布局”的知識(shí)贰拿。