css技巧

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;
}

效果圖
image_1aobrvr1dlvqnd1mb2jeugfr9.png-7.1kB

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.垂直居中

參考自Vertical-centering

line-heigth:

html

<div id="parent">
  <div id="child">Text here</div>
</div>

css

#parent {
    line-height: 200px;
}

#parent #child{
    vertical-align: middle;
}

效果
![](http://www.vanseodesign.com/blog/wp-content/uploads/2011/07/line-height.png)

table-cell

html

<div id="parent">
  <div id="child">Content here</div>
</div>

css

#parent {display: table;}
#child {
  display: table-cell;
  vertical-align: middle;
}

效果
(http://www.vanseodesign.com/blog/wp-content/uploads/2011/07/line-height.png

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%;
}

效果
image_1b053u9i3ghg1duf19p61bqidd613.png-15.1kB

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;
}

效果
image_1b053vfgb12co3nl1491pib17h61g.png-11kB

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;
}

效果
image_1b05405fg1c8f15chobhd121jba1t.png-9.5kB

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章