CSS重置(CSS Reset) 让网页样式在各浏览器中表现一致

  发布时间:2012-12-21 14:32:08   作者:佚名   我要评论
CSS Reset是指重设浏览器的样式,在各种浏览器中,都会对CSS的选择器默认一些数值,譬如当h1没有被设置数值时,显示一定大小;有了CSS Reset,让网页的样式在各浏览器中表现一致,需要的朋友可以了解下

CSS Reset是指重设浏览器的样式。在各种浏览器中,都会对CSS的选择器默认一些数值,譬如当h1没有被设置数值时,显示一定大小。但并不是所有的浏览器都使用一样的数值,所以有了CSS Reset,以让网页的样式在各浏览器中表现一致。

下面介绍几个主流的CSS Reset代码
1、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, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

2、YUI

复制代码
代码如下:

/*
YUI 3.4.1 (build 4118)
Copyright 2011 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
/*
TODO will need to remove settings on HTML since we can't namespace it.
TODO with the prefix,should I group by selector or property for weight savings?
*/
html {
color:#000;
background:#FFF;
}
/*
TODO remove settings on BODY since we can't namespace it.
*/
/*
TODO test putting a class on HEAD.
- Fails on FF.
*/
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;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
}
fieldset,img {
border:0;
}
/*
TODO think about hanlding inheritence differently,maybe letting IE6 fail a bit...
*/
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;
font-variant:normal;
}
/* to preserve line-height and selector appearance */
sup {
vertical-align:text-top;
}
sub {
vertical-align:text-bottom;
}
input,textarea,select {
font-family:inherit;
font-size:inherit;
font-weight:inherit;
}
/*to enable resizing for IE*/
input,textarea,select {
*font-size:100%;
}
/*because legend doesn't inherit in IE */
legend {
color:#000;
}

3、csslab

复制代码
代码如下:

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, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, dialog, figure, header, footer, hgroup, menu, nav, section, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
}
article, aside, nav, section, dialog, figure, header, footer, hgroup {
display:block;
}
legend {
display:none;
}
:focus {
outline: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
a img, iframe {
border: none;
}
ul {
list-style: none;
}
input, textarea, select, button {
font-size: 100%;
font-family: inherit;
}
input, select {
vertical-align:middle;
}
select {
margin: inherit;
}
button {
border: 0;
padding: 0;
background: transparent;
cursor: pointer;
}
/* Fixes incorrect placement of numbers in ol's in IE6/7 */
ol { margin-left:2em; }
/* ========================================= clearfix == */
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}

需要说明的是CSS Reset并不是一成不变的,具体还需要根据项目的不同需求做适当的修改,以达到浏览器的兼容和操作上的便利性。

相关文章

  • css reset样式重置介绍 重置css样式工具分享

    每个浏览器都有一套CSS样式表用于保证网页正常显示,为了精准写出WEB页面 通常一开始就重新定义标签样式,介绍两个比较不错的Reset.css 分别来自雅虎YUI和Eric Meyer
    2014-01-26
  • 全局CSS的设置(基础样式重置)

    全局CSS想必大家并不陌生吧,主要就是一些基础全局的样式设置,提高书写效率,本文整理了一些方便大家使用,感兴趣的朋友可以了解下
    2013-09-12
  • CSS样式重置和清除(让不同浏览器显示效果一致)

    CSS样式清除和重置是前端开发必需要做的事情,结合了前辈们的经验整理了一份CSS重置样式代码不敢独享特此与大家分享下,感兴趣的朋友可不要错过了哈
    2013-05-20
  • css reset 重置样式介绍

    reset.css本意就是重置样式,我始终建议把.clearfix放入layout.css,而把h1、h2之类的定义放进typography.css
    2012-04-01
  • 让样式表CSS代码更加专业规范

    网页制作Webjx文章简介:Eric Meyer Reset和YUI Reset都是非常强大的,但是对于我而言,它们走的太远了。我觉得你最终需要重置一切,然后重新定义所有元素的属性。这就是为
    2009-04-02
  • 编写适合所有项目的通用的reset.css

    网页制作Webjx文章简介:本文就是来介绍如何写一个合适所有项目的通用的reset.css,以及介绍在设置玩reset.css之后需要针对不同项目要首先要设置的内容。
    2009-04-02
  • CSS样式重置代码

    这篇文章主要介绍了CSS样式重置代码,一般保存为reset.css修改了默认的css设置,方便布局与提高浏览器兼容性
    2014-06-11

最新评论