如何使这两个div具有文本响应?

时间:2016-06-06 09:57:48

标签: html css text responsive-design

我有两个这样的div:

    <div id="splash-container">
     <video id="splash-video" preload autoplay loop muted>
        <source src="videos/splash.mp4" type="video/mp4" />Your browser does not support the video tag. I suggest you upgrade your browser.
     </video>
     <div id="splash-message">MAYUR BHADRACANT</div>
     <div id="splash-submessage">ONLINE PROFILE</div>
   </div>

我想将splash-message显示在splash-submessage之上,如下所示: http://prntscr.com/bcxu1r

但是当我调整浏览器大小时:会发生这种情况: http://prntscr.com/bcxuec

我现在的css是:

    #splash-container {
position: relative;
overflow: hidden;
width: 100vw;
max-width: 100%;
min-height: 100px;
text-align: center;
margin: 0 auto;
}

    #splash-message {
position: absolute;
font-weight: bold;
z-index: 1;
color:white;
font-weight: 300;
letter-spacing: 7px;
left: 0;
width: 100%;
text-align: center;
font-size: 35.5px;
top:40vh;
}


#splash-submessage {
position: absolute;
color: white;
z-index: 1;
font-weight: 300;
letter-spacing: 7px;
left: 0;
width: 100%;
text-align: center;
font-size: 22px;
top:50vh;
}   

感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:2)

使用Flexbox,您可以将messagesubmessage置于中心,然后您可以使用视频上的position: absolute将其从元素流中移除,然后再使用transform: translate()以此为中心。

body,
html {
  margin: 0;
  padding: 0;
}
#splash-container {
  display: flex;
  height: 100vh;
  flex-direction: column;
  position: relative;
  align-items: center;
  justify-content: center;
}
video {
  border: 1px solid black;
  top: 50%;
  left: 50%;
  position: absolute;
  transform: translate(-50%, -50%);
}
<div id="splash-container">
  <video id="splash-video" preload autoplay loop muted>
    <source src="videos/splash.mp4" type="video/mp4" />Your browser does not support the video tag. I suggest you upgrade your browser.
  </video>
  <div id="splash-message">MAYUR BHADRACANT</div>
  <div id="splash-submessage">ONLINE PROFILE</div>
</div>