css职位需要帮助

时间:2010-08-11 02:34:00

标签: html css

的HTML

<div class="navigation">
   <a class="active" href="index.html">1</a>
   <a href="index.html">2</a>
   <a href="index.html">3</a>
   <a href="index.html">4</a>
</div>

CSS

.navigation {
  float: left;
  height: 160px;
  position: relative;
  width: 24px;
}    
.navigation a {
  display: block;
}

任何人都可以帮助我如何在<a>内设置<div class="navigation"> 垂直中心。 <a> s范围的数量,因此我不能padding-top <div class="navigation"> {{1}}。

请帮忙。感谢。

3 个答案:

答案 0 :(得分:2)

text-align:center

.navigation {
  float: left;
  height: 160px;
  position: relative;
  width: 24px;
  text-align: center;
}    
.navigation a {
  display: block;
}

修改 如果您希望它垂直居中,则需要添加另一个垂直居中的边界框:

<style type='text/css'>
.navigation {
  float: left;
  height: 160px;
  position: relative;
  width: 24px;
  border: 3px solid black;
  text-align: center;
  display: table;
}    
.wrapper {
    vertical-align: middle;
    display: table-cell;
}
.navigation a {
  display: block;
}
</style>
<div class="navigation">
<div class='wrapper'>
   <a class="active" href="index.html">1</a>
   <a href="index.html">2</a>
   <a href="index.html">3</a>
   <a href="index.html">4</a>
</div>
</div>

答案 1 :(得分:2)

无论如何。如果您希望VERTICALLYHORIZONTALLY对齐(在所有浏览器中包括IE6,可能没有IE5.5 MAC):

See it in action.

.navigation {
  float: left;
  height: 160px;
  position: relative;
  width: 24px;
  text-align: center;
  display: table;
  _position: relative; 
  overflow: hidden;
}
.navigation_inner {
  _position: absolute; 
  _top: 50%; 
  display: table-cell; 
  vertical-align: middle;
}    
.navigation a {
  display: block;
}

HTML

<div class="navigation"> 
<div class="navigation_inner"> 
   <a class="active" href="index.html">1</a>
   <a href="index.html">2</a>
   <a href="index.html">3</a>
   <a href="index.html">4</a> 
</div> 
</div>​

答案 2 :(得分:1)

试试这个

.navigation {
  float: left;
  height: 160px;
  position: relative;
  width: 24px;
  vertical-align: middle;
}    
.navigation a {
  display: block;
}