我正在try 使用视频作为循环和静音的背景.问题是,我想要有一个标题和副标题在视频的中心.不过,当在视频中使用位置:绝对这样的内容时,它会 destruct 页面的完全响应性.
我试着在视频上设置绝对位置,如果它不应该有react 的话,它确实可以工作.我也try 了一些相对位置的东西,尽管文本在视频的右侧(因为它是行中的第二个弹性项).如何正确地将文本居中放置在背景视频上?对于图片,我倾向于使用background-image
标签,根据我的研究,这对视频不起作用.
<div className='homeImage'>
<video loop autoPlay muted>
<source src={video} type="video/mp4"/>
</video>
<div className='home-content'>
<h1 className='mb-4'>My Name</h1>
<h2>This is a blog</h2>
</div>
</div>
.homeImage{
background-color: black;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.home-content{
height: 100vh;
width: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.home-content h1{
font-size: 90px !important;
color: #fff !important;
z-index: 10;
}
.home-content h2{
font-size: 40px !important;
color: #fff !important;
z-index: 10;
}
.homeImage img,video{
opacity: 0.5;
height: 100vh;
z-index: 0;
width: 100%;
object-fit: cover;
position: absolute;
}
@media (max-width: 767px){
.home-content h1{
font-size: 60px !important;
}
.home-content h2{
font-size: 35px !important;
}
}
@media (max-width: 497px){
.home-content h1{
font-size: 30px !important;
}
.home-content h2{
font-size: 20px !important;
}
}
This is how it looks after modifying the CSS:
所以遗憾的是它仍然没有react