相当于< center>标签在CSS? [英] Equivalent to <center> tag in CSS?

查看:233
本文介绍了相当于< center>标签在CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到< center> 标签已弃用,但我在CSS中找不到任何真正的等价物。 text-align 适用于文本,但不适用于其他元素,并且自动边距只有在你知道容器的宽度时才会起作用(如果你不知道宽度提前)。那么是否有任何真正的等价于这个< center> 标签?

I read that the <center> tag is deprecated, however I cannot find any real equivalent to it in CSS. text-align works for text but not other elements, and auto margins only work if you know the width of the container (so not a solution if you don't know the width in advance). So is there any real equivalent to this <center> tag?

推荐答案

p> text-align应该适用于其他种类的元素。这是否有效?

text-align should work for other kinds of elements. Does this work?

.center { margin: auto; text-align: center; }

编辑三年后:-D

margin:auto;也使顶部和底部边距自动。这可能不是你想要的。或者,你可以有类似的:

"margin: auto;" also makes the top and bottom margins "auto". That might not be what you want. Alternatively you could have something like:

.center { margin-left: auto;
          margin-right: auto;
          margin-top: 3px;
          margin-bottom: 3px;
          text-align: center; }

这个特定的示例将水平放置文本的中心,同时将上边距和下边距硬连线为3像素。

This particular example will center the text horizontally while hardwiring the upper and lower margins to 3 pixels.

也可以说margin:3px auto 3px auto;但我更喜欢详细说明方向,因为我永远不会记得参数的顺序,如果我把它们都放在一个margin:设置。

One can also say something like "margin: 3px auto 3px auto;" but I prefer spelling out the directions explicitly, as I can never quite remember what the order of the parameters are, if I put them all on the one "margin:" setting.

这篇关于相当于&lt; center&gt;标签在CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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