1

如何在下图中将文本居中

我有这个

.flag{ 
    background: url('flag.png') no-repeat;
    width:120px; 
height:120px; 
}
</style>

<div class="flag">WOW</div>

这就是它目前的显示方式 文本对齐错误

4

3 回答 3

2
text-align: center;
line-height: 120px;
于 2012-08-18T21:19:52.370 回答
2

尝试:

.flag{ 
    background: url('flag.png') no-repeat;
    width:120px; 
    height:120px;
    text-align:center;
    line-height:120px;
  }
于 2012-08-18T21:20:16.883 回答
2

利用

.flag{ 
    background: url('flag.png') no-repeat;
    width:120px; 
    height:120px; 
    line-height:120px; /* same as height */
    text-align:center;
}
于 2012-08-18T21:20:17.063 回答