性能优化-学习笔记

134 阅读1分钟

背景缩写:background: url() no-repeat 80px 40px;

字体缩写: "微软雅黑" 12px/1.5em bold;

  • 使用字体简写形式,我们至少要指定font-family和font-size属性,其他属性如果没 有指定则将自动使用默认值。
  • 在简写形势中,font-size值和line-height值之间是需要加入斜杠“/”的。

CSS中最后一个属性之后的结尾分号是不必要的。

在CSS中,像background-image、cursor等属性url()中的路径不需要添加引号。

在CSS中,当一个属性的属性值是以0开头的小数时,可把0去掉。


利用继承进行合并

 可继承的属性:

  • 文本相关属性:font-family、font-size、font-style、font-weight、font、line-height、text-align、text-indent、word-spacing。
  • 列表相关属性:list-style-image、list-style-position、list-style-type、list-style。
  • 颜色相关属性:color。


高性能选择器

  • 不要使用通配符
  • 不要在id选择器以及class选择器前添加元素名
  • 选择器最好不要超过三层,位置靠右的选择条件尽可能精确
  • 避免使用后代选择器,尽量少用子选择器