为什么要初始化css样式

1.浏览器差异

不同浏览器对有些标签的默认值是不同的,如果没对css初始化会出现浏览器之间的页面显示差异

2.提高编码质量

如果不初始化,整个页面做完会很糟糕,重复的css样式很多

最简单的初始化方法是:(不建议)

1 * {padding: 0; margin: 0;} 

淘宝样式 样式初始化

 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:0; padding:0; }
 2 body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; }
 3 h1, h2, h3, h4, h5, h6{ font-size:100%; }
 4 address, cite, dfn, em, var { font-style:normal; }
 5 code, kbd, pre, samp { font-family:couriernew, courier, monospace; }
 6 small{ font-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 sub{ vertical-align:text-bottom; }
12 legend { color:#000; }
13 fieldset, img { border:0; }
14 button, input, select, textarea { font-size:100%; }
15 table { border-collapse:collapse; border-spacing:0; }

腾讯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:12px; margin-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 html {overflow-y:scroll;}
2 body {margin:0; padding:29px00; font:12px"\5B8B\4F53",sans-serif;background:#ffffff;}
3 div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,blockquote,p{padding:0; margin:0;}
4 table,td,tr,th{font-size:12px;}
5 li{list-style-type:none;}
6 img{vertical-align:top;border:0;}
7 ol,ul {list-style:none;}
8 h1,h2,h3,h4,h5,h6{font-size:12px; font-weight:normal;}
9 address,cite,code,em,th {font-weight:normal; font-style:normal;} 

原文地址:https://www.cnblogs.com/miluluyo/p/11152926.html

时间: 2024-07-28 13:31:18

为什么要初始化css样式的相关文章

Web前端面试指导(十六):为什么要初始化CSS样式?

题目点评 这个题目乍一看感觉怪怪的,什么叫初始化样式了?如果换一句话你可能就理解了,就是通用样式.这道题目主要涉及的是理论方面的知识,不用写代码,只要描述清楚就可以了 初始化样式的原因 因为浏览器的兼容的问题,不同浏览器有些标签的默认值是不同的,如果没有CSS初始化往往会出现浏览器之间的页面显示差异.

标准初始化css样式表

body { font-size:12px; line-height:1.3; font-family:'微软雅黑', Tahoma,Helvetica,Arial,'宋体', sans-serif;} body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code,form, fieldset, legend, input, textarea, p, blockquote, th, td { margin:0; padd

初始化css样式

1 html,body,div,ul,li,ol,a,input,textarea,p,dl,dt,dd{margin:0;padding:0;} 2 ul li{list-style: none;} 3 a{text-decoration: none;cursor: pointer;} 4 html{height: 100%;} 5 body{height: 100%;background: #f5f5f5;position: relative;font-family: '微软雅黑';max-

css样式初始化代码总结

编写css样式之前需要初始化css样式,总结如下: /* CSS Document */ html, body, div, span, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,abbr, address, cite, code,del, dfn, em, img, ins,kbd, q, samp,small, strong, sub, sup, var,b, i,dl, dt, dd, ol, ul, li,field

初始化CSS

为什么要初始化CSS? 建站老手都知道,这是为了考虑到浏览器的兼容问题,其实不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面差异.当然,初始化样式会对SEO有一定的影响,但鱼和熊掌不可兼得,但力求影响最小的情况下初始化. 最简单的初始化方法就是: * {padding: 0; margin: 0;} .有很多人也是这样写的.这确实很简单,但有人就会感到疑问:*号这样一个通用符在编写代码的时候是快,但如果网站很大,CSS样式表文件很大,这样写的话,他会把所有的标

cssText设置css样式

js中用cssText设置css样式 (2012-08-21 10:40:22) 转载▼ 标签: js   如果网页中一个 id为“no”的标签,暂且当div标签来tell:想要在js中设置这个div的css样式,很一般的做法是: var obj = document.getElementByIdx_x_x('no');obj.style.width = '400px';obj.style.height = '300px'; 如果要设置一堆又一堆的css样式呢,太麻烦了把.一般情况下都会结合cs

js 设置多条css样式

如果在一个网页中给id="mydiv"的元素添加css样式,先获取该节点:var obj = document.getElementById("mydiv");给节点添加css:如果需要添加的css不多的话,可以obj.style.width = "300px";如果需要添加多条css语句的话,这样会有多条,如:obj.style.width="300px";obj.style.height="300px"

CSS样式表初始化代码

CSS为什么要初始化?建站老手都知道,这是为了考虑到浏览器的兼容问题,其实不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面差异.当然,初始化样式会对SEO有一定的影响,但鱼和熊掌不可兼得,但力求影响最小的情况下初始化. 最简单的初始化方法就是: * {padding: 0; margin: 0;} .有很多人也是这样写的.这确实很简单,但有人就会感到疑问:*号这样一个通用符在编写代码的时候是快,但如果网站很大,CSS样式表文件很大,这样写的话,他会把所有的标签

web前端入门到实战:css样式初始化

为了消除各浏览器对css默认的设置,保持网页在各浏览器中的外观保持一致,初始化css就显得非常必要了!很多时候出现的样式不兼容问题,都可以通过css初始化代码来解决. 1.最耗资源的,最简单的 * { padding: 0; margin: 0; border: 0; } 2.选择性初始化举例(综合) body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,legend,button form,fieldset,input,textarea,p