CSS重置(CSS Reset) 讓網(wǎng)頁樣式在各瀏覽器中表現(xiàn)一致
發(fā)布時(shí)間:2012-12-21 14:32:08 作者:佚名
我要評論

CSS Reset是指重設(shè)瀏覽器的樣式,在各種瀏覽器中,都會對CSS的選擇器默認(rèn)一些數(shù)值,譬如當(dāng)h1沒有被設(shè)置數(shù)值時(shí),顯示一定大小;有了CSS Reset,讓網(wǎng)頁的樣式在各瀏覽器中表現(xiàn)一致,需要的朋友可以了解下
CSS Reset是指重設(shè)瀏覽器的樣式。在各種瀏覽器中,都會對CSS的選擇器默認(rèn)一些數(shù)值,譬如當(dāng)h1沒有被設(shè)置數(shù)值時(shí),顯示一定大小。但并不是所有的瀏覽器都使用一樣的數(shù)值,所以有了CSS Reset,以讓網(wǎng)頁的樣式在各瀏覽器中表現(xiàn)一致。
下面介紹幾個(gè)主流的CSS Reset代碼:
1、Eric Meyer
復(fù)制代碼
代碼如下: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
復(fù)制代碼
代碼如下:/*
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
復(fù)制代碼
代碼如下: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并不是一成不變的,具體還需要根據(jù)項(xiàng)目的不同需求做適當(dāng)?shù)男薷模赃_(dá)到瀏覽器的兼容和操作上的便利性。
相關(guān)文章
- 每個(gè)瀏覽器都有一套CSS樣式表用于保證網(wǎng)頁正常顯示,為了精準(zhǔn)寫出WEB頁面 通常一開始就重新定義標(biāo)簽樣式,介紹兩個(gè)比較不錯(cuò)的Reset.css 分別來自雅虎YUI和Eric Meyer2014-01-26
- 全局CSS想必大家并不陌生吧,主要就是一些基礎(chǔ)全局的樣式設(shè)置,提高書寫效率,本文整理了一些方便大家使用,感興趣的朋友可以了解下2013-09-12
- CSS樣式清除和重置是前端開發(fā)必需要做的事情,結(jié)合了前輩們的經(jīng)驗(yàn)整理了一份CSS重置樣式代碼不敢獨(dú)享特此與大家分享下,感興趣的朋友可不要錯(cuò)過了哈2013-05-20
- reset.css本意就是重置樣式,我始終建議把.clearfix放入layout.css,而把h1、h2之類的定義放進(jìn)typography.css2012-04-01
- 網(wǎng)頁制作Webjx文章簡介:Eric Meyer Reset和YUI Reset都是非常強(qiáng)大的,但是對于我而言,它們走的太遠(yuǎn)了。我覺得你最終需要重置一切,然后重新定義所有元素的屬性。這就是為2009-04-02
- 網(wǎng)頁制作Webjx文章簡介:本文就是來介紹如何寫一個(gè)合適所有項(xiàng)目的通用的reset.css,以及介紹在設(shè)置玩reset.css之后需要針對不同項(xiàng)目要首先要設(shè)置的內(nèi)容。2009-04-02
- 這篇文章主要介紹了CSS樣式重置代碼,一般保存為reset.css修改了默認(rèn)的css設(shè)置,方便布局與提高瀏覽器兼容性2014-06-11