html - 使用 <div> <a> <p> 在分区内水平对齐文本时出现问题

标签 html css

我不知道为什么我遇到了这个麻烦。请看截图:

screenshot

我的 CSS 是这样的:

#tabbase {
   display : inline-block;
   width : 230px;
   height : 173px;
   border : 1px solid #3e3e3e;
   background-color : #1b1b1b;
   box-shadow : 0px 0px 4px 2px rgba(0, 0, 0, 0.4) inset;
   margin-top : 6px;
}

#tabbase a {
   display : block;
   height : 43px;
   text-decoration : none;
   font-family : 'Nexa Bold';
   font-size : 24px;
}

#tabbase a p {
   text-align : center;
}

这是 html:

<div id = "tabbase">
   <a id = "blog" href = "#"> <p> Blog </p> </a>
   <a class = "batl" href = "#"> <p> Home </p> </a>
   <a class = "batl" href = "#"> <p> Contact </p> </a>
   <a class = "batl" href = "#"> <p> Samples </p> </a>
</div>

我不知道为什么这在 css 中如此困难,其他一切都很容易。我试过边距、填充、边框、垂直对齐和现在的文本对齐。

为什么它不起作用?

p.s:如果有帮助,<a id = "blog"> 的背景图片标签是这个 css:

#tabbase #blog {
   color : #000000;
   background-image : url('Tab.png');
}

当我使用 span 我得到这个:

screenshot 2

当我添加 text-align:center; 时到 anchor 标记我得到这个:

https://dl.dropbox.com/u/107533178/Screen%20shot%202012-10-21%20at%202.18.38%20PM.png

最佳答案

你可以尝试这种风格:

#tabbase *
{
  text-align:center;
  vertical-align:middle;
}

它将 DIV#tabbase 的所有子项设置为水平和垂直居中。

关于html - 使用 <div> <a> <p> 在分区内水平对齐文本时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12997255/

相关文章:

css - 即使里面有内容,div 也不会扩展

html/css : Draw borders through a table cell

html - 你如何改变导航栏的颜色

jquery - 无限滚动 jQuery 插件 : how to fix loading graphic from "animating" left to center of page?

jquery - 我可以在选择列表的末尾移动一个选项吗?

jquery - 单击时放大这些缩略图的最佳方法是什么?图片目前没有链接

html - CSS 在 CodePen 中不工作

javascript - 全屏图像,图像放置在 html 中

html - 将 h2 垂直底部对齐

html - 如何使导航左对齐?