vertical-align with Bootstrap 3

后端 未结 25 2396
庸人自扰
庸人自扰 2020-11-21 05:34

I\'m using Twitter Bootstrap 3, and I have problems when I want to align vertically two div, for example — JSFiddle link:

25条回答
  •  野的像风
    2020-11-21 05:58

    I thought I'd share my "solution" in case it helps anyone else who isn't familiar with the @media queries themselves.

    Thanks to @HashemQolami's answer, I built some media queries that would work mobile-up like the col-* classes so that I could stack the col-* for mobile but display them vertically-aligned in the center for larger screens, e.g.

    .

    .row-xs-flex-center {
        display:flex;
        align-items:center;
    }
    @media ( min-width:768px ) {
        .row-sm-flex-center {
            display:flex;
            align-items:center;
        }
    }
    @media ( min-width: 992px ) {
        .row-md-flex-center {
            display:flex;
            align-items:center;
        }
    }
    @media ( min-width: 1200px ) {
        .row-lg-flex-center {
            display:flex;
            align-items:center;
        }
    }
    

    More complicated layouts that require a different number of columns per screen resolution (e.g. 2 rows for -xs, 3 for -sm, and 4 for -md, etc.) would need some more advanced finagling, but for a simple page with -xs stacked and -sm and larger in rows, this works fine.

提交回复
热议问题