如何清空css 的默认边距

时间:2023-03-10 02:43:43
如何清空css 的默认边距

在网页开发中,html的元素,有部分元素默认是有内外边距的,例如body 元素,是有默认边距的

如何清空css 的默认边距

所以在通常情况下,我们都要先清空元素的内外边距:使用通配符选择器* 清空元素的内边距和外边距

   *{ margin:; padding:; }

但是使用通配符选择器,会遍历所有的元素,对网页的性能会有影响,为了减少对网页性能的损耗,我们采用另外一种方法,看一下大型网站是怎么做的  Yui 的雅虎开发的一个框架,

我们看下  yui 是怎么做的

在百度输入  yui css reset

如何清空css 的默认边距

如何清空css 的默认边距

结果如下:

如何清空css 的默认边距

上图中初始化 html 元素的 代码如下:

 html{color:#000;background:#FFF}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{margin:;padding:}table{border-collapse:collapse;border-spacing:}fieldset,img{border:}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;*font-size:100%}legend{color:#000}#yui3-css-stamp.cssreset{display:none}

其中,清除边框的代码如下:

             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 {
margin:;
padding: 0
}

所以,以后清除元素边框的边距,直接写以上代码就好了