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!

4

1 回答 1

2

vertical-align属性不适用于块级元素,仅适用于内联格式上下文和表格单元格中的元素

您可以添加display: table-cell;到您的.insideDiv类以垂直居中其文本:

示例:http: //jsfiddle.net/Adrift/qTkAN/1/

于 2013-05-02T00:17:49.390 回答