以前听大家说*号在css中要慎用,原来一直没有发现问题,今天帮客户改样式让我认识到*的危险性,举个简单的例子
<span style="font-size: 16px"><span style="color: #000000">测试内容</span></span>
这段html在浏览器中可以将字体设置为16px,但是加上
*{font-size:12px;}
后字体的大小将即成*号设置的大小即12px
建议大家以后定义全局样式话用下面的代码吧
html,body,h1,h2,h3,h4,h5,h6,p,br,form,input,button,textarea,select,fieldset,blockquote,ul,ol,li,dl,dt,dd,pre{margin:0;padding:0;}
我的css全局样式(css rest)
/*base styles*/
body{
text-align:center;
font-family:"宋体",arial;
margin:0;
padding:0;
background:#FFF;
font-size:12px;
color:#333;
}
div,form,p,img,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6{
margin:0;
padding:0;
border:0;
}
ul,ol,li {list-style-type:none;}
table,td,tr,th,input,select{font-size:12px;}
input {font-family:Arial;}/*text and password width*/
table{border-collapse:collapse;}
hr {
clear:both;
border-width:0;
border-top:1px solid #ccc;
border-bottom:1px solid #FFF;
height:2px;
overflow:hidden;
}
i {font-size:14px;color:red;font-style:normal;margin:0 5px;}/* * */
/*link*/
a:link {color:#333;text-decoration:none;font-family:arial;}
a:visited {color:#333;text-decoration:none;font-family:arial;}
a:hover {color:#bc2931; text-decoration:underline;font-family:arial;}
a:active {color:#bc2931;}
/*font*/
.f12{font-size:12px;}
.f14{font-size:14px;}
.fb{font-weight:800;}
.fi{font-style:italic;}
.dele{text-decoration:line-through;}
.ful {text-decoration:underline;}
/*Area*/
#head,#nav,#main,#foot {
width:950px;
height:auto;
margin:0 auto;
clear:both;
overflow:hidden;/*为了里面有float的时候自动撑开idv,但是现在发现加了之后使用position绝对定位的时候超出的部分总是被切掉,晕。后来不得不去掉这一句。。。*/
}
各大门户网站以及常用css全局样式
1.网易
body { text-align: center; font-family:"宋体", arial;margin:0; padding:0; background: #FFF; font-size:12px; color:#000;}
div,form,img,ul,ol,li,dl,dt,dd {margin: 0; padding: 0; border: 0; }
li{list-style-type:none;}
img{vertical-align:top;}
h1,h2,h3,h4,h5,h6 { margin:0; padding:0;font-size:12px; font-weight:normal;}
/* Link */
a:link {color: #1f3a87; text-decoration:none;}
a:visited {color: #83006f;text-decoration:none;}
a:hover {color: #bc2931; text-decoration:underline;}
a:active {color: #bc2931;}
2.MSN
body {padding:0;margin:0;text-align:center;color:#666;font-size:12px;font-family:tahoma,arial,sans-serif;}
h1, h2, h3, h4, h5, h6, form, div, p, i, img, ul, li, ol, table, tr, td,th, fieldset, label, legend,button,input { margin:0;padding:0;}
li{list-style:none;}
a img{border:none;}
a:link{text-decoration:none;color:#07519A;}
a:visited{text-decoration:none;color:#07519A;}
a:active,a:hover{text-decoration:underline;color:#07519A;}
3.搜狐
/* 全局CSS定义 */
body{font-family:'宋体';text-align:center;margin:0 auto;padding:0;background:#FFF;font-size:12px;color:#333;}
body > div{text-align:center;margin-right:auto;margin-left:auto;}
div,form,ul,ol,li,span,p{margin:0;padding:0;border:0;}
img,a img{border:0;margin:0;padding:0;}
h1,h2,h3,h4,h5,h6{margin:0;padding:0;font-size:12px;font-weight:normal;}
ul,ol,li{list-style:none}
table,td,input{font-size:12px}
/* 默认链接颜色 */
a{outline-style:none;color:#333;text-decoration:none}
a:hover{color:#c00;text-decoration:underline;}
4.中国制造网
/*M-I-C.home0825*/body{font-size:75%;padding-bottom:40px;background-color:#fff}/*Base12px*/#top,#cr,#urh,#footer ul.les{font-family:Verdana,Arial,Helvetica,sans-serif;font-size:91.67%}#urhC,#lesC,#urh h1,#urhB h1,.qp{font-family:Verdana,Arial,Helvetica,sans-serif;font-size:83.33%;font-weight:normal}.qp,#fastLink{font-family:Arial,Helvetica,sans-serif;font-size:91.67%;font-weight:normal}h1,h2,h3,h4,h5,h6,small,big{font-size:100%}body,h1,h2,h3,h4,h5,h6,form,table{margin:0;border:0}img{border:0}body,td,th,select,input,button{font-family:Arial,Helvetica,sans-serif;color:#02032f}img,select,input,button{vertical-align:middle}input,textarea,button,select{font-family:inherit;font-weight:normal;font-size:inherit}em{font-style:normal}ul,li{margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;padding:0;list-style:none}caption{font-weight:bold;text-align:left;border-top-width:0;border-right-width:0;border-left-width:0;padding-bottom:2px}hr{clear:both;color:#A9BAD3}a *{cursor:pointer}a{text-decoration:none}a:link,#header a:visited,#headC a:visited,#nav a:visited,.urhD a:visited,#fastLink a:visited,#footer a:visited,.search a:visited{color:#0b4a9f}#se .cont a:visited,#tabCa01ct a:visited,#ca .cont a:visited,#uc .cont a:visited{color:#774B90}a:link,a:visited,a.mr:visited,#main .mr a:visited,a#showHere:visited{color:#0b4a9f}#top a:link,#top a:visited{color:#386cb1;margin-left:3px;margin-right:3px}#top #newMsg a:link,#top #newMsg a:visited{color:#FF7800}#newMsg img{margin-bottom:2px;>margin-bottom:-2px;}a:hover,#top a:hover,#header a:hover,#headC a:hover,#nav a:hover,#urh a:hover,.urhD a:hover,#urhC a:hover,#fastLink a:hover,#footer a:hover,.search a:hover{color:#e35b00;text-decoration:underline}
非常感谢Perishable的整理与归纳,以下是由某人翻译
_________________________
Minimalistic Reset [ Version 1 ]
相信这一段你经常看到.而且也是我们经常用到的
引用内容* {
padding: 0;
margin: 0;
}
Minimalistic Reset [ Version 2 ]
border:0的设计有些不靠谱了
引用内容* {
padding: 0;
margin: 0;
border: 0;
}
Minimalistic Reset [ Version 3 ]
当然这个也是不推荐的.会跟某些默认样式有冲突
引用内容* {
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
_________________________
Condensed Universal Reset
这是作者当前比较钟意的一种写法.保证了相对普遍浏览器样式的统一性.
引用内容* {
vertical-align: baseline;
font-weight: inherit;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: 0 none;
outline: 0;
padding: 0;
margin: 0;
}
_________________________
Poor Man’s Reset
其实这也是我们常用的一类Css Reset.对字体的大小复位,以及图片链接的边框处理.
也经常在某些站点看到
引用内容html, body {
padding: 0;
margin: 0;
}
html {
font-size: 1em;
}
body {
font-size: 100%;
}
a img, :link img, :visited img {
border: 0;
}
_________________________
Shaun Inman’s Global Reset
作者认为Shaun写这类的Css Reset是有某种目的性.
而且这类规则是针对的是某些重要的常用浏览器.
比如ie,firefox等
引用内容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;
}
_________________________
Yahoo CSS Reset
yahoo这帮家伙写的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;
}
_________________________
Erik Meyer’s CSS Reset
作者将Erik Meyer的代码重新整理了.但功能上还是一样的
这套Css 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;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
body {
background: white;
line-height: 1;
color: black;
}
ol, ul {
list-style: none;
}
/* tables still need cellspacing="0" in the markup */
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
font-weight: normal;
text-align: left;
}
/* remove possible quote marks (") from <q> & <blockquote> */
blockquote:before, blockquote:after, q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
_________________________
Condensed Meyer Reset
总的来说这是对Erik Meyer的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;
}