HTML学习笔记11——CSS 初始化

一、为啥要初始化?

  不同的浏览器对CSS的初始化不同,就会造成不同的效果。

因此每次新开发网站或新网页时候我们通过初始化CSS样式的属性,为我们将用到的CSS或html标签更加方便准确,为我们节约网页代码,节约网页下载时间;还会使得我们开发网页内容时更加方便简洁,不用考虑很多。

二、需要初始化的地方:   

  初始化的项一般包括margin,border,padding,color,font等等,大致需要初始化有h1到h4标签、table、文字大小、文字没有链接颜色、超链接样式、DIV、居中、ol、 ul、li、img等等的样式。

三、常见一些网站的初始化代码:

yahoo(https://www.yahoo.com/)的初始化

 1 html {https://www.yahoo.com/
 2     background: none repeat scroll 0 0 #FFFFFF;
 3     color: #000000;
 4 }
 5 body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
 6     margin: 0;
 7     padding: 0;
 8 }
 9 table {
10     border-collapse: collapse;
11     border-spacing: 0;
12 }
13 fieldset, img {
14     border: 0 none;
15 }
16 address, caption, cite, code, dfn, em, strong, th, var {
17     font-style: normal;
18     font-weight: normal;
19 }
20 li {
21     list-style: none outside none;
22 }
23 caption, th {
24     text-align: left;
25 }
26 h1, h2, h3, h4, h5, h6 {
27     font-size: 100%;
28     font-weight: normal;
29 }
30 q:before, q:after {
31     content: "";
32 }
33 abbr, acronym {
34     border: 0 none;
35     font-variant: normal;
36 }
37 sup {
38     vertical-align: text-top;
39 }
40 sub {
41     vertical-align: text-bottom;
42 }
43 input, textarea, select {
44     font-family: inherit;
45     font-size: inherit;
46     font-weight: inherit;
47 }
48 input, textarea, select {
49 }
50 legend {
51     color: #000000;
52 }
53 body {
54     font: 13px/1.231 arial,helvetica,clean,sans-serif;
55 }
56 select, input, button, textarea {
57     font: 99% arial,helvetica,clean,sans-serif;
58 }
59 table {
60     font-size: inherit;
61 }
62 pre, code, kbd, samp, tt {
63     font-family: monospace;
64     line-height: 100%;
65 }
66 a {
67     text-decoration: none;
68 }
69 a:hover, a:focus {
70     text-decoration: underline;
71 }
72 strong {
73     font-weight: bold;
74 }
75 input[type="submit"] {
76     cursor: pointer;
77 }
78 button {
79     cursor: pointer;
80 }
View Code

腾讯QQ官网(http://www.qq.com)初始化

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

新浪官网(http://www.sina.com.cn/)初始化

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

淘宝官网(http://www.taobao.com/)初始化

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

网易官网(http://www.163.com/)初始化

1 html {overflow-y:scroll;}
2 body {margin:0; padding:29px00; font:12px"5B8B4F53",sans-serif;background:#ffffff;}
3 div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,blockquote,p{padding:0; margin:0;}
4 table,td,tr,th{font-size:12px;}
5 li{list-style-type:none;}
6 img{vertical-align:top;border:0;}
7 ol,ul {list-style:none;}
8 h1,h2,h3,h4,h5,h6{font-size:12px; font-weight:normal;}
9 address,cite,code,em,th {font-weight:normal; font-style:normal;}
View Code

博客园(http://www.cnblogs.com/)初始化

 1 /*version: 2.7.0*/
 2 html,body{color:#000;background:#FFF;}
 3 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{
 4     margin:0;padding:0;
 5 }
 6 table{border-collapse:collapse;border-spacing:0;}
 7 fieldset,img{border:0;}
 8 address,caption,cite,code,dfn,em,strong,th,var,optgroup{
 9     font-style:inherit;font-weight:inherit;
10 }
11 del,ins{text-decoration:none;}
12 li{list-style:none;}
13 caption,th{text-align:left;}
14 h1,h2,h3,h4,h5,h6{    font-size:100%;font-weight:normal;}
15 q:before,q:after{content:'';}
16 abbr,acronym{border:0;font-variant:normal;}
17 sup{vertical-align:baseline;}
18 sub{vertical-align:baseline;}
19 legend{color:#000;}
20 input,button,textarea,select,optgroup,option{
21     font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;
22 }
23 input,button,textarea,select{*font-size:100%;}
24 .clear{clear:both;}
25 input::-moz-focus-inner{ border: 0;padding: 0;}
26 
27 /*added*/
28 input[type=button],input[type=submit] {-webkit-appearance: button;}
View Code

以上内容参考:http://www.php1.cn/article/84790.html

嘻嘻嘻……

原文地址:https://www.cnblogs.com/Christeen/p/5678542.html