代理加盟

2023全新代理计划,一站式模板建站,铜牌代理低至699元送终身VIP,独立代理后台,自营贴牌。

您现在的位置: 麦站网 > 站长学院 > 编程语言 >

CSS样式初始化通用代码总结

来源:本站原创 发布时间:2020-09-22 21:01:56热度:我要评论(0

麦站模板建站平台(10年经验),服务数万家企业,固定透明报价。域名注册、主机/服务器、网站源码一站式服务。实体公司,专业团队,值得选择!超过1000套模板已登记版权,合规合法建站,规避版权风险!【点击获取方案】

我们在写css之前,首先最好是进行css样式初始化一下,这样做可以解决不同浏览器对HTML标签解析不够统一,而造成不兼容的问题。对于这样的问题,很多CSS新手都似乎忽略了这个问题的严重性!看完下面的文字,你就会明白初始化CSS的重要性,我们还在本文后面提供了一些初始化CSS的通用样式表!

为什么要初始化CSS样式表 

因为不同的浏览器对html元素的margin、padding、borer等属性的默认值是不相同的,如果不进行初始化css样式表,往往就会出现在不同浏览器中显示效果也不相同,这样会造成网页显示异常的情况发生!通过初始化CSS样式表,强制让所有元素的属性值达到一样,浏览器中的显示效果才会一致,减少或避免出现在某些浏览器中不兼容情况的发生!

 

初始化CSS的优点

1、可以使网页在不同浏览器中显示效果一致,减少不兼容性问题的发生;

2、可以使网页代码更加简洁,提高开发速度;

3、可以使整个网站的风格和样式更加统一;

初始化CSS的缺点就是会对搜索引擎优化造成小的影响,不过,比起它的优点来说,这点缺点算不了什么!

通过前面的讲述,我相信大家已经知道,在开发新网页或网站之前,有必要先对CSS样式表进行初始化操作了。

 

下面我们就例举几个CSS初始化示范代码

腾讯官网CSS样式初始化

body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0;padding:0} 
body{font:12px"宋体","Arial Narrow",HELVETICA;background:#fff;-webkit-text-size-adjust:100%;} 
a{color:#2d374b;text-decoration:none} 
a:hover{color:#cd0200;text-decoration:underline} 
em{font-style:normal} 
li{list-style:none} 
img{border:0;vertical-align:middle} 
table{border-collapse:collapse;border-spacing:0} 
p{word-wrap:break-word}

雅虎工程师提供的CSS样式初始化

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { margin:0; padding:0; }
body { background:#fff; color:#555; font-size:14px; font-family: Verdana, Arial, Helvetica, sans-serif; }
td,th,caption { font-size:14px; }
h1, h2, h3, h4, h5, h6 { font-weight:normal; font-size:100%; }
address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}
a { color:#555; text-decoration:none; }
a:hover { text-decoration:underline; }
img { border:none; }
ol,ul,li { list-style:none; }
input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }
table { border-collapse:collapse; }
html {overflow-y: scroll;} 
 
.clearfix:after {content: "."; display: block; height:0; clear:both; visibility: hidden;}
.clearfix { *zoom:1; }

 

新浪官网CSS样式初始化

body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div{margin:0;padding:0;border:0;} 
body{background:#fff;color:#333;font-size:12px; margin-top:5px;font-family:"SimSun","宋体","Arial Narrow";} 
ul,ol{list-style-type:none;} 
select,input,img,select{vertical-align:middle;} 
a{text-decoration:none;} 
a:link{color:#009;} 
a:visited{color:#800080;} 
a:hover,a:active,a:focus{color:#c00;text-decoration:underline;}

 

麦站官网CSS样式初始化

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,pre,a,code,del,em,img,strong,sub,sup,b,u,i,dl,dt,dd,ol,ul,li,fieldset,form,label,table,tbody,tfoot,thead,tr,th,td{border:none;font-size:100%;margin:0;outline:0;padding:0;vertical-align:baseline}
body{font-family:"microsoft jhenghei,sans-serif","Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,tahoma,arial,Verdana,sans-serif,"WenQuanYi Micro Hei","B8BF53";font-size:12px;margin:0 auto; background:#fff!important}
html,html body{_background-attachment:fixed;}
input:focus{outline:0}
.topArea table{border-collapse:collapse;border-spacing:0}
ol,ul{list-style:none}
th,td{vertical-align:middle}
.Left{float:left}.f_r{float:right}
.r{text-align:right!important}
.c{text-align:center!important}
.l{text-align:left!important}
a{color:#666;text-decoration:none}
a:hover{color:#f60;text-decoration:none}

 

淘宝官网CSS样式初始化

body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin:0; padding:0; } 
body, button, input, select, textarea { font:12px/1.5tahoma, arial, b8bf53; } 
h1, h2, h3, h4, h5, h6{ font-size:100%; } 
address, cite, dfn, em, var { font-style:normal; } 
code, kbd, pre, samp { font-family:couriernew, courier, monospace; } 
small{ font-size:12px; } 
ul, ol { list-style:none; } 
a { text-decoration:none; } 
a:hover { text-decoration:underline; } 
sup { vertical-align:text-top; } 
sub{ vertical-align:text-bottom; } 
legend { color:#000; } 
fieldset, img { border:0; } 
button, input, select, textarea { font-size:100%; } 
table { border-collapse:collapse; border-spacing:0; }

 

    转载请注明来源网址:https://www.xiuzhanwang.com/bcyy/2711.html

    发表评论

    评论列表(条)

       
      QQ在线咨询
      VIP限时特惠