我有一个问题,将文本放在我的div内。有人能帮我把这段文字和盒子的中间对齐吗?

这是我的css:
#btc-container {
height: 50px;
width: 150px;
background: orange;
border: 2px solid;
border-radius: 25px;
bottom: 50px;
left: 0px;
border-style: ridge;
}
#btc-price {
color: black;
font-family: digital-7;
font-size: 30px;
alignment-adjust:middle;
}下面是我在HTML中的内容:
<div id="btc-container">
<div id="btc-price">930.1234</div>
</div>发布于 2013-12-13 20:11:11
只需像这样更改css:
#btc-price {
color: black;
font-family: digital-7;
font-size: 30px;
text-align: center;
line-height: 50px; // or what ever is your button height
}发布于 2013-12-13 20:12:21
若要对齐文本,请使用text-align: center。要使文本垂直对齐变得更加复杂(特别是如果您希望跨浏览器和/或需要支持旧的浏览器),但是如果您知道div中的文本只有一行,那么一个简单的方法是在您的情况下使用line-height (比如line-height:50px )。
发布于 2013-12-13 20:13:06
http://jsfiddle.net/isherwood/uN2Dt/
#btc-price {
text-align: center;
margin-top: 8px;
}https://stackoverflow.com/questions/20575081
复制相似问题