Html 即使没有设置,H1 标签仍然在底部有填充或边距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11048873/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:02:43  来源:igfitidea点击:

H1 tag still has a padding or margin on the bottom even though none set

htmlcss

提问by RSM

H1 tag still has a padding or margin on the bottom even though none set.

即使没有设置,H1 标签仍然在底部有填充或边距。

I have a h1 tag and a bit of text underneath. I set margin and madding to 0 on both and the text still does not sit right underneath the h1 text.

我有一个 h1 标签和下面的一些文字。我将两者的边距和 madding 都设置为 0,但文本仍然没有位于 h1 文本的正下方。

I have created a js fiddle to illustrate my point

我创建了一个 js 小提琴来说明我的观点

http://jsfiddle.net/6hCrC/

http://jsfiddle.net/6hCrC/

回答by Quentin

There is no padding. There is just space allocated by the default line-heightand no characters with descenders (like p, q, and g) in the text.

没有填充。默认情况下只分配了空间line-height,文本中没有带有降序的字符(如 p、q 和 g)。

http://jsfiddle.net/6hCrC/1/

http://jsfiddle.net/6hCrC/1/

回答by sandeep

Every fonthas their own vertical space which is called line-height. It's the line-heightof H1.

每个font都有自己的垂直空间,称为line-height。这line-heightH1 的

Check this http://jsfiddle.net/6hCrC/4/

检查这个http://jsfiddle.net/6hCrC/4/

回答by Dipak

Try using line-height: 70px;

尝试使用 line-height: 70px;

Hope this helps!

希望这可以帮助!

回答by Undefined

This is something to do with line-height. Perhaps an alternative would be to set a negative margin to the first paragraph.

这与行高有关。也许另一种选择是为第一段设置负边距。

Here is a jsfiddle example

这是一个jsfiddle示例

http://jsfiddle.net/6hCrC/3/

http://jsfiddle.net/6hCrC/3/

Alternatively you could set the line height to a value other than auto (the default)

或者,您可以将行高设置为自动以外的值(默认值)

回答by Axente Paul

回答by LexA

The better solution here is:

这里更好的解决方案是:

h1, h2, h3, h4 {line-height: 1em;}