【发布时间】:2020-06-17 13:06:03
【问题描述】:
我正在制作一个需要实现视差效果的非常简单的应用程序。
到目前为止我已经尝试过的事情,
-> 将图像放置在类 parallax 的 div 中。
-> 然后放置一个带有引导类 card item-card card-block 的覆盖 div,其中包含标题、图像和一些文本。
.parallax {
width: 100%;
height: 250px;
border-radius: 0;
}
.item-card {
flex-direction: column;
box-sizing: border-box;
display: flex;
place-content: center flex-start;
align-items: center;
margin: -24px 0 0;
width: 100%;
padding: 0;
border-radius: 18px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="container mt-2">
<div class="parallax">
<img style="width: 100%" src="https://www.w3schools.com/howto/img_parallax.jpg" />
</div>
<div class="card item-card card-block">
<h1 class="card-title text-center">Some big text here as headline</h1>
<div class="card-body">
<img style="width: 100%" src="https://static.pexels.com/photos/7357/startup-photos.jpg" alt="Photo of sunset">
</div>
<h5 class="item-card-title mt-3 mb-3">Sierra Web Development • Owner</h5>
<p class="card-text">This is a company that builds websites, web apps and e-commerce solutions.</p>
</div>
</div>
尝试将position:fixed 应用于parallax div,但这没有帮助。
图像 div 需要固定位置,然后下一个 div 卡需要在其上滚动。
将给定图像更改为背景图像会使整个 div 不是响应式的。
【问题讨论】:
标签: javascript html css sass parallax