css center div不工作 [英] css center div not working

查看:67
本文介绍了css center div不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将音箱div居中,这是在评论div内。我似乎不能得到它的工作。 :(

I want to center the speaker div, which is within the review div. i cannot seem to get it working. :(

HTML:

<div class="review">
<div class="speaker">
<p>SPEAKER DIV</p>
</div>
</div>

CSS:

.speaker{
align:center;
}

不工作:/

推荐答案

没有这样的CSS属性 align

There’s no such CSS property as align.

当你说要将音箱div居中时,是什么意思?

When you say you want to "center" the speaker div, what exactly do you mean?

您可以像这样中心对齐其文本:

You can center-align its text like this:

.speaker {
    text-align:center;
}

(请参阅 http://jsfiddle.net/pauldwaite/X7LN5/

如果, ,您希望扬声器div只与其文本一样宽,并且位于评论div的中心,那么您需要使用:

If, alternatively, you want the speaker div to only be as wide as its text, and be positioned in the center of the review div, then you’d need to use this:

.review {
    text-align:center;
}

.speaker {
    display:inline-block;
}

(请参阅 http://jsfiddle.net/wxha4/

这篇关于css center div不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆