重置浏览器默认样式

2020-05-08 08:41:06易采站长站整理


html{color:#000;background:#FFF;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,
fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
}
fieldset,img {
border:0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-style:normal;
font-weight:normal;
}
ol,ul {
list-style:none;
}
caption,th {
text-align:left;
}
h1,h2,h3,h4,h5,h6 {
font-size:100%;
font-weight:normal;
}
q:before,q:after {
content:”;
}
abbr,acronym { border:0;
}

你要做的就是把这些规则简单地保存到reset.css中,然后在页面中使用。在需要给这些元素增加新的样式的时候,和其它元素的设定没有什么不同。

注意:上面reset.css中 input,textarea,select{*font-size:100%;} 只有Internet Explorer可以认识,这样的设定是为了使在Internet Explorer中可以缩放表单控件字体的大小。而 legend{color:#000;} 是因为在Internet Explorer中lengend元素使用字体颜色和系统有关(甚至和系统风格有关)。这里还要指出的 是,html{color:#000;background:#FFF;} 这条规则虽是细节,却很重要,因为在某些时候他直接影响了页面的整体外观,百度就存在这样的设计失误(雅虎没似乎也没有给这一条,但是在某个示例中似乎出 现了)。

和Yahoo!一样,Eric Meyer在他的网站也给出了一个新的写法:


html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
body {
line-height: 1;
color: black;
background: white;
}
ol, ul {
list-style: none;
}
/* tables still need ‘cellspacing=”0″‘ in the markup */
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: “”;
}
blockquote, q {
quotes: “” “”;
}

PS:在做网站时,遇到这样的问题。各个浏览器兼容的问题,单写好CSS不行,还得对其进行初始化,这样,在各个浏览器上运行页面才不会变形。本人正研究中,希望有经验的朋友也给我指教一下。。