How to use vertical align in bootstrap

后端 未结 8 2051
北恋
北恋 2020-11-29 22:29

Simple problem: How do I vertically align a col within a col using bootstrap? Example here (I want to vertically align child1a and child1b):

http://bootply.com/7366

相关标签:
8条回答
  • 2020-11-29 22:56

    Prinsen's answer is the best choice. But, to fix the issue where the columns don't collapse his code needs to be surrounded by a media check statement. This way these styles are only applied when the larger columns are active. Here is the updated complete answer.

    HTML:

    <div class="row display-table">
        <div class="col-xs-12 col-sm-4 display-cell">
            img
        </div>
        <div class="col-xs-12 col-sm-8 display-cell">
            text
        </div>
    </div>
    

    CSS:

    @media (min-width: 768px){
       .display-table{
           display: table;
           table-layout: fixed;
       }
    
       .display-cell{
           display: table-cell;
           vertical-align: middle;
           float: none;
       }
    }
    
    0 讨论(0)
  • 2020-11-29 23:00

    For the parent: display: table;

    For the child: display: table-cell;

    Then add vertical-align: middle;

    I can make a fiddle but home time now, yay!

    OK here is the lovely fiddle: http://jsfiddle.net/lharby/AJAhR/

    .parent {
       display:table;
    }
    
    .child {
       display:table-cell;
       vertical-align:middle;
       text-align:center;
    }
    
    0 讨论(0)
提交回复
热议问题