html 标题标签(<h1>、<h2>、<h3> 等)的默认边距是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7049952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the default margins for the html heading tags (<h1>, <h2>, <h3>, etc.)?
提问by Mr.T.K
I avoid using the defaults with the reset code below:
我避免在下面的重置代码中使用默认值:
margin:0px; and padding:0px;
For example, what are the default margins for the heading tag below?
例如,下面标题标签的默认边距是多少?
<h1>Header</h1>
采纳答案by darma
It's different regarding which browser, thus if you want a pixel-perfect design then practice is to "reset" those values to 0 (margin and padding) and set them yourself.
哪个浏览器是不同的,因此如果你想要一个像素完美的设计,那么实践是将这些值“重置”为 0(边距和填充)并自己设置它们。
"CSS reset" is very common to front-end developers, a simple example of one i use :
“CSS 重置”对于前端开发人员来说很常见,我使用的一个简单示例:
html,body,blockquote,code,h1,h2,h3,h4,h5,h6,p,pre{margin:0;padding:0}
button,fieldset,form,input,legend,textarea,select{margin:0;padding:0}
fieldset{border:0}
a,a *{cursor:pointer}
div{margin:0;padding:0;background-color:transparent;text-align:left}
hr,img{border:0}
applet,iframe,object{border:0;margin:0;padding:0}
button,input[type=button],input[type=image],input[type=reset],input[type=submit],label{cursor:pointer;}
ul,li{list-style:none;margin:0;padding:0;}
strong{font-weight:bold;}
em{font-style:italic;}
回答by Madara's Ghost
Your Question:
你的问题:
It varies between browsers. Check each browser's specific default stylesheets to tell.
它因浏览器而异。检查每个浏览器的特定默认样式表来判断。
For Google Chrome for example, it's 0.67em
.
例如,对于谷歌浏览器,它是0.67em
.
A Better Solution?
更好的解决方案?
Do know that if you wish to aim for x-browser consistency, you'll have to use a CSS Reset.
请知道,如果您希望实现 x 浏览器的一致性,则必须使用CSS 重置。
The most common one being:
最常见的一种是:
* { padding: 0; margin: 0; }
Although other (and probably better) exist.
尽管存在其他(可能更好)。
回答by Markus Winand
The CSS specification has an informative Appendix D. Default style sheet for HTML 4.
CSS 规范有一个信息丰富的附录 D. HTML 4 的默认样式表。
Although it is informativeit still says:
虽然信息量很大,但它仍然说:
Developers are encouraged to use it as a default style sheet in their implementations.
鼓励开发人员在其实现中将其用作默认样式表。
There you can find
在那里你可以找到
h1 { font-size: 2em; margin: .67em 0 }
h2 { font-size: 1.5em; margin: .75em 0 }
h3 { font-size: 1.17em; margin: .83em 0 }
h4, p,
blockquote, ul,
fieldset, form,
ol, dl, dir,
menu { margin: 1.12em 0 }
h5 { font-size: .83em; margin: 1.5em 0 }
h6 { font-size: .75em; margin: 1.67em 0 }
回答by cuongtrinh
I think you should set line-height:100%
for h1,h2,h3,h4,h5,h6
tag. So blank line will be shortest.
我想你应该设置line-height:100%
的h1,h2,h3,h4,h5,h6
标签。所以空行将是最短的。