每次新开发网站或新网页时候我们通过初始化CSS样式的属性,为我们将用到的CSS或html标签更加方便准确。假如我们不初始化CSS样式属性,将会增大CSS代码量,为我们节约网页代码,节约网页下载时间;还会使得我们开发网页内容时更加方便简洁,不用考虑很多。如果不初始化CSS我们在开发比较复杂的网页时候就不会知道自己是否已经设置了此处的CSS属性,是否和前面的CSS属性相同,是否统一整个网页的风格和样式。
需要初始化地方主要如下:
大致一般需要初始化有h1到h6标签、font(字体/大小/颜色) 、body、 a、DIV、p、span、dl、dt、ol、 ul、li、img等等的样式。
下面是网上找来的几个初始化参考:
腾讯QQ官网 样式初始化
- body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0;padding:0}
- body{font:12px"宋体","Arial Narrow",HELVETICA;background:#fff;-webkit-text-size-adjust:100%;}
- a{color:#2d374b;text-decoration:none}
- a:hover{color:#cd0200;text-decoration:underline}
- em{font-style:normal}
- li{list-style:none}
- img{border:0;vertical-align:middle}
- table{border-collapse:collapse;border-spacing:0}
- p{word-wrap:break-word}
新浪官网 样式初始化
- body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div{margin:0;padding:0;border:0;}
- body{background:#fff;color:#333;font-size:12px; margin-top:5px;font-family:"SimSun","宋体","Arial Narrow";}
- ul,ol{list-style-type:none;}
- select,input,img,select{vertical-align:middle;}
- a{text-decoration:none;}
- a:link{color:#009;}
- a:visited{color:#800080;}
- a:hover,a:active,a:focus{color:#c00;text-decoration:underline;}
淘宝官网 样式初始化
- 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:0; padding:0; }
- body, button, input, select, textarea { font:12px/1.5tahoma, arial, \\5b8b\\4f53; }
- h1, h2, h3, h4, h5, h6{ font-size:100%; }
- address, cite, dfn, em, var { font-style:normal; }
- code, kbd, pre, samp { font-family:couriernew, courier, monospace; }
- small{ font-size:12px; }
- ul, ol { list-style:none; }
- a { text-decoration:none; }
- a:hover { text-decoration:underline; }
- sup { vertical-align:text-top; }
- sub{ vertical-align:text-bottom; }
- legend { color:#000; }
- fieldset, img { border:0; }
- button, input, select, textarea { font-size:100%; }
- table { border-collapse:collapse; border-spacing:0; }