【发布时间】:2018-02-10 14:06:49
【问题描述】:
#hero-container {
display: flex;
position: relative;
height: 520px;
}
.hero {
position: absolute;
left: 0;
top: 0;
}
#text {
z-index: 100;
position: absolute;
color: white;
font-size: 3vw;
font-weight: bold;
left: 150px;
top: 40px;
}
#text2 {
z-index: 100;
position: absolute;
color: white;
font-size: 2vw;
font-weight: bold;
left: 150px;
top: 70px;
}
#hero-container img {
display: flex;
width: 100%;
}
<html>
<head>
</head>
<body>
<div id="hero-container">
<img class="hero" src="https://vreauperle.ro/images/banners/hero-image.jpg"></img>
<p id="text">
First text here
</p>
<p id="text2">
Secondary
</p>
</div>
</body>
</html>
我有一个 width:100% 的图像,在一个固定的容器中。因为我的图像调整了大小,所以文本没有跟随并保持在相同的位置,从而在容器上移动。
如何在不添加 1000 个媒体查询的情况下使文本保持在图像的中心(垂直)和左侧,并有几个像素填充(水平)?
【问题讨论】: