CSS reset重置代码 页面初始化问题

CSS Reset是什么?
HTML标签在浏览器里有默认的样式,例如 p 标签有上下边距,strong标签有字体加粗样式,em标签有字体倾斜样式。不同浏览器的默认样式之间也会有差别,例如ul默认带有缩进的样式,在IE 下,它的缩进是通过margin实现的,而Firefox下,它的缩进是由padding实现的。在切换页面的时候,浏览器的默认样式往往会给我们带来麻烦,影响开发效率。所以解决的方法就是一开始就将浏览器的默认样式全部去掉,更准确说就是通过重新定义标签样式。“覆盖”浏览器的CSS默认属性。最最简 单的说法就是把浏览器提供的默认样式覆盖掉!这就是CSS reset。

为什么要重置它?

因为浏览器的品种很多,每个浏览器的默认样式也是不同的,比如<button>标签,在IE浏览器、Firefox浏览器以及Safari浏 览器中的样式都是不同的,所以,通过重置button标签的CSS属性,然后再将它统一定义,就可以产生相同的显示效果。

下面是经常使用的重置代码:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, em, p, font,

img, small, strong, center, dl, dt, dd, ol, ul, li, form, label, table, caption,

tbody, tr, th, td {margin:0;padding:0;border:0;outline:0;font-size:12px;vertical-align:baseline}
ol, ul {list-style:none}

:focus {outline:none; }

table {border-collapse:collapse;border-spacing: 0}

caption, th, td { text-align: left; font-weight: normal}

strong {font-weight:600}

a{font:12px Arial;text-decoration:none;color:#404040;cursor:pointer;}

a:hover{text-decoration:underline;color:#FF3300}

h1{font-size:16px;font-weight:600;color:#666}

.left{float:left}

.right{float:right}

.clear{clear:both}

雅虎工程师提供的CSS初始化示例代码

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

body { background:#fff; color:#555; font-size:14px; font-family: Verdana, Arial, Helvetica, sans-serif; }

td,th,caption { font-size:14px; }

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

address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}

a { color:#555; text-decoration:none; }

a:hover { text-decoration:underline; }

img { border:none; }

ol,ul,li { list-style:none; }

input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }

table { border-collapse:collapse; }

html {overflow-y: scroll;} 

 

.clearfix:after {content: "."; display: block; height:0; clear:both; visibility: hidden;}

.clearfix { *zoom: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} 

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; }

网易官网 样式初始化

html {overflow-y:scroll;} 

body {margin:0; padding:29px00; font:12px"\5B8B\4F53",sans-serif;background:#ffffff;} 

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

table,td,tr,th{font-size:12px;} 

li{list-style-type:none;} 

img{vertical-align:top;border:0;} 

ol,ul {list-style:none;} 

h1,h2,h3,h4,h5,h6{font-size:12px; font-weight:normal;} 

address,cite,code,em,th {font-weight:normal; font-style:normal;}

 下面顺便给出admin10000.com 的html模板,用于每次新开发页面使用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"> //用来说明你用的xhtmlhtml是什么版本

    <head>

    <title>网站标题 - Admin10000.com </title>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <meta http-equiv="Content-Language" content="zh-CN" />

        <meta name="Author" content="网页作者" /> 

        <meta name="Copyright" content="网站版权" /> 

        <meta name="keywords" content="网站关键字" />

        <meta name="description" content="网站描述" />

        <link rel="Shortcut Icon" href="网站.ico图标路径" />

        <link type="text/css" rel="stylesheet" href="CSS文件路径" />

        <script type="text/javascript" src="JS文件路径"></script>

    </head>

    <body>

    

    </body></html>


猜你喜欢

转载自blog.csdn.net/hahhahahaa/article/details/80677661