在Div的中间居中文本

时间:2015-03-21 14:47:32

标签: css html5

我试图将时间集中在div中。我知道我用内联css控制它。我想可以做任何一件事。

基本上只是尝试在div的中间对齐文本对齐 - vertical-align:middle; - 不工作。图像是当前的外观 - 你可以看到它已关闭......

current look

思考?

  <div style="top: 50%; position: relative; font-family: Verdana; font-size: 10pt; color: green; height: 30px; border-top:1px solid ##000;">
  7:45 am
  </div>

5 个答案:

答案 0 :(得分:0)

你读过这个帖子吗?

div vertical align middle css

也许它会对你有所帮助:)。

答案 1 :(得分:0)

尝试text-align:center

http://jsfiddle.net/Lybfn4ph/

  <div style="top: 50%; position: relative; font-family: Verdana; font-size: 10pt; color: green; height: 30px; border:1px solid black;text-align:center;">
   7:45 am
  </div>

答案 2 :(得分:0)

试试这个:

div {
    text-align: center;
}

答案 3 :(得分:0)

添加line-height样式等于height

div {
  font-family: Verdana; font-size: 10pt; 
  color: green; 
  height: 60px;
  line-height: 60px;
  border:1px solid #000;
  text-align: center;
  width: 100px;
}
<div>7:45 am</div>

答案 4 :(得分:0)

最佳解决方案是

<div style="top: 50%; position: relative; font-family: Verdana; font-size: 10pt; color: green; height: 30px; border:1px solid black; text-align:center;">
7:45 am
</div>
相关问题