html - Center div inside a div vertically -


i have tried methods find .. , nothing worked me... can wrap head around problem of aligning div (or block element) inside div .. difficult..

i want align green block vertically.

here fiddle: http://fiddle.jshell.net/795st/1/

<div class="rtl centerwrapper">     <div class="green-block pull-right"></div>     <div class="green-block pull-right"></div>     <div class="green-block pull-right"></div>     <div>average</div> </div>  .green-block {     background-color: #02a556;     margin: 0 .25em 0 .25em !important;     width: 1em;     height: 0.5em; } .pull-right {     float: right; } .rtl {     direction:rtl; } .centerwrapper {     position: absolute;     top: 50%;     left: 0px;     width: 100%;     overflow: visible; } 

please .. can 1 .. , explain dooing wrong ?

edit: let me more clear... need element in 1 line. blocks needs aligned @ vertical middle of text.

edit2: here image

enter image description here

new answer

here new fiddle link http://fiddle.jshell.net/795st/16/

css

.green-block {     background-color: #02a556;     margin: 0 .25em 0 .25em !important;     width: 1em;     height: 0.5em;     vertical-align: middle;     position: relative;     } .pull-right {     display: inline-table; } .rtl {     direction:rtl; } .centerwrapper {     position: absolute;     top: 50%;     left: 0px;     width: 100%;     overflow: visible; }  html <div class="rtl centerwrapper">      <div class="green-block pull-right"></div>     <div class="green-block pull-right"></div>     <div class="green-block pull-right"></div>     <div class="pull-right">average</div> </div> 

screenshot of output

center aligned divs

old answer

here required output http://fiddle.jshell.net/795st/5/

.pull-right {     display: inline-table; }  .centerwrapper {     position: absolute;     top: 50%;     left: 0px;     width: 100%;     overflow: visible;     text-align: center; } 

for inner divs added display inline-table not treated block element , shown in 1 line. outer div added text-align center. show contents in center.

only 2 changes done fiddle.

  1. for inner div instead of float: right added display:inline-table
  2. and outer div added text-align:center.

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -