开源软件企业

为什么要初始化CSS-张魁

2017/1/3 21:44:31

      每次新开发网站或新网页时候我们通过初始化CSS样式的属性,为我们将用到的CSS或html标签更加方便准确。假如我们不初始化CSS样式属性,将会增大CSS代码量,为我们节约网页代码,节约网页下载时间;还会使得我们开发网页内容时更加方便简洁,不用考虑很多。如果不初始化CSS我们在开发比较复杂的网页时候就不会知道自己是否已经设置了此处的CSS属性,是否和前面的CSS属性相同,是否统一整个网页的风格和样式。


需要初始化地方主要如下:
大致一般需要初始化有h1到h6标签、font(字体/大小/颜色) 、body、 a、DIV、p、span、dl、dt、ol、 ul、li、img等等的样式。


下面是网上找来的几个初始化参考:

腾讯QQ官网 样式初始化

  1. body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0;padding:0
  2. body{font:12px"宋体","Arial Narrow",HELVETICA;background:#fff;-webkit-text-size-adjust:100%;} 
  3. a{color:#2d374b;text-decoration:none
  4. a:hover{color:#cd0200;text-decoration:underline
  5. em{font-style:normal
  6. li{list-style:none
  7. img{border:0;vertical-align:middle
  8. table{border-collapse:collapse;border-spacing:0
  9. p{word-wrap:break-word} 

新浪官网 样式初始化

  1. body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div{margin:0;padding:0;border:0;} 
  2. body{background:#fff;color:#333;font-size:12pxmargin-top:5px;font-family:"SimSun","宋体","Arial Narrow";} 
  3.  
  4. ul,ol{list-style-type:none;} 
  5. select,input,img,select{vertical-align:middle;} 
  6.  
  7. a{text-decoration:none;} 
  8. a:link{color:#009;} 
  9. a:visited{color:#800080;} 
  10. a:hover,a:active,a:focus{color:#c00;text-decoration:underline;} 


淘宝官网 样式初始化
 

  1. body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin:0padding:0; } 
  2. body, button, input, select, textarea { font:12px/1.5tahoma, arial, \\5b8b\\4f53; } 
  3. h1, h2, h3, h4, h5, h6font-size:100%; } 
  4. address, cite, dfn, em, var { font-style:normal; } 
  5. code, kbd, pre, samp { font-family:couriernew, courier, monospace; } 
  6. smallfont-size:12px; } 
  7. ul, ol { list-style:none; } 
  8. a { text-decoration:none; } 
  9. a:hover { text-decoration:underline; } 
  10. sup { vertical-align:text-top; } 
  11. subvertical-align:text-bottom; } 
  12. legend { color:#000; } 
  13. fieldset, img { border:0; } 
  14. button, input, select, textarea { font-size:100%; } 
  15. table { border-collapse:collapseborder-spacing:0; }