简体   繁体   English

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

[英]flexbox not centering vertically on mobile

I have made a template using bootstrap and I am using a flexbox to vertically and horizontally center my landing page content. 我已经使用引导程序制作了一个模板,并且正在使用flexbox将着陆页内容垂直和水平居中。 It looks fine on a desktop(chrome and firefox checked), but on mobile(chrome and safari checked) it floats to the top. 它在台式机上看起来不错(检查了chrome和Firefox),但在移动设备上(检查了chrome和safari)它浮动到顶部。 I have searched the web but have not found a solution that has worked for me. 我已经在网上搜索过,但是没有找到适合我的解决方案。

I have pasted in my code and the live version is at http://webcanvases.com/download-theme/theme/material-theme.html 我已经粘贴了代码,实时版本位于http://webcanvases.com/download-theme/theme/material-theme.html

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 的CSS

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

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

It's not working because you have to set the flex properties on an outer container. 它不起作用,因为您必须在外部容器上设置flex属性。 Then the elements on the inside will follow the flex properties. 然后,内部的元素将遵循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