css页面的初始化作用是什么?

html-css012

css页面的初始化作用是什么?,第1张

CSS初始化的代码一般要控制常见的页面元素比如body div table等的大小,位置和背景色等夜页面初始加载的样式:

body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td { margin:0padding:0}

body { font-size:12pxcolor:#666font-family:Verdana, Microsoft YaHei, Simsunbackground:#fffline-height:24px}

fieldset, img { border:0}

ol, ul { list-style:none}

h1, h2, h3, h4, h5, h6{ font-size:100%}

em { font-style:normal}

input, button, select, textarea { outline:none}

textarea { resize:none} //禁用了文本的拖拉,尤其在谷歌下

p{ text-align:justifytext-justify:distribute} //为了使文本段落左右两边对齐

初始化css可以避免不必要的麻烦。

很多html都会有默认属性,而且对不同浏览默认值可能不同,很容易导致兼容性问题。而且对于默认值,也容易被自己或他人忽略而造成样式没有达到预期效果。

比如body在浏览器中会有默认的margin如果不清除,对于我们后面的代码编写会造成影响,明明没有写的属性却被设置了。对于其他如p元素、input元素等亦是如此。