css初始化代码放在哪里

css初始化代码放在哪里

css初始化代码通常放在一个单独的.css文件中,可以将它命名为reset.css,在html中引用时,需要放在head标签中,并且作为第一个css样式文件来引用。其他的css文件应该放在reset.css文件的下面。

CSS为什么要初始化?

(相关课程推荐:css视频教程

建站老手都知道,这是为了考虑到浏览器的兼容问题,其实不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面差异。

最简单的初始化方法就是: * {padding: 0; margin: 0;} 。有很多人也是这样写的。这确实很简单,但有人就会感到疑问:*号这样一个通用符在编写代码的时候是快,但如果网站很大,CSS样式表文件很大,这样写的话,他会把所有的标签都初始化一遍,这样就大大的加强了网站运行的负载,会使网站加载的时候需要很长一段时间。

下面为各位提供一个基本的css初始化样式,供大家参考。

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,legend,button
form,fieldset,input,textarea,p,blockquote,th,td {   
  padding: 0;   
  margin: 0;   
}
/* 酌情修改 */
body {
    background:#fff;color:#333;font-size:12px; margin-top:5px;font-family:"SimSun","宋体","Arial Narrow";
}

/* 短引用的内容可取值:''或"" */
q:before,q:after {content:”;}  

/* 缩写,图片等无边框 */
fieldset,img,abbr,acronym {border: 0 none;}
abbr,acronym {font-variant: normal;}
legend {color:#000;}

/* 清除特殊标记的字体和字号 */
address,caption,cite,code,dfn,em,strong,th,var {   
  font-weight: normal;   
  font-style: normal;   
}

/* 上下标 */
sup {vertical-align: text-top;}
sub {vertical-align: text-bottom;}

/* 设置表格的边框被合并为一个单一的边框, 指定分隔边框模型中单元格边界之间的距离为0*/
table {   
  border-collapse: collapse;   
  border-spacing: 0;   
}   

/* 表格标题及内容居左显示 */
caption,th {text-align: left;}
input,img,select {vertical-align:middle;}

/* 清除列表样式 */
ol,ul {list-style: none;}  

/* 输入控件字体 */
input,button,textarea,select,optgroup,option {
    font-family:inherit;
    font-size:inherit;
    font-style:inherit;
    font-weight:inherit;
}

/* 标题元素样式清除 */ 
h1,h2,h3,h4,h5,h6 {   
  font-weight: normal;   
  font-size: 100%;   
}   

/* 链接样式,颜色可酌情修改 */
del,ins,a {text-decoration:none;}
a:link {color:#009;}
a:visited {color:#800080;}
a:hover,a:active,a:focus {color:#c00; text-decoration:underline;} 

/* 鼠标样式 */
input[type="submit"] {cursor: pointer;}
button {cursor: pointer;}
input::-moz-focus-inner { border: 0; padding: 0;}

.clear {clear:both;}

本文来自css答疑栏目,欢迎学习!

以上就是css初始化代码放在哪里的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » CSS3 答疑