盒子模型及案例
padding:加上内边距Padding其实是撑开盒子
div {
height:20px;
width:20px;
padding-left:10px;
}
这里的height 和width才是盒子内容的大小
盒子大小由margin+border+padding+contend决定
防止margin border padding把盒子撑开,添加 box-sizing: border-box;
案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
.box {
width: 248px;
height: 163px;
border: 1px solid #cccccc;
margin: 100px auto;
}
a {
text-decoration: none;
color: grey;
font-size: 12px;
}
h3 {
height: 32px;
line-height: 32px;
font-size: 14px;
font-weight: 400;
border-bottom: 1px dotted #cccccc;
padding-left: 15px;
}
li {
height: 23px;
line-height: 23px;
padding-left: 20px;
}
a:hover{
text-decoration: underline;
}
</style>
</head>
<body>
<div class="box">
<h3>品优购快报</h3>
<ul>
<li><a href="#">【特惠】爆款耳机5折秒!</a></li>
<li><a href="#">【特惠】母亲节,健康好礼低至5折!</a></li>
<li><a href="#">【特惠】爆款耳机5折秒!</a></li>
<li><a href="#">【特惠】9.9元洗100张照片!</a></li>
<li><a href="#">【特惠】长虹智能空调立省1000</a></li>
</ul>
</div>
</body>
</html>
文字居中:line-height和height值设置一样
要设置border首先盒子得有width height
盒子垂直居中: margin: 100px auto;