导航

Css常用属性 必要样式

Posted on 2011-02-23 15:45  夹心刺猬  阅读(195)  评论(0)    收藏  举报
  1. 对于 HTML 元素水平居中

    body{margin:0 auto;width:1000px;} /*页面居中*/

    div{margin:0 auto;width:200px;} /*div相对于父类居中 */

    /*

    注释:使用 margin:0 auto;必须于 width同时使用否则不生效

    所有方便起见直接设为 

    */

    *{margin:0 auto;} /*所有都居中 想让其生效 就单独加  width:?px */

  2. 对于 HTML 元素垂直居中

    div{height:20px;line-height:20px;} /*对于 纯文字 line-height = height 就可以将文字垂直居中*/

    对于 图片居中 

    .picbox {display: table-cell;vertical-align:middle; text-align:center; *display: block;*font-family:Arial;} /*通用图片容器样式*/

    /* 具体的图片容器大小的样式

      width,height,*font-size 中不能漏掉 *

      不同于 font-size,*font-size针对IE的Hack,

      *font-size的换算公式为 *font-size = height*0.9

    */

    .procpicbox{*font-size:180px;width:800px; height:200px; }

  3.对于 Div 中的 Div 垂直居中

    /* 除去父容器一般的高/宽与自己一半的高/宽 作为 x/y 0点来实现居中*/

    /*所有Div公用样式*/

    .divmiddle{position:relative; top:50%; left:50%;} 

    /*具体的某个DIV样式 : margin:(-(1/2*height)) 0 0 (-(1/2*width)) */

    .divsize{width:200px;height:200px;margin:-100px 0 0 -100px; border:solid 1px red;}