html - Vertically centering two <div class="span6">'s within Bootstrap -


edit: wanted clarify these spans have unknown height (because of responsiveness)!

i'm trying vertically align 2 <div class="span6">'s within <div class="row"> in bootstrap , i'm having problems using of usual tricks, such display: inline-block; or display: table-cell; (here's jsfiddle working on: http://jsfiddle.net/ma6za/).

here's trying use, not work in bootstrap:

<div class="container">     <div class="row" style="display: table">         <div class="span6" style="height: 300px; background: red; display: table-cell !important; vertical-align: middle;">             block 1 - vertically center me please!         </div>         <div class="span6" style="height: 170px; background: blue; display: table-cell !important; vertical-align: middle;">             block 2- center me         </div>     </div> </div> 

is possible vertically align these 2 .span6's such both height of block1 , block2 unknown? i'd use bootstrap because of responsible features, tablet+ we'd content vertically align.

i don't think you're making clear if want content of div's vertically centered or the actual div's themselves. anyway, there's solution both options:

vertically centering actual div's

first solution vertically aligns div's: jsfiddle

it works setting display: table; on .container , display: table-cell; on .row. once done can set vertical-align: middle; on .row vertically center content.

i have had manually force width of .row 960px, not responsive (you fix using media queries), margin-left of -20px bootstrap sets on .row doesn't work after setting display: table-cell; on .row. not forcibly adding these 20px result in second div ending below first because won't both fit on same line anymore. have set height: 100%;'s on elements demonstration purposes.

css

.container {     margin-top: 10px;     display: table;     height: 100%; } .row {     min-width: 960px;     display: table-cell;     height: 100%;     vertical-align:middle; } 

vertically centering div's contents

if wanted vertically center content of div's, can setting display: table; on .row , setting display: table-cell; on .span6. you'd need rid of float: left; on .span6 setting float: none.

here's fiddle demonstrating option: jsfiddle


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -