css技巧

来源:互联网 发布:化学物质欧洲数据库 编辑:程序博客网 时间:2024/06/06 03:25

css技巧

标签(空格分隔): css


  • css技巧
    • 水平导航栏
    • 首行缩进
    • 无序列表前面有图片
    • 垂直居中
      • line-heigth
      • table-cell
      • Absolute Positioning and Negative Margin
      • Equal Top and Bottom Padding
      • Floater Div

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

0 0
原创粉丝点击