簡(jiǎn)化的CSS Reset:15套CSS重設(shè)實(shí)例
互聯(lián)網(wǎng) 發(fā)布時(shí)間:2009-04-02 19:36:40 作者:佚名
我要評(píng)論

網(wǎng)頁(yè)制作Webjx文章簡(jiǎn)介:CSS重設(shè)就是由于各種瀏覽器解釋CSS樣式的初始值有所不同,導(dǎo)致設(shè)計(jì)師在沒有定義某個(gè)CSS屬性時(shí),不同的瀏覽器會(huì)按照自己的默認(rèn)值來(lái)為沒有定義的樣式賦值,所以我們要先定義好一些CSS樣式,來(lái)讓所有瀏覽器都按照同樣的規(guī)
CSS重設(shè)就是由于各種瀏覽器解釋CSS樣式的初始值有所不同,導(dǎo)致設(shè)計(jì)師在沒有定義某個(gè)CSS屬性時(shí),不同的瀏覽器會(huì)按照自己的默認(rèn)值來(lái)為沒有定義的樣式賦值,所以我們要先定義好一些CSS樣式,來(lái)讓所有瀏覽器都按照同樣的規(guī)則解釋CSS,這樣就能避免發(fā)生這種問題.
在當(dāng)今網(wǎng)頁(yè)設(shè)計(jì)/開發(fā)實(shí)踐中,使用CSS來(lái)為語(yǔ)義化的(X)HTML標(biāo)記添加樣式風(fēng)格是重要的關(guān)鍵。在設(shè)計(jì)師們的夢(mèng)想中都存在著這樣的一個(gè)完美世界:所有的瀏覽器都能夠理解和適用多有CSS規(guī)則,并且呈現(xiàn)相同的視覺效果(沒有兼容性問題)。但是,我們并沒有生活在這個(gè)完美的世界,現(xiàn)實(shí)中發(fā)生的失竊卻總是恰恰相反,很多CSS樣式在不同的瀏覽器中有著不同的解釋和呈現(xiàn)。
相關(guān)CSS文章:YaHoo方法:CSS Reset重設(shè)瀏覽器的樣式
當(dāng)今流行的瀏覽器(如:Firefox、Opera、Internet Explorer、Chrome、Safari等等)中,有一些都是以自己的方式去理解CSS規(guī)范,這就會(huì)導(dǎo)致有的瀏覽器對(duì)CSS的解釋與設(shè)計(jì)師的CSS定義初衷相沖突,使得網(wǎng)頁(yè)的樣子在某些瀏覽器下能正確按照設(shè)計(jì)師的想法顯示,但有些瀏覽器卻并沒有按照設(shè)計(jì)師想要的樣子顯示出來(lái),這就導(dǎo)致瀏覽器的兼容性問題。更糟的是,有的瀏覽器完全無(wú)視CSS的一些聲明和屬性。
正因?yàn)樯鲜鰶_突和問題依然存在于這個(gè)”不完美的世界”,所以一些設(shè)計(jì)師想到了一種避免瀏覽器兼容性問題的方法,那就是CSS Reset,什么是CSS Reset?我們可以把它叫做CSS重設(shè),也有人叫做CSS復(fù)位、默認(rèn)CSS、CSS重置等。CSS重設(shè)就是由于各種瀏覽器解釋CSS樣式的初始值有所不同,導(dǎo)致設(shè)計(jì)師在沒有定義某個(gè)CSS屬性時(shí),不同的瀏覽器會(huì)按照自己的默認(rèn)值來(lái)為沒有定義的樣式賦值,所以我們要先定義好一些CSS樣式,來(lái)讓所有瀏覽器都按照同樣的規(guī)則解釋CSS,這樣就能避免發(fā)生這種問題。
今天腳本之家總結(jié)收集了15套CSS重設(shè)實(shí)例,您可以在前端開發(fā)工作中進(jìn)行參考和使用,有些是很簡(jiǎn)化的CSS Reset,有些則是非常復(fù)雜非常全面的CSS Reset,至于使用哪套,全看您的愛好或需要。
腳本之家會(huì)經(jīng)常更新前端開發(fā)/網(wǎng)頁(yè)設(shè)計(jì)等相關(guān)技術(shù)及教程文章,歡迎訂閱本博客來(lái)及時(shí)瀏覽本博客的最新教程及資源。 一.最簡(jiǎn)化的CSS Reset(重設(shè)) :
* {
padding: 0;
margin: 0;
}
這是最普遍最簡(jiǎn)單的CSS重設(shè),將所有元素的padding和margin值都設(shè)為0,可以避免一些瀏覽器在理解這兩個(gè)屬性默認(rèn)值上的”分歧”。
* {
padding: 0;
margin: 0;
border: 0;
}
這是在上一個(gè)重設(shè)的基礎(chǔ)上添加了對(duì)border屬性的重設(shè),初始值為0的確能避免一些問題。
* {
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
在前兩個(gè)的基礎(chǔ)上添加了outline屬性的重設(shè),防止一些沖突。
二.濃縮實(shí)用型CSS Reset(重設(shè)):
* {
vertical-align: baseline;
font-weight: inherit;
font-family: inherit;
font-style: inherit;
font-size: 100%;
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
該CSS重設(shè)方法出自Perishable Press,這是他常用的方法。 三.Poor Man 的CSS Reset:
html, body {
padding: 0;
margin: 0;
}
html {
font-size:1em;
}
body {
font-size:100%;
}
a img, :link img, :visited img {
border:0px;
}
這個(gè)重設(shè)方法將html和body下元素的padding和margin都設(shè)為0,并分別為html標(biāo)簽和body標(biāo)簽下的所有元素設(shè)置了初始的字體大小,最重要的是把有鏈接的圖片的默認(rèn)邊框去掉了。 四.Siolon’s Global Reset
五.Shaun Inman’s Global Reset
* {
vertical-align: baseline;
font-family: inherit;
fo
nt-style: inherit;
font-size: 100%;
border: none;
padding: 0;
margin: 0;
}
body {
padding: 5px;
}
h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
margin: 20px 0;
}
li, dd, blockquote {
margin-left: 40px;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
#p#
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, table, th, td, embed, object {
padding: 0;
margin: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset, img, abbr {
border: 0;
}
address, caption, cite, code, dfn, em,
h1, h2, h3, h4, h5, h6, strong, th, var {
font-weight: normal;
font-style: normal;
}
ul {
list-style: none;
}
caption, th {
text-align: left;
}
h1, h2, h3, h4, h5, h6 {
font-size: 1.0em;
}
q:before, q:after {
content: ”;
}
a, ins {
text-decoration: none;
}
CSS重設(shè)就是由于各種瀏覽器解釋CSS樣式的初始值有所不同,導(dǎo)致設(shè)計(jì)師在沒有定義某個(gè)CSS屬性時(shí),不同的瀏覽器會(huì)按照自己的默認(rèn)值來(lái)為沒有定義的樣式賦值,所以我們要先定義好一些CSS樣式,來(lái)讓所有瀏覽器都按照同樣的規(guī)則解釋CSS,這樣就能避免發(fā)生這種問題. 六.Yahoo(YUI) CSS Reset:
七.Eric Meyer’s CSS Reset
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,
form,fieldset,input,textarea,p,blockquote,th,td {
padding: 0;
margin: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset,img {
border: 0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-weight: normal;
font-style: normal;
}
ol,ul {
list-style: none;
}
caption,th {
text-align: left;
}
h1,h2,h3,h4,h5,h6 {
font-weight: normal;
font-size: 100%;
}
q:before,q:after {
content:”;
}
abbr,acronym {
border: 0;
}
八.Condensed Meyer Reset:
html, body, div, span, applet, object, iframe, table, caption,
tbody, tfoot, thead, tr, th, td, del, dfn, em, font, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,
h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr,
acronym, address, big, cite, code, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend {
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
:focus {
outline: 0;
}
body {
background: white;
line-height: 1;
color: black;
}
ol, ul {
list-style: none;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
font-weight: normal;
text-align: left;
}
blockquote:before, blockquote:after, q:before, q:after {
content: “”;
}
blockquote, q {
quotes: “” “”;
}
九.Ateneu Popular CSS Reset
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6,
pre, form, fieldset, input, textarea, p, blockquote, th, td {
padding: 0;
margin: 0;
}
fieldset, img {
border: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
ol, ul {
list-style: none;
}
address, caption, cite, code, dfn, em, strong, th, var {
font-weight: normal;
font-style: normal;
}
caption, th {
text-align: left;
}
h1, h2, h3, h4, h5, h6 {
font-weight: normal;
font-size: 100%;
}
q:before, q:after {
content: ”;
}
abbr, acronym {
border: 0;
}
十.Chris Poteet’s Reset CSS
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;
}
:focus {
outline: 0;
}
a, a:link, a:visited, a:hover, a:active{
text-decoration:none
}
table {
border-collapse: separate;
border-spacing: 0;
}
th, td {
text-align: left;
font-weight: normal;
}
img, iframe {
border: none;
text-decoration:none;
}
ol, ul {
list-style: none;
}
input, textarea, select, button {
font-size: 100%;
font-family: inherit;
}
select {
margin: inherit;
}
hr {
margin: 0;
padding: 0;
border: 0;
color: #000;
background-color: #000;
height: 1px
}
#p#
* {
vertical-align: baseline;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: none;
padding: 0;
margin: 0;
}
body {
padding: 5px;
}
h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
margin: 20px 0;
}
li, dd, blockquote {
margin-left: 40px;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
CSS重設(shè)就是由于各種瀏覽器解釋CSS樣式的初始值有所不同,導(dǎo)致設(shè)計(jì)師在沒有定義某個(gè)CSS屬性時(shí),不同的瀏覽器會(huì)按照自己的默認(rèn)值來(lái)為沒有定義的樣式賦值,所以我們要先定義好一些CSS樣式,來(lái)讓所有瀏覽器都按照同樣的規(guī)則解釋CSS,這樣就能避免發(fā)生這種問題. 十一.Tantek Celik Reset CSS
十二.Christian Montoya Reset CSS
:link,:visited { text-decoration:none }
ul,ol { list-style:none }
h1,h2,h3,h4,h5,h6,pre,code { font-size:1em; }
ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input
{ margin:0; padding:0 }
a img,:link img,:visited img { border:none }
address { font-style:normal }
十三.Rudeworks Reset CSS
html, body, form, fieldset {
margin: 0;
padding: 0;
font: 100%/120% Verdana, Arial, Helvetica, sans-serif;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
margin: 1em 0;
padding: 0;
}
li, dd, blockquote {
margin-left: 1em;
}
form label {
cursor: pointer;
}
fieldset {
border: none;
}
input, select, textarea {
font-size: 100%;
font-family: inherit;
}
十四.Anieto2K Reset CSS
* {
margin: 0;
padding: 0;
border: none;
}
html {
font: 62.5% “Lucida Grande”, Lucida, Verdana, sans-serif;
text-shadow: #000 0px 0px 0px;
}
ul {
list-style: none;
list-style-type: none;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
font-weight: normal;
margin: 0 0 1em 0;
}
cite, em, dfn {
font-style: italic;
}
sup {
position: relative;
bottom: 0.3em;
vertical-align: baseline;
}
sub {
position: relative;
bottom: -0.2em;
vertical-align: baseline;
}
li, dd, blockquote {
margin-left: 1em;
}
code, kbd, samp, pre, tt, var, input[type='text'], textarea {
font-size: 100%;
font-family: monaco, “Lucida Console”, courier, mono-space;
}
del {
text-decoration: line-through;
}
ins, dfn {
border-bottom: 1px solid #ccc;
}
small, sup, sub {
font-size: 85%;
}
abbr, acronym {
text-transform: uppercase;
font-size: 85%;
letter-spacing: .1em;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
a abbr, a acronym {
border: none;
}
sup {
vertical-align: super;
}
sub {
vertical-align: sub;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.8em;
}
h3 {
font-size: 1.6em;
}
h4 {
font-size: 1.4em;
}
h5 {
font-size: 1.2em;
}
h6 {
font-size: 1em;
}
a, a:link, a:visited, a:hover, a:active {
outline: 0;
text-decoration: none;
}
a img {
border: none;
text-decoration: none;
}
img {
border: none;
text-decoration: none;
}
label, button {
cursor: pointer;
}
input:focus, select:focus, textarea:focus {
background-color: #FFF;
}
fieldset {
border: none;
}
.clear {
clear: both;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
body {
text-align: center;
}
#wrapper {
margin: 0 auto;
text-align: left;
}
十五.CSSLab CSS Reset
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,
center, u, b, i {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
font-family: inherit;
vertical-align: baseline
}
body {
line-height: 1
}
:focus {
outline: 0
}
ol, ul {
list-style: none
}
table {
border-collapse: collapse;
border-spacing: 0
}
blockquote:before, blockquote:after, q:before, q:after {
content: “”
}
blockquote, q {
quotes: “” “”
}
input, textarea {
margin: 0;
padding: 0
}
hr {
margin: 0;
padding: 0;
border: 0;
color: #000;
background-color: #000;
height: 1px
}
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;
}
:focus {
outline: 0;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
a img, iframe {
border: none;
}
ol, ul {
list-style: none;
}
input, textarea, select, button {
font-size: 100%;
font-family: inherit;
}
select {
margin: inherit;
}
/* 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重設(shè)目前先總結(jié)到這里,這15套重設(shè)方法其實(shí)都是有共同點(diǎn)的,也許有的實(shí)現(xiàn)方法不同,但大部分都是同一個(gè)目的,就是為了讓更多的瀏覽器能顯示同樣的效果。有了這些CSS重設(shè)作為資料和參考,也許會(huì)對(duì)你的工作有所幫助甚至提高效率,但是,畢竟這些重設(shè)都是別人寫的,你完全也可以為自己量身定制一套CSS重設(shè)。如果您有什么意見或是看法,歡迎發(fā)表評(píng)論。
相關(guān)文章
css行內(nèi)元素padding,margin,width,height沒有變化
這篇文章主要介紹了css行內(nèi)元素設(shè)置padding,margin,width,height沒有變化的解決方法,需要的朋友可以參考下2014-05-07css中padding和margin的異同點(diǎn)介紹
本文從語(yǔ)法結(jié)構(gòu)、可能取的值、瀏覽器兼容問題等方面為大家介紹下padding和margin的異同點(diǎn)另附截圖,有想學(xué)習(xí)的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-28CSS邊距屬性定義是用margin還是用padding的兩者對(duì)比
用CSS做網(wǎng)頁(yè)時(shí).邊距用哪個(gè)屬于好呢?是margin屬性還是padding屬性呢.2012-06-12- 關(guān)鍵字描述:詳解 樣式 風(fēng)格 solid 必要   修改 padding:0 margin:0 body{font-size:9pt; background:url($imgpath/$stylepath/bodybg.gif) repeat-x ; font-famil2009-06-06
- 關(guān)鍵字描述:注釋 大全 樣式 默認(rèn) 模板 定義 margin:0 10px padding:0 下面這個(gè)是默認(rèn)的ZBLOG CSS樣式表 里面附帶有最全的CSS注釋 讓你一看就理解了。如果您覺得麻煩2009-06-06
Css Reset(復(fù)位)的簡(jiǎn)單介紹-CSS教程-網(wǎng)頁(yè)制作-網(wǎng)頁(yè)教學(xué)網(wǎng)
Css Reset是什么? 有些同行叫 "css復(fù)位",有些可能叫 "默認(rèn)css"..... 相信看完全文您會(huì)對(duì)Css Reset有個(gè)重新的認(rèn)識(shí) 原文地址: http://perishablepre2008-10-17- 在CSS中margin是指從自身邊框到另一個(gè)容器邊框之間的距離,就是容器外距離。在CSS中padding是指自身邊框到自身內(nèi)部另一個(gè)容器邊框之間的距離,就是容器內(nèi)距離。下面講解 pa2017-06-26