CSS 如何使用CSS定义两行之间的空格?

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

How to define spaces between two lines using CSS?

css

提问by Steven

Margin, padding, or whatever?

边距、填充或其他什么?

回答by

line-height attribute, more details: http://www.css3.com/css-line-height/

line-height 属性,更多详情:http: //www.css3.com/css-line-height/

回答by Guffa

Margin is used to specify the distance between elements.

边距用于指定元素之间的距离。

Padding is used to specify the padding between an element and it's content.

填充用于指定元素与其内容之间的填充。

Line-height is used to specify the height of text lines in a continuous text.

Line-height 用于指定连续文本中文本行的高度。

So, if you have separate elements that you want a distance between, margin is appropriate:

所以,如果你有单独的元素,你想要一个距离,边距是合适的:

<p style="margin: 5px 0">Line 1</p>
<p style="margin: 5px 0">Line 2</p>

If you have a continuous text where you want a distance between the text lines, line-height is appropriate:

如果你有一个连续的文本,你想要文本行之间的距离,line-height 是合适的:

<p style="line-height: 1.8em">Long text that spans several lines...</p>

回答by Alex

If your lines stored in single <div>or <p>element, your can use(as was mentioned above) line-height(line-height) attribute. In case, when lines are placed in different block elements, yuo can modify space between two lines with margin(margin description) or padding(padding description) attributes.

如果您的行存储在单个<div><p>元素中,您可以使用(如上所述)line-heightline-height)属性。如果行放置在不同的块元素中,您可以使用margin( margin description) 或padding( padding description) 属性修改两行之间的空间。