WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

CSS样式初始化通用代码

更新时间:2021-03-05 10:12 作者:刘代码点击:

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

为什么要初始化CSS样式表 

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

初始化CSS的优点
 

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

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

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

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

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

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

 

最简单的初始化方法:

 

* {padding: 0; margin: 0;}
 

这个比较简单,一个 *  号就解决,编写代码的时候也非常快,但是这样写有一个弊端,就是在你的网站的比较大时,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,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样式初始化

 

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, 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; }

 

网易官网CSS样式初始化

 

html {overflow-y:scroll;} 

body {margin:0; padding:29px00; font:12px"B8BF53",sans-serif;background:#ffffff;} 

div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,blockquote,p{padding:0; margin:0;} 

table,td,tr,th{font-size:12px;} 

li{list-style-type:none;} 

img{vertical-align:top;border:0;} 

ol,ul {list-style:none;} 

h1,h2,h3,h4,h5,h6{font-size:12px; font-weight:normal;} 

address,cite,code,em,th {font-weight:normal; font-style:normal;}

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容