vertical-align with Bootstrap 3

后端 未结 25 2959
庸人自扰
庸人自扰 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:56

    This answer presents a hack, but I would highly recommend you to use flexbox (as stated in @Haschem answer), since it's now supported everywhere.

    Demos link:
    - Bootstrap 3
    - Bootstrap 4 alpha 6

    You still can use a custom class when you need it:

    .vcenter {
        display: inline-block;
        vertical-align: middle;
        float: none;
    }
    Big
    Small

    Bootply

    Using inline-block adds extra space between blocks if you let a real space in your code (like ...

...). This extra space breaks our grid if column sizes add up to 12:

Big
Small

Here, we've got extra spaces between

and
(a carriage return and 2 tabs/8 spaces). And so...

Enter image description here

Let's kick this extra space!!

Big
Small

Enter image description here

Notice the seemingly useless comments ? They are important -- without them, the whitespace between the

elements will take up space in the layout, breaking the grid system.

Note: the Bootply has been updated

提交回复
热议问题