CSS 设置行间距
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3845433/
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
Set line spacing
提问by Moon
How can I set line spacing with CSS, like we can set it in MS Word?
如何使用 CSS 设置行距,就像我们可以在 MS Word 中设置它一样?
回答by Mario Cesar
Try the line-heightproperty.
试试line-height属性。
For example, 12px font-size and 4px distant from the bottom and upper lines:
例如,12px 字体大小和 4px 距离底部和上部线:
line-height: 20px; /* 4px +12px + 4px */
Or with em
units
或与em
单位
line-height: 1.7em; /* 1em = 12px in this case. 20/12 == 1.666666 */
回答by MikeTheLiar
You can also use a unit-less value, which is the number of lines: line-height: 2;
is double spaced, line-height: 1.5;
is one and a half, etc.
您还可以使用无单位值,即行数:line-height: 2;
双倍行距、一倍line-height: 1.5;
半等。
回答by Thomas Visel
You cannot set inter-paragraph spacing in CSS using line-height, the spacing between <p>
blocks. That instead sets the intra-paragraph line spacing, the space between lines within a <p>
block. That is, line-height is the typographer's inter-line leading within the paragraph is controlled by line-height.
您不能使用 line-height(<p>
块之间的间距)在 CSS 中设置段落间距。而是设置段落内行间距,即<p>
块内行之间的空间。也就是说,line-height 是排版者在段落内的行间引导,由 line-height 控制。
I presently do not know of any method in CSS to produce (for example) a 0.15em inter-<p>
spacing, whether using em or rem variants on any font property. I suspect it can be done with more complex floats or offsets. A pity this is necessary in CSS.
我目前不知道 CSS 中有任何方法可以产生(例如)0.15em 的<p>
间距,无论是在任何字体属性上使用 em 还是 rem 变体。我怀疑它可以用更复杂的浮点数或偏移量来完成。可惜这在 CSS 中是必需的。
回答by olibre
If you want condensed lines, you can set same value for font-size
and line-height
如果你想要压缩线,你可以为font-size
和设置相同的值line-height
In your CSS file
在你的 CSS 文件中
.condensedlines {
font-size: 10pt;
line-height: 10pt; /* try also a bit smaller line-height */
}
In your HTML file
在您的 HTML 文件中
<p class="condensedlines">
bla bla bla bla bla bla <br>
bla bla bla bla bla bla <br>
bla bla bla bla bla bla <br>
</p>
--> Play with this snippet on jsfiddle.net
You can also increase line-height
for fine line spacing control:
您还可以增加line-height
细线间距控制:
.mylinespacing {
font-size: 10pt;
line-height: 14pt; /* 14 = 10 + 2 above + 2 below */
}
回答by ANANTH.S
Try this property
试试这个属性
line-height:200%;
or
或者
line-height:17px;
use the increase & decrease the volume
使用增加和减少音量
回答by Alan Haggai Alavi
I am not sure if this is what you meant:
我不确定这是否是您的意思:
line-height: size;
回答by Harsha M V
Try line-height
property; there are many ways to assign line height
尝试line-height
财产;有很多方法可以指定行高
回答by RubenVerg
Yup, as everyone's saying, line-height
is the thing.
Any font you are using, a mid-height character (such as a or ■, not going through the upper or lower) should go with the same height-length at line-height: 0.6
to 0.65
.
是的,正如每个人所说,line-height
就是这样。您使用的任何字体,中等高度的字符(例如 a 或 ■,不穿过上部或下部)应具有相同的高度长度line-height: 0.6
至0.65
。
<div style="line-height: 0.65; font-family: 'Fira Code', monospace, sans-serif">
aaaaa<br>
aaaaa<br>
aaaaa<br>
aaaaa<br>
aaaaa
</div>
<br>
<br>
<div style="line-height: 0.6; font-family: 'Fira Code', monospace, sans-serif">
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■<br>
■■■■■■■■■■
</div>
<br>
<br>
<strong>BUT</strong>
<br>
<br>
<div style="line-height: 0.65; font-family: 'Fira Code', monospace, sans-serif">
ddd<br>
???<br>
ggg
</div>
回答by Eric Kim
lineSpacing is used in React Native (or native mobile apps).
lineSpacing 用于 React Native(或原生移动应用)。
For web you can use letterSpacing
(or letter-spacing
)
对于网络,您可以使用letterSpacing
(或letter-spacing
)