我的问题与此基本相同,但将“line-height”替换为“letter-spacing”:当继承相对行高时,它与元素的字体大小无关。为什么?我如何使其相对?
我的用例是这样的:
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
work.
当然我可以这样做:
* {
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;
}
但它仍然没有我想要的那么优雅。我认为这个问题没有一个优雅的解决方案,但我想问一下,以防我遗漏了什么。