css样式书写的问题

经常遇到前端的朋友问及css样式书写的问题,结合自己实际的工作,自己总结了整理了一下,给大家分享:

一、顺序问题:显示属性-位置属性-元素自身属性-文本属性-其他属性

  1、显示属性:z-index、display、list-style

  2、位置属性:position、float

  3、元素自身属性:width、height、margin、padding、border、border-radius、background

  4、文本属性:color、font-size、font-weight、font-family、line-height、text-align、text-indent

  5、其他属性:cursor:pointer

.div{
    display:block;
    position:absolate;
    left:0;
    top:20px;
    width:200px;
    height:500px;
    padding:10px;
    border:1px solid #f60;
    border-radius:5px;
    background:#f00;
    font-size:14px;
    font-weight:bold;
    color:#fff;
    ...
}

二、样式问题

1、使用CSS缩写属性

  CSS有些属性是可以缩写 、简写的,比如padding,margin,font,color等等,这样精简代码同时又能提高加载速度。

  如:padding:0 10px; color:#f3c;等

2、去掉小数点前面的‘0’

  如font-size:.8em; opacity:.5 等

原文地址:https://www.cnblogs.com/chengkun101/p/4153254.html