代理加盟

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

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

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

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

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

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

为什么要初始化CSS样式表 

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

 

初始化CSS的优点

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

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

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

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

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

 

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

腾讯官网CSS样式初始化

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

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

01body,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; }
02body { background:#fff; color:#555; font-size:14px; font-family: Verdana, Arial, Helvetica, sans-serif; }
03td,th,caption { font-size:14px; }
04h1, h2, h3, h4, h5, h6 { font-weight:normal; font-size:100%; }
05address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}
06a { color:#555; text-decoration:none; }
07a:hover { text-decoration:underline; }
08img { border:none; }
09ol,ul,li { list-style:none; }
10input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }
11table { border-collapse:collapse; }
12html {overflow-y: scroll;}
13  
14.clearfix:after {content: "."; display: block; height:0; clear:both; visibility: hidden;}
15.clearfix { *zoom:1; }

 

新浪官网CSS样式初始化

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

 

麦站官网CSS样式初始化

01html,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}
02body{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}
03html,html body{_background-attachment:fixed;}
04input:focus{outline:0}
05.topArea table{border-collapse:collapse;border-spacing:0}
06ol,ul{list-style:none}
07th,td{vertical-align:middle}
08.Left{float:left}.f_r{float:right}
09.r{text-align:right!important}
10.c{text-align:center!important}
11.l{text-align:left!important}
12a{color:#666;text-decoration:none}
13a:hover{color:#f60;text-decoration:none}

 

淘宝官网CSS样式初始化

01body, 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; }
02body, button, input, select, textarea { font:12px/1.5tahoma, arial, b8bf53; }
03h1, h2, h3, h4, h5, h6{ font-size:100%; }
04address, cite, dfn, em, var { font-style:normal; }
05code, kbd, pre, samp { font-family:couriernew, courier, monospace; }
06small{ font-size:12px; }
07ul, ol { list-style:none; }
08a { text-decoration:none; }
09a:hover { text-decoration:underline; }
10sup { vertical-align:text-top; }
11sub{ vertical-align:text-bottom; }
12legend { color:#000; }
13fieldset, img { border:0; }
14button, input, select, textarea { font-size:100%; }
15table { border-collapse:collapse; border-spacing:0; }

 

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

    发表评论

    评论列表(0条)

       
      QQ在线咨询
      VIP限时特惠