【问题标题】:Centering columns in flexboxflexbox 中的列居中
【发布时间】:2016-09-15 00:47:42
【问题描述】:

这是我的目标

Flex 有效,居中也有效。但两者都不起作用:/ 由于 flex,centered 选项不再起作用。

我认为,这是由于 CSS 中的那些部分带有两个显示:

.row-flex, .row-flex > div[class*='col-']
{  
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex; /* same height */
        flex: 0 auto;
}

.col-centered
{
        display: inline-block; /* centered */
        float: none;
        text-align: left;
        margin-right: -4px;
}

这是我的Bootplyhttp://www.bootply.com/rrpj1Y1cBB

我该如何解决这个问题?谢谢

【问题讨论】:

    标签: html twitter-bootstrap css flexbox


    【解决方案1】:
    .row-flex, .row-flex > div[class*='col-'] {
    
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            flex: 0 auto;
    
            justify-content: center;       /* NEW; center flex items horizontally */
            align-items: center;           /* NEW; center single-line flex items vertically */
            align-content: center;         /* NEW; center multi-line flex items vertically */
    
    }
    

    Revised Demo

    更多详情:How to Center Elements Vertically and Horizontally in Flexbox

    【讨论】:

    • 哦!只是justify-content: center; 做我想做的事(居中+ 相同高度),因为在您的Bootply 中,列不再具有相同的高度。谢谢 :) (感谢您的编辑
    猜你喜欢
    • 2019-02-14
    • 1970-01-01
    • 2016-08-06
    • 2014-10-21
    • 2019-04-01
    • 2020-06-17
    • 2020-07-27
    • 2023-03-24
    • 2021-03-29
    相关资源
    最近更新 更多