小编ben*_*ace的帖子

是否可以相对于font-size具有字母间距并正确继承?

我的问题与此问题基本相同,但将"line-height"替换为"letter-spacing":当继承相对行高时,它与元素的font-size无关.为什么?我如何使它相对?

我的用例是这样的:

body {
    font-size: 18px;
    letter-spacing: 1.2em; /* I would like letter-spacing to be relative to the font-size across the document, at least until I override it */
}

.small {
    font-size: 14px;
    /* letter-spacing is 1.2em of 18px instead of 14px */
}
Run Code Online (Sandbox Code Playgroud)

我知道它不起作用的原因是继承了计算值而不是指定值,因此letter-spacing每次font-size更改时都必须重新指定.但我希望有类似于line-height工作中无单位价值的东西.

当然,我可以这样做:

* {
    letter-spacing: 1.2em;
}
Run Code Online (Sandbox Code Playgroud)

但是我无法阻止某个元素的级联,就像我能够line-height:

body {
    font-size: 18px;
    line-height: 1.5;
}

.normal-line-height {
    line-height: normal;
    /* all the descendants of this element …
Run Code Online (Sandbox Code Playgroud)

html css letter-spacing

7
推荐指数
1
解决办法
686
查看次数

标签 统计

css ×1

html ×1

letter-spacing ×1