【发布时间】:2020-12-01 03:51:35
【问题描述】:
我遇到了一个小的 css 问题,我希望将文本的底部放在相同的垂直位置,即使它们的字体大小不同。但显然这不是它的工作方式。实现这一目标的最直接方法是什么?所以我希望左下角和右下角以及左上角和右上角垂直对齐。
<html>
<head>
<style>
.container {
position: relative;
width: 300px;
height: 100px;
}
.topright {
position: absolute;
top: 20px;
right: 16px;
font-size: 8px;
}
.topleft {
position: absolute;
top: 20px;
left: 16px;
font-size: 28px;
}
.bottomright {
position: absolute;
top: 100px;
right: 16px;
font-size: 28px;
}
.bottomleft {
position: absolute;
top: 100px;
left: 16px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="container">
<div class="topleft">Top Left</div>
<div class="topright">Top Right</div>
<div class="bottomleft">Bottom Left</div>
<div class="bottomright">Bottom Right</div>
</div>
</body>
</html>
【问题讨论】:
-
没有指定高度是不可能的。右上角元素不知道左上角元素的高度。底部元素也是如此。如果您可以使用
bottom而不是top位置,那将是可能的。
标签: html css vertical-alignment