admin管理员组文章数量:1405392
I am working on a hero section where I need to:
- Have a background video covering the full screen.
- Overlay an iceberg image on top of the video, positioned properly at the bottom.
- Ensure text is centered above both the video and the iceberg.
- Make it responsive so that the iceberg and text scale properly on different screen sizes.
.hero-section {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.hero-video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: 1;
}
.iceberg {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 60%;
max-width: 600px;
height: auto;
z-index: 2;
}
.hero-content {
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
z-index: 3;
width: 80%;
}
<div class="hero-section"> <!-- Background Video --> <video class="hero-video" autoplay loop muted playsinline> <source src=".mp4" type="video/mp4"> Your browser does not support the video tag. </video>
<!-- Iceberg Image -->
<img src=".png" class="iceberg" alt="Iceberg">
<!-- Overlay Content -->
<div class="hero-content">
<h1>THESE CHALLENGES DON’T HAVE TO DEFINE YOUR LOYALTY PROGRAM.</h1>
<p>Let’s turn the submerged into the summit with GRAVTY®.</p>
<a href="#" class="btn">CONTACT US</a>
</div>
</div>
I am working on a hero section where I need to:
- Have a background video covering the full screen.
- Overlay an iceberg image on top of the video, positioned properly at the bottom.
- Ensure text is centered above both the video and the iceberg.
- Make it responsive so that the iceberg and text scale properly on different screen sizes.
.hero-section {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.hero-video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: 1;
}
.iceberg {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 60%;
max-width: 600px;
height: auto;
z-index: 2;
}
.hero-content {
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
z-index: 3;
width: 80%;
}
<div class="hero-section"> <!-- Background Video --> <video class="hero-video" autoplay loop muted playsinline> <source src="https://lji-test.loyaltycloud1/assets/images/Aurora_video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
<!-- Iceberg Image -->
<img src="https://i.sstatic/nugUb6pP.png" class="iceberg" alt="Iceberg">
<!-- Overlay Content -->
<div class="hero-content">
<h1>THESE CHALLENGES DON’T HAVE TO DEFINE YOUR LOYALTY PROGRAM.</h1>
<p>Let’s turn the submerged into the summit with GRAVTY®.</p>
<a href="#" class="btn">CONTACT US</a>
</div>
</div>
Reference image:
Video reference
https://lji-test.loyaltycloud1/assets/images/Aurora_video.mp4
Share Improve this question edited Mar 25 at 8:47 Ori Drori 194k32 gold badges238 silver badges229 bronze badges asked Mar 25 at 7:29 Prasad GudipalliPrasad Gudipalli 91 silver badge 2 |1 Answer
Reset to default 1If you set the background-image
of the hero-section rather than an inline img
element you can set the z-index ( as negative or lower ) for the video to appear behind the hero-section. You can fudge around with the background-position to move the iceberg if you need as the result appears different in the snippet editor to the preview here.
body,body *{
font-family:monospace;
}
body{
padding:0;
margin:0;
height:100vh;
width:100%;
}
.hero-section {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
margin:0;
background-image:url("https://i.sstatic/nugUb6pP.png");
background-size:100%;
background-repeat:no-repeat;
background-position:50% 20%;
color:white;
}
.hero-video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -1;/* set the video behind hero image */
}
.hero-content {
text-align: center;
z-index: 3;
width: 80%;
}
<div class="hero-section">
<video class="hero-video" autoplay loop muted playsinline>
<source src="https://lji-test.loyaltycloud1/assets/images/Aurora_video.mp4" type="video/mp4" /> </video>
<div class="hero-content">
<h1>THESE CHALLENGES DON’T HAVE TO DEFINE YOUR LOYALTY PROGRAM.</h1>
<p>Let’s turn the submerged into the summit with GRAVTY®.</p>
<a href="#" class="btn">CONTACT US</a>
</div>
</div>
本文标签: htmlHow to overlay Video and iceberg image correctly with responsive scalingStack Overflow
版权声明:本文标题:html - How to overlay Video and iceberg image correctly with responsive scaling? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744212785a2595498.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
* { box-sizing: border-box; padding: 0; margin: 0; }
– Sigurd Mazanti Commented Mar 25 at 8:54