html - How to center horizontal table-cell and content inside it in the middle -


i building on question asked here how center horizontal table-cell slight modification.

basically, divs need centered now, however, need vertically align content in cell in middle.

changing vertical-align: middle; .column nothing. if change display: inline-block; .column display: table-cell, align content in middle, .column divs no longer centered , widths broken (currently evenly set 25%). setting margin:auto; or text-align on parent nothing.

i've been running around days. appreciated.

/* setting container table maximum width , height */  #container {  	display: table;  	height: 100%;  	width: 100%;  }  /* sections (container's children) should table rows minimal height */    .section {  	display: table-row;  	min-height: 1px;  }    /* need 1 container, setting full width */  .columns-container {  	display: table-cell;  	height: 100%;  	width:100%;  	text-align: center;  }  /* creating columns */  .column {      display: inline-block;   	vertical-align: middle;  	min-height: 150px;  	width: 25%;  	text-align: left;  }  #a {  	background-color: pink;  }  #b {  	background-color: lightgreen;  }  #c {  	background-color: lightblue;  }
<div id="container">    <div class="section">      <div class="columns-container">        <div class="column" id="a"> contents </div>        <div class="column" id="b"> contents b </div>        <div class="column" id="c"> contents c </div>      </div>    </div>  </div>

you follows, uses css3 transforms, see browser support details. , aware of white spaces thing on inline block.

jsfiddle demo

.container {      text-align: center;      margin: 0 auto;  }  .column {      display: inline-block;      width: 150px;      height: 150px;  }  .column > div {      position: relative;      top: 50%;      transform: translatey(-50%);  }  #a { background-color: pink; }  #b { background-color: lightgreen; }  #c { background-color: lightblue; }
<div class="container">      <div class="column" id="a"><div>contents a</div></div>      <div class="column" id="b"><div>contents b</div></div>      <div class="column" id="c"><div>contents c</div></div>  </div>


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -