
Originally Posted by
maya90
so what do you have to do to make vertical-align:middle work??
As Maleika said above vertical-align only applies to inline elements (and table-cells). It was never meant to vertically align block elements.
display:table-cell is the easiest solution and works in IE8+ and all other browsers that are in use. If you want IE7 support then you need to add a hack like this:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.outer {
overflow: hidden;
width: 134px;
height: 149px;
background:#ccc;
float:left;
margin: 10px;
white-space:nowrap;
display:table;
}
.outer ul {
margin:0;
padding:0;
list-style:none;
width:134px;
display:table-cell;
vertical-align:middle;
position:relative;
}
.outer li{
width:100%;
position:relative;
}
.outer li a{
display:block;
padding:0 10px;
background:#666;
zoom:1.0;
position:relative
}
.outer li a:hover{background:red}
* html .outer ul {top:50%}/* ie6 hack*/
* html .outer li {top:-50%}/* ie6 hack*/
*+html .outer ul {top:50%}/* ie6 hack*/
*+html .outer li {top:-50%}/* ie6 hack*/
</style>
</head>
<body>
<div class="outer">
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</div>
<div class="outer">
<ul>
<li><a href="#">Link 3</a></li>
</ul>
</div>
<div class="outer">
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</div>
</body>
</html>
Bookmarks