Fork me on GitHub

CSS的布局

CSS布局:

定位(position)中有
static 没有定位 默认值
relative 相对定位
absolute 绝对定位
fixed 固定定位

tip:使用绝对定位前先指定父元素的相对定位为止,否则默认为窗口
使用固定定位默认相对于浏览器窗口进行定位

层级(z-index)

tip: 只有定位元素才能使用z-index,值越大,显示越前面
定位元素高于非定位元素,同为定位元素比较z-index

隐藏及显示(display与visibility)

隐藏元素 display:none; visibility:hidden;
显示元素 display:block; visibility:visible;
区别在于display:none不占用位置,而visibility还会占用位置

css reset

reset

css 优化

  • 属性简写 margin:10px 15px 20px 25px;

    margin:上   右   下   左     顺时针方向
    
    background:#fff url(bg.jpg) no-repeat fixed top center;
    background:颜色  图像 平铺方式 滚动方式 图像开始位置
    
    font:italic bold 15px/20px "微软雅黑"
    font: 斜体  粗体  字号/行高  字体名称
    

css 书写顺序

显示属性 display visibility overflow position float clear
自身属性 top left width height margin padding border outline background
文本属性 color font line-height text-align text-decoration text-indent 
        text-transform vertical-align white-space content