【问题标题】:How can I make these two divs with text responsive?如何使这两个 div 具有文本响应?
【发布时间】:2016-06-06 09:57:47
【问题描述】:

我有两个这样的 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>

我希望启动消息显示在启动子消息的顶部,如下所示: 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;
}   

感谢任何帮助,谢谢!

【问题讨论】:

    标签: html css text responsive-design


    【解决方案1】:

    使用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>

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 2018-09-27
      • 2018-08-09
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多