为什么header上方会有空隙?
< 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看看基础吧
谢谢各位,根据以上各位的答案,总结了下:
虽然对body元素设置了margin:0px;padding:0px;但是margin属性是不可继承的,所以还是不行
p元素有默认的样式,p{margin:1.12em 0};
可以对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/
10 回答11.1k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
5 回答1.9k 阅读
p标签默认有margin,你可以样式重置一下,http://meyerweb.com/eric/tools/css/reset/