书写高效的CSS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:34:31
Original
1102 people have browsed it

一、使用高效是CSS

①:使用外联样式替代行间样式或内嵌样式。

  不推荐使用内联样式:

  不推荐使用内嵌样式:

  推荐使用外联样式:

②:为了兼容老版本的浏览器,建议使用link引入外部样式表的方式替代@import导入样式的方式。@import是css2.1提出来的,所以老的浏览器不支持。

  不推荐@import导入方法:

  推荐引入外部样式表方式:

③:使用继承:将子元素共同使用的样式赋给父元素

④:使用多重选择器:将元素共同使用到的样式写在一起。比如h1,h2,h3,h4样式一样的部分,就写在一起,不要写成4个独立的。

⑤:使用多重声明。不要像下面那种写法,应该写在一起。

  p { margin: 0 0 1em; }
  p { background: #ddd; }
  p { color: #666; }

⑥:使用简记属性。margin:10px 10px;

⑦:避免使用!important,特定情况下可以使用提高权重级别。

二、维护

①:在样式表开头添加一个注释块,用以描述这个样式表的创建日期、 创建者、标记等备注信息.

②:包括公用颜色标记

  /*
  ---------------------------------
  COLORS
  Body background: #def455
  Container background: #fff
  Main Text: #333
  Links: #00600f
  Visited links: #098761
  Hover links: #aaf433
  H1, H2, H3: #960
  H4, H5, H6: #000
  ---------------------------------
  */

③:给ID和Class进行有意义的命名

④:将关联的样式规则进行整合

#header { ... }
#header h1 { ... }
#header h1 img { ... }
#header form { ... }
#header a#skip { ... }
#navigation { ... }
#navigation ul { ... }
#navigation ul li { ... }
#navigation ul li a { ... }
#navigation ul li a:hover { ... }
#content { ... }
#content h2 { ... }
#content p { ... }
#content ul { ... }
#content ul li { ... }
⑤:给样式添加清晰的注释
三、管理整站的CSS文件

①:组件化CSS

②:特定情况下使用条件注释

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!