首页 > header上方的空隙

header上方的空隙

为什么header上方会有空隙?

网址如下:http://output.jsbin.com/wopeyucinu


body或者header标签的padding和margin属性值设置为0


p {

margin: 0;
padding: 0;
border: 0;

}


< p >有和body都有margin:

Typical default display properties
p {
display: block;
margin-before: 1em;
margin-after: 1em;
margin-start: 0;
margin-end: 0; }

https://github.com/necolas/normalize.css/blob/master/normalize.css#L15

/**
 * Remove default margin.
 */

body {
  margin: 0;
}

其实直接用normalize.css这类的lib去方便做跨浏览器的开发比较好:

<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" rel="stylesheet" type="text/css">
</head>

http://jsbin.com/kidizemoha/edit?html,css,output 给你改好了,暴力改法
*{margin: 0px;
padding:0px;}
还有小伙子你是萌新吗?你还是去看w3c看看基础吧


margin-top: 0px;


哈哈,浏览器会有默认的margin.


谢谢各位,根据以上各位的答案,总结了下:

  1. 虽然对body元素设置了margin:0px;padding:0px;但是margin属性是不可继承的,所以还是不行

  2. p元素有默认的样式,p{margin:1.12em 0};

  3. 可以对p元素添加{margin:0px;padding:0px;}或者使用全局样式*{margin:0px;padding:0px;}
    或者在开发过程中使用normalize.css来解决

参考链接:
https://developer.mozilla.org/en-US/docs/Web/CSS/margin
http://www.cnblogs.com/xiangzi888/archive/2011/10/12/2209514.html
https://github.com/necolas/normalize.css/


p标签默认有margin,你可以样式重置一下,http://meyerweb.com/eric/tools/css/reset/

【热门文章】
【热门文章】