我正在尝试在响应式容器中显示重叠图像。
即使图像重叠,图像也应该填满。
我无法用负余量实现它,因为它不会延伸到顶部,是否可能没有js或者方法完全错误?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv"></div>
body {
margin: 0;
height: 1200px;
}
.c-hero {
align-items: center;
display: flex;
justify-content: center;
background: green;
height: 400px;
text-align: center;
width: 100%;
}
.c-hero__image {
object-fit: cover;
object-position: center;
height: 100%;
width: 50%;
}
.c-hero__item {
align-self: center;
width: 50%;
}
.c-hero__quote {
font-size: 36px;
}
答案 0 :(得分:0)
这样的东西?
body {
margin: 0;
height: 1200px;
}
.c-hero {
align-items: center;
display: flex;
justify-content: center;
background: green;
height: 400px;
text-align: center;
width: 100%;
position: relative;
}
.c-hero__image {
object-fit: cover;
object-position: center;
min-height: 100%;
min-width: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate( -50%, -50% );
z-index: 0;
}
.c-hero__item {
align-self: center;
width: 50%;
}
.c-hero__quote {
font-size: 36px;
position: relative;
z-index: 1;
}
<div class="c-hero">
<img class="c-hero__image" src="https://snag.gy/mZNKqJ.jpg">
<div class="c-hero__item">
<p class="c-hero__quote">quote</p>
</div>
</div>