vertical-align: middle with Bootstrap 2

105,124

Solution 1

Try this:

.row > .span3 {
    display: inline-block !important;
    vertical-align: middle !important;
}

Edit:

Fiddle: http://jsfiddle.net/EexYE/

You may need to add Diego's float: none !important; also if span3 is floating and it interferes.

Edit:

Fiddle: http://jsfiddle.net/D8McR/

In response to Alberto: if you fix the height of the row div, then to continue the vertical center alignment you'll need to set the line-height of the row to be the same as the pixel height of the row (ie. both to 300px in your case). If you'll do that you will notice that the child elements inherit the line-height, which is a problem in this case, so you will then need to set your line height for the span3s to whatever it should actually be (1.5 is the example value in the fiddle, or 1.5 x the font-size, which we did not change when we changed the line-height).

Solution 2

Try removing the float attribute from span6:

{ float:none !important; }
Share:
105,124
bgondy
Author by

bgondy

Updated on July 28, 2020

Comments

  • bgondy
    bgondy almost 4 years

    I use the twitter bootstrap and I wanted to align verticaly a div block with a picture and the text at the right.

    Here is the code:

    <ol class="row" id="possibilities">
         <li class="span6">
             <div class="row">
                 <div class="span3">
                     <p>some text here</p>
                     <p>Text Here too</p>
                 </div>
                 <figure class="span3"><img src="img/screenshots/options.png" alt="Some text" /></figure>
             </div>
         </li>
         <li class="span6">
             <div class="row">
                 <figure class="span3"><img src="img/qrcode.png" alt="Some text" /></figure>
                 <div class="span3">
                     <p>Some text</p>
                     <p>Some text here too.</p>
                 </div>
             </div>
         </li>
    </ol>
    

    I tried this but not wortks:

    .span6 .row{display: table;}
    .span6 .row .span3, .span6 .row figure{display:table-cell; vertical-align: middle;}
    

    I tried this too:

    .span6 .row .span3{display: inline-block; vertical-align: middle;}
    

    None is working. Does somebody have an idea? Thanks in advance.