【发布时间】:2021-09-22 14:51:49
【问题描述】:
我有一个html 页面如下,其对应的css 代码:
<div class="container">
<div class="row mt-4">
<div class="col-sm-8">
<h2>blah blah</h2>
<p>blah blah</p>
</div>
<div class="col-sm-4">
<h2>Contact Us</h2>
<address>
<strong>blah blah</strong>
</address>
<div class="row">
<div class="col-6 col-sm-12 col-md-8">
<a target="_blank" rel="noopener noreferrer" href="https://www.blahblah/home/">
<img src="media/logos/blah.png" class="img-fluid mb-2">
</a>
</div>
<div class="col-6 col-sm-12 col-md-8">
<text>Sponsored by:</text>
<a target="_blank" rel="noopener noreferrer" href="https://www.blahblah/">
<img src="media/logos/blah.png" class="img-fluid mb-2">
</a>
</div>
</div>
</div>
</div>
</div>
text {
position: absolute;
font-size: small;
background: blanchedalmond;
}
我将css 代码更改为以下内容,以确保text 标签之间的文本居中,但没有任何效果...
text {
position: absolute;
font-size: small;
background: blanchedalmond;
text-align: center;
vertical-align: middle;
justify-content: center;
align-items: center;
}
这四个添加的行单独或组合都不能解决问题。文本没有在中心对齐,我做错了什么?
【问题讨论】:
-
你有绝对定位的元素并且没有给它任何宽度 - 所以宽度将由一种称为收缩适合的计算方法确定。如果元素的宽度仅与其文本内容开始时要求的一样宽 - 那么尝试将文本“居中”在该宽度内,当然不会取得任何成果。
标签: html css bootstrap-5