0

My brain is fried so I need you guys help.

I am trying to do a vertical align in a div.

I have

html

<a href='#'>
  <div class="div">
     <div class="insideDiv">text here</div>
  </div>
</a>

My css

a {
   color: #006699;
   text-decoration: none;
   font-size: 10pt;
   border-width: 0;
   position: relative
}

.div{
  position: absolute;
  background-color: red;
  top: -75px;
  left: 50px;
  width: 100px;
  height: 50px;
  z-index: 1000;
  padding: 8px;
}

.insideDiv{
  background-color: white;
  width: 100px;
  height: 47px;
  border: solid 1px grey;
  font-weight: bold;
  vertical-align: middle;
  text-align: center;
}

It seems like text here can't be vertically align to middle but is horizontally align to center. Can anyone help me to solve this issue? Thanks so much!

Rouge
  • 3,891
  • 8
  • 25
  • 36

1 Answers1

2

The vertical-align property doesn't apply to block-level elements, only elements in the inline formatting context and table-cells

You can add display: table-cell; to your .insideDiv class to vertically center its text:

Example: http://jsfiddle.net/Adrift/qTkAN/1/

Jason Yaraghi
  • 51,338
  • 11
  • 87
  • 88