准备工具:
前端IDE:HBuilderX(不一定这个)
教程开始:
开始之前先带大家学习一下BAT公司都是对哪些HTML元素和标签进行初始化的。
下面是取自百度贴吧一部分的CSS初始化代码:
table {
border-collapse: collapse;
border-spacing: 0;
}
td,th {
padding: 0;
}
html,body,div,p,ul,li,ol,dl,dt,dd,pre,code,table,tr,
td,form,fieldset,legend,button,input,textarea,h1,h2,
h3,h4,h5,h6,hr,blockquote {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
ul,ol,li {
list-style: none;
}下面是取自淘宝一部分的CSS初始化代码:
body,button,dd,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,hr,input,legend,li,ol,p,pre,td,textarea,th,ul {
margin: 0;
padding: 0
}
body,button,input,select,textarea {
font: 12px/1.5 tahoma, arial, 'Hiragino Sans GB', '\5b8b\4f53', sans-serif
}
h1,h2,h3,h4,h5,h6 {
font-size: 100%
}
address,cite,dfn,em,var {
font-style: normal
}
code,kbd,pre,samp {
font-family: courier new, courier, monospace
}
small {
font-size: 12px
}
ol,ul {
list-style: none
}
a {
text-decoration: none
}下面是取自腾讯网一部分的CSS初始化代码:
body,ol,ul,li,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select {
margin: 0;
padding: 0
}
img {
border: 0;2.参考了BAT三家公司的常见初始化代码,我们可以发现大多都是对常用标签如:h1-h6,body,table等进行边距(margin)和填充(padding)大小还有块元素(display)的初始化。所以这边综合了一下一些常见的初始化代码给大家,大家可以根据需要增删减。
/*css 初始化 */
html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img {
margin: 0;
padding: 0;
}
h1, h2, h3, h4, h5, h6 {
text-decoration: none;
font-weight: normal;
font-size: 100%;
}
img, input, button {
border: none;
padding: 0;
margin: 0;
outline-style: none;
}
ul, ol {
list-style: none;
}
/*css 设置文本输入框统一字体 */
input {
padding-top: 0;
padding-bottom: 0;
font-family: "SimSun", "宋体";
}
/*防止拖动*/
img {
border: 0;
vertical-align: middle;
}
/* 去掉图片低测默认的3像素空白缝隙*/
table {
border-collapse: collapse;
}
s, i, em {
font-style: normal;
text-decoration: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
td,th {
padding: 0;
}
a {
text-decoration: none
}3.上述初始化也存在不完整性,可以参考下列的标签默认样式进行筛选初始化。
//块级元素
html, body, div,ol, p, ul, h1, h2,h3,h4,h5, h6,
address,blockquote, form,
dd,dl, dt, fieldset, frame, frameset,noframes,center, dir, hr, menu, pre
{ display: block }
//列表元素类
li{ display:list-item }
ol{list-style-type: decimal }
ol ul, ul ol,ul ul, ol ol { margin-top: 0; margin-bottom: 0 }
ol, ul{ margin-left: 40px }
//预格式文本类
i, cite, em,var, address{ font-style: italic }
big{ font-size:1.17em }
small, sub, sup{ font-size: .83em }
sub{ vertical-align:sub }
sup{ vertical-align:super }
s, strike, del{ text-decoration: line-through }
u, ins{ text-decoration:underline }
//标题类
h1{ font-size:2em; margin: .67em 0 }
h2{ font-size:1.5em; margin: .75em 0 }
h3{ font-size:1.17em; margin: .83em 0 }
h4, p,blockquote, ul,fieldset, form,ol, dl, dir,menu { margin: 1.12em 0}
h5 { font-size:.83em; margin: 1.5em 0 }
h6{ font-size:.75em; margin: 1.67em 0 }
h1, h2, h3, h4,h5, h6, b,strong { font-weight: bolder }
//伪类
br:before{ content: ”\A” }
:before, :after{ white-space: pre-line }
:link, :visited { text-decoration: underline }
:focus{ outline: thin dotted invert }
//表格类
table{ display: table }
tr{ display:table-row }
thead{ display:table-header-group }
tbody{ display:table-row-group }
tfoot{ display:table-footer-group }
col{ display:table-column }
colgroup{ display:table-column-group }
td, th{ display: table-cell;}
caption{ display: table-caption }
th{font-weight: bolder; text-align: center }
caption{ text-align: center }
table{ border-spacing: 2px;}
thead, tbody,tfoot { vertical-align:middle }
td, th { vertical-align:inherit }
//其它元素
head{ display: none }
body{ margin: 8px;line-height: 1.12 }
button, textarea,input, object,select { display:inline-block;}
blockquote{ margin-left: 40px;margin-right: 40px }
pre, tt, code,kbd, samp { font-family: monospace }
pre{ white-space: pre}
hr{ border: 1px inset }
center{ text-align: center }
abbr, acronym{ font-variant: small-caps; letter-spacing:0.1em }
BDO[DIR="ltr"] { direction: ltr; unicode-bidi:bidi-override }
BDO[DIR="rtl"] { direction: rtl; unicode-bidi:bidi-override }
/*定义BDO元素当其属性为DIR="ltr/rtl"时的默认文本读写显示顺序*/
*[DIR="ltr"]{ direction: ltr;unicode-bidi: embed }
*[DIR="rtl"] { direction: rtl;unicode-bidi: embed }
/*定义任何元素当其属性为DIR="rtl/rtl"时的默认文本读写显示顺序*/
@media print {
h1{page-break-before: always }
h1, h2, h3,h4, h5, h6 { page-break-after: avoid }
ul, ol, dl{ page-break-before: avoid }
} /*定义标题和列表默认的打印样式*/完!
暂时就这些吧,若想起少了什么再来补充………………
本文地址:https://www.mainblog.cn/127.html
版权声明:本文为原创文章,版权归 阁主 所有,欢迎分享本文,转载请保留出处!
免责申明:有些内容源于网络,没能联系到作者。如侵犯到你的权益请告知,我们会尽快删除相关内容。
版权声明:本文为原创文章,版权归 阁主 所有,欢迎分享本文,转载请保留出处!
免责申明:有些内容源于网络,没能联系到作者。如侵犯到你的权益请告知,我们会尽快删除相关内容。
黔ICP备19006353号-2
贵公网安备 52052102000042号