使用CSS水平对齐 [英] Horizontal alignment with CSS

查看:114
本文介绍了使用CSS水平对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<div class="one">
   <p>Test<p><span style="color: Green">▼</span>
</div>

这是一个很简单的问题,我想,但我不知道CSS。如何使段落在中心水平对齐?

This is a really easy question I think but I don't know CSS. How can I make the paragraph appear aligned horizontal in the center?

推荐答案

这里有两个问题。


  1. 将包含该段落的DIV居中。

  2. DIV。

为了使DIV居中,下面是使用内嵌样式的代码:

To center the DIV, here's the code using inline styling:

<div style="margin: 0 auto" class="one">
    <p>Test<p>
</div>

上面将使整个DIV居中,但不会将文本与中心对齐。同样,如果类one具有指定的宽度,div将只得到中心。否则,它没有效果。您还可以在名为one的类中包含边距样式信息。

The above will center the whole DIV but NOT align the text to the center. Again, the div will only get centered if the class "one" has a width specified. Otherwise, it has no effect. You can also include the margin style info inside the class named "one".

现在,为了对齐在DIV中水平出现的所有文本,您可以:

Now, to align all text that appear within the DIV horizontally, you can style it like this:

<div style="text-align: center" class="one">
    <p>Test<p>
</div>

如果要仅将中心样式应用于单个段落,可以包括样式< p> 标签中的规则。

And if you want to apply the centering style only for a single paragraph, you can include the the style rule within the <p> tag.

这篇关于使用CSS水平对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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