<style type="text/css">
body,#container,#header,#content,ul{
padding: 0px;
margin: 0px;
}
#container{
width: 800px;
margin: 0px auto;
}
#header{
width: 100%;
}
#content{
width: 100%;
}
#list{
width: 600px;
margin: 0px auto;/*水平居中*/
border-left: 3px;
border-left-style: solid;
border-left-color: #CCCCCC;
}
#list ul li{
list-style: none;/*去掉列表的小點(diǎn)*/
width: 100%;
height: 30px;
line-height: 30px;
border-bottom: 1px dashed #ccc;
font-family: cursive;
font-size: 16px;
margin-bottom: 50px;
border-bottom-style: dashed;
}
/*前面的小圓點(diǎn)*/
#list ul li span{
display: block; /*只有先設(shè)置為塊級(jí)元素才能設(shè)置其寬高*/
float: left;
width: 6px;
height: 6px;
background-color:coral;
border-radius: 50%;
position: relative;
left: -5px;
top: 12px;
}
#list ul li p{
margin-left: 20px;
font-size: 14px;
color: bisque;
font-family: serif;
}
#list ul li a {
text-decoration: none; /*去掉a標(biāo)簽下劃線*/
color: #666;
font-family: serif;
}
#list ul li a:hover{
color: coral;
}
#list ul li p b {
margin-left: 10px;/*文字和時(shí)間的間隔*/
font-family: serif;
}
#header #title{
width: 400px;
height: 200px;
margin: 0px auto;
margin-top: 40px;
text-align: center;
}
#title p{
width: 200px;
height: 40px;
background-color: black;
margin: 0px auto;
line-height: 40px;
margin-top: 60px;
font-size: 25px;
color: white;
}
#title .subTitle{
display: block;
color: coral;
font-size: 20px;
margin-top: 40px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<div id="title"> 
<p>丁丁服務(wù)中心</p>
<i class="subTitle">一家專(zhuān)做特“賣(mài)”的網(wǎng)站</i><!--用一個(gè)空格來(lái)充當(dāng)該div的第一個(gè)元素,這樣后面的子元素設(shè)置margin時(shí)就不會(huì)影響到其位置-->
</div>
</div>
<div id="content">
<div id="list">
<ul>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
<li><span></span><p><a href="">08-19 來(lái)啦</a></p></li>
</ul>
</div>
</div>
</div>
</body>
總結(jié):#####
垂直margin在盒模型中被折疊的問(wèn)題:
“collapsing margins”(折疊margin)的意思是:2個(gè)或2個(gè)以上盒模型之間(關(guān)系可以是相鄰或嵌套)相鄰的margin屬性(這之間不能有非空內(nèi)容儒鹿、padding區(qū)域、border邊框或使用清除分離方法)結(jié)合表示為一個(gè)單獨(dú)的margin;
因?yàn)檎郫Bmargin的問(wèn)題,我們?cè)谠O(shè)置盒子的margin時(shí),可能會(huì)直接影響到其父盒子公般,所以我們可以根據(jù)其特性來(lái)打破這種折疊margin,方法有如下幾種:
- 在兩個(gè)盒子之間加入非空內(nèi)容(如:?)
- 加入padding(如:padding-top: 1px)
- 設(shè)置border(如:border: 1px solid #000)
- 清除分離方法(不會(huì))
一個(gè)盒子要想在其父盒子中水平垂直居中:
- 設(shè)置margin:0px auto(上下為0,水平自動(dòng));
- 設(shè)置margin-top:xxpx;
一個(gè)文本在盒子(p也算盒子)中水平垂直居中:
- 設(shè)置盒子text-align:center;
- 設(shè)置盒子line-height:父盒子高度