gpt4 book ai didi

html - 将文本中心置于其上方的边框空间

转载 作者:搜寻专家 更新时间:2023-10-31 22:18:15 25 4
gpt4 key购买 nike

在下面的代码中,如何将文本中心放置到其正上方的边框空间,如下面的屏幕截图所示,“一些文本 1”和“一些文本 2”位于它们上方边框空间的中心。

enter image description here

.Row {
display: table;
width: 100%;
table-layout: fixed;
border-spacing: 10px;
}

.Column {
display: table-cell;
background-color: red;
}

.Column:nth-child(1) {
width:20%;
}
.Column:nth-child(2) {
width:50%;
}
.Column:nth-child(3) {
width:30%;
}
<div class="Row">
<div class="Column">C1</div>
<div class="Column">C2</div>
<div class="Column">C3</div>
</div>

最佳答案

您可以通过将文本元素放置在单元格中,将它们设置为 position: absolute; 并使用 transform: translate 将它们自身宽度的 50% 推出单元格来实现这一点(50%, 0);.

当然,您需要适当的供应商前缀来支持旧版浏览器。

.Row {
display: table;
width: 100%;
table-layout: fixed;
border-spacing: 10px;
}

.Column {
display: table-cell;
position: relative;
background-color: red;
}

.Column:nth-child(1) {
width:20%;
}
.Column:nth-child(2) {
width:50%;
}
.Column:nth-child(3) {
width:30%;
}

.Column > span {
position: absolute;
right: 0;
top: 1.5em;
transform: translate(50%, 0);
text-align: center;
}
<div class="Row">
<div class="Column">C1<span>Some Text 1</span></div>
<div class="Column">C2<span>Some Text 2</span></div>
<div class="Column">C3</div>
</div>

关于html - 将文本中心置于其上方的边框空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42132702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com