【发布时间】:2021-01-07 19:31:48
【问题描述】:
我想在我的白页的中心放置一个图像并在其上添加一个标题(标题会大于图像 || 并且标题中心必须是图像中心)。问题是标题不会出现在图片之上。
我使用 Django 和引导程序 ^^
代码如下:
HTML:
<div class="col-md-7 white nopadding text-center">
<div class="brand">
Brand
</div>
<div class="heading">
<img src="{% static '/eyemeet/hero.jpg' %}" class="hero">
<div class="title ctr">Title</div>
</div>
CSS:
.hero {
width: 65%;
height: auto;
}
.title {
position: absolute;
background-color: cadetblue;
top: 50%;
left: 50%;
}
.ctr {
position: absolute;
transform: translate(-50%, -50%);
}
编辑:
我找到了答案!我希望它可以帮助那些仍然想知道如何做的人:) Center text over an image in flexbox
【问题讨论】:
-
我认为您需要添加更多 CSS,因为您提供的代码运行良好:jsfiddle.net/17bofkqa
-
我会将图片用作标题的背景图片