CSS初始化科普
一、为什么要初始化
1、浏览器差异
因为浏览器的兼容问题,不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面显示差异。
2、提高编码质量
初始化CSS为我们节约网页代码,节约网页下载时间;还会使得我们开发网页内容时更加方便简洁,不用考虑很多。如果不初始化,整个页面做完会很糟糕,重复的css样式很多。我们在开发比较复杂的网页时候就不会知道自己是否已经设置了此处的CSS属性,是否和前面的CSS属性相同,是否统一整个网页的风格和样式。
每次新开发网站或新网页时候通过初始化CSS样式的属性,为我们将用到的CSS或html标签更加方便准确,使得我们开发网页内容时更加方便简洁,同时减少CSS代码量,节约网页下载时间。
二、怎么初始化
最简单的初始化的方式:
* {padding: 0; margin: 0;}
*
号这样一个通用符在编写代码的时候是快,但如果网站很大,CSS样式表文件很大,这样写的话,他会把所有的标签都初始化一遍,这样就大大的加强了网站运行的负载,会使网站加载的时候需要很长一段时间。
以下是一些大网页的初始化方式:
京东式初始化:
-
* {
-
margin: 0;
-
padding: 0
-
}
-
-
em,
-
i {
-
font-style: normal
-
}
-
-
li {
-
list-style: none
-
}
-
-
img {
-
border: 0;
-
vertical-align: middle
-
}
-
-
button {
-
cursor: pointer
-
}
-
-
a {
-
color: #666;
-
text-decoration: none
-
}
-
-
a:hover {
-
color: #c81623
-
}
-
-
button,
-
input {
-
font-family: Microsoft YaHei, Heiti SC, tahoma, arial, Hiragino Sans GB, "\5B8B\4F53", sans-serif
-
}
-
-
body {
-
-webkit-font-smoothing: antialiased;
-
background-color: #fff;
-
font: 12px/1.5 Microsoft YaHei, Heiti SC, tahoma, arial, Hiragino Sans GB, "\5B8B\4F53", sans-serif;
-
color: #666
-
}
-
-
.hide,
-
.none {
-
display: none
-
}
-
-
.clearfix:after {
-
visibility: hidden;
-
clear: both;
-
display: block;
-
content: ".";
-
height: 0
-
}
-
-
.clearfix {
-
*zoom: 1
-
}
淘宝式初始化:
-
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, \5b8b\4f53;
-
}
-
-
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;
-
}
腾讯式初始化:
-
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
-
}
新浪式初始化:
-
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;
-
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhhagffj
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13