css技巧
標籤(空格分隔): css
1.水平導航欄
html代碼
<div class="nav">
<ul>
<li>
<a href="index.htm/">首頁</a>
</li>
<li>
<a href="introduce.htm/">業務介紹</a>
</li>
<li>
<a href="agent.htm/">加盟代理</a>
</li>
<li>
<a href="cooperate.htm/">招商合作</a>
</li>
<li>
<a href="partner.htm/">合作伙伴</a>
</li>
<li>
<a href="help.htm/">幫助中心</a>
</li>
</ul>
</div>
css代碼
.nav{
position: relative;
top:-19px;
left: 207px;
width: 791px;
}
.nav ul{
width: 791px;
overflow:hidden;
}
ul>li{
float: left;/**這個是重點***/
height: 25px
}
.nav ul>li>a{
padding-left: 40px;
display:block;
width: 72px;
height: 25px;
font-size: 18px;
text-align:center;
text-decoration:none;
}
效果圖
2.首行縮進
text-indent:10px;/*****大小根據實際情況*****/
3.無序列表前面有圖片
ul>li{
width: 291px;
height: 21px;
text-indent: 20px;/****空出來顯示圖標*********/
font-size: 12px;
background: url(../img/li.gif) 0 4px no-repeat;/***設置圖標***/
}
4.垂直居中
line-heigth:
html
<div id="parent">
<div id="child">Text here</div>
</div>
css
#parent {
line-height: 200px;
}
#parent #child{
vertical-align: middle;
}
效果
table-cell
html
<div id="parent">
<div id="child">Content here</div>
</div>
css
#parent {display: table;}
#child {
display: table-cell;
vertical-align: middle;
}
效果
Absolute Positioning and Negative Margin
html
<div id="parent">
<div id="child">Content here</div>
</div>
css
#parent {position: relative;}
#child {
position: absolute;
top: 50%;
left: 50%;
height: 30%;
width: 50%;
margin: -15% 0 0 -25%;
}
效果
Equal Top and Bottom Padding
html
<div id="parent">
<div id="child">Content here</div>
</div>
css
#parent {
padding: 5% 0;
}
#child {
padding: 10% 0;
}
效果
Floater Div
html
<div id="parent">
<div id="child">Content here</div>
</div>
css
#parent {height: 250px;}
#floater {
float: left;
height: 50%;
width: 100%;
margin-bottom: -50px;
}
#child {
clear: both;
height: 100px;
}
效果