【发布时间】:2018-07-06 06:26:59
【问题描述】:
On codepen I'm testing some frame classes span button input 和一个空的 span。为了确保空的span 与我正在使用的其他人的高度相匹配calc 数学给它min-height 但这个计算似乎需要知道line-height。有没有办法在不需要知道line-height 的情况下确保min-height?另外我不明白为什么vertical-alignmiddle 将空的与其他对齐,而baseline 没有。如果有人可以解释或提出替代方案,那就太棒了
.frame-apply {
--sum-border: calc(2 * var(--frame-border-width, 0));
--sum-padding-y: calc(2 * var(--frame-padding-y));
border-image: none;
border-radius: var(--radii-medium);
border-style: solid;
border-width: var(--frame-border-width, 0);
display: inline-block;
/* Using middle aligns the empty one with the others
I don't understand why it doesn't align correctly as baseline */
vertical-align: middle;
/* min-height only seems necssary to fill the empty one
It'd be better to avoid needing to know line-height */
min-height: calc(
var(--sum-padding-y) +
var(--sum-border) +
1em * var(--test-line)
);
min-width: 0;
padding:
var(--frame-padding-y)
var(--frame-padding-x);
}
.frame-dense {
--frame-padding-y: 3px;
--frame-padding-x: 11px;
--frame-border-width: 1px;
}
.frame-basic {
--frame-padding-y: 7px;
--frame-padding-x: 15px;
--frame-border-width: 1px;
}
.frame-plush {
--frame-padding-y: 11px;
--frame-padding-x: 23px;
--frame-border-width: 1px;
}
/* Test values ideally all scale */
:root {
--test-size calc(1rem * 14px / 16px);
--test-line: 1.5;
}
.font-test {
font-size: var(--test-size);
line-height: var(--test-line);
}
【问题讨论】:
标签: css alignment vertical-alignment