0

demo

div{
    display: table-cell;
    height: 100px;
    background-color: red;
    vertical-align: middle;
    /*position: absolute;*/
}

In the above demo If you remove the comment from position: absolute; the vertical-align won't work.

I also found this question but here is added a parent div. But in my case, I need without touching up markup. Any idea?

Community
  • 1
  • 1
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231

4 Answers4

0

here is the refrence for ur detail position: absolute forces display: block, read number two here.

As for a workaround, I think you'll have to wrap it in another element:

Hushme
  • 3,108
  • 1
  • 20
  • 26
0

Check this fiddle as a workaround..http://jsfiddle.net/DjGQ5/ Change display : block and Wrapped text in p tag with padding-top: 50% property in css

Nitin Agrawal
  • 1,341
  • 1
  • 10
  • 19
0

Wow! I did it. See this demo

div{
    display: table-cell;
    height: 100px;
    background-color: red;
    vertical-align: middle;
    position: absolute;
}
div:before{content: " "; height: 50%; display: inline-block;}
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0

Jus make Position:relative Its fine now... Updated the fiddle.. Here is the link..

Demo

Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200