Html 定义标题标签之间的行距

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

Defining Line spacing between Header tags

htmltags

提问by Jeiman

Is there a way of defining the line spacing between headers. I know using various header tags(h1, h2, h3) have various line spacing and I was wondering if there's a way of defining a line spacing for all of them, so that they are consistent and fluid throughout the page?

有没有办法定义标题之间的行距。我知道使用各种标题标签(h1、h2、h3)有不同的行距,我想知道是否有一种方法可以为所有这些标签定义行距,以便它们在整个页面中保持一致和流畅?

There are lots of articles on using margin and such, but I'm not too sure about it.

有很多关于使用保证金等的文章,但我不太确定。

回答by David Rust-Smith

If you are not familiar with CSS I suggest reading a little: CSS Intro: http://www.w3schools.com/css/default.asp

如果您不熟悉 CSS,我建议您阅读一下:CSS Intro:http: //www.w3schools.com/css/default.asp

CSS like this would set the line height for all of your header tags:

像这样的 CSS 会设置所有标题标签的行高:

h1, h2, h3, h4, h5, h6{
  line-height: 30px; 
}

Or this would set top and bottom margin's for all headers:

或者这将为所有标题设置顶部和底部边距:

h1, h2, h3, h4, h5, h6{
  margin-top:20px;
  margin-bottom:10px;
}

回答by Michael Moriarty

Most suggest using a line-height of 1.45 for h1~h6 so that would be:

大多数人建议对 h1~h6 使用 1.45 的行高,这样将是:

h1, h2, h3, h4, h5, h6 {
  line-height: 1.45;
}

The recommended method for defining line height is using a number value, referred to as a "unitless" line height. A number value can be any number.

定义行高的推荐方法是使用一个数值,称为“无单位”行高。数字值可以是任何数字。