我的问题与这个问题基本相同,但将“line-height”替换为“letter-spacing”:当继承相对 line-height 时,它与元素的 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 */
}
我知道它不起作用的原因是计算值而不是指定值是继承的,所以我必须在letter-spacing
每次font-size
更改时重新指定。但我希望有一些类似于无单位价值观的line-height
工作方式。
当然我可以这样做:
* {
letter-spacing: 1.2em;
}
但是我无法阻止某些元素的级联,就像我可以使用的那样line-height
:
body {
font-size: 18px;
line-height: 1.5;
}
.normal-line-height {
line-height: normal;
/* all the descendants of this element will have a normal line-height */
}
我的意思是,当然,我总是可以这样做......
.normal-letter-spacing, .normal-letter-spacing * {
letter-spacing: normal;
}
但它仍然没有我想要的那么优雅。我不认为这个问题有一个优雅的解决方案,但我问的是我是否遗漏了一些东西。