繁体   English   中英

Flexbox无法在移动设备上垂直居中

[英]flexbox not centering vertically on mobile

我已经使用引导程序制作了一个模板,并且正在使用flexbox将着陆页内容垂直和水平居中。 它在台式机上看起来不错(检查了chrome和Firefox),但在移动设备上(检查了chrome和safari)它浮动到顶部。 我已经在网上搜索过,但是没有找到适合我的解决方案。

我已经粘贴了代码,实时版本位于http://webcanvases.com/download-theme/theme/material-theme.html

的HTML

<!-- Landing Page -->
<div class="video-bg vertical-center" id="page-top" data-vide-bg="mp4/traffic2">  
    <div class="jumbotron container text-center">
        <h1>Material World<br>Theme</h1> 
        <a data-scroll href="#about"><span class="glyphicon glyphicon-menu-down animated bounce"></span></a>
    </div>
</div>
<!-- Landing Page End -->

的CSS

.vertical-center {
    display: flex;
    justify-content: center;
    align-items: center;
}

.video-bg {
    height: 800px;
    min-width: 100%;
}

它不起作用,因为您必须在外部容器上设置flex属性。 然后,内部的元素将遵循flex属性。

 .vertical-center { display: flex; align-items: center; justify-content: center; height: 100vh; background: #ccc; } .video-bg { width: 400px; height: 300px; background: yellow; } 
 <div class="vertical-center"> <div class="video-bg"></div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM