文本对齐对齐,无法覆盖 [英] text-align justify, cannot override
问题描述
我有一些带有 text-align:justify;
的文本,该属性在该文本的链接和其他嵌套的嵌入式元素中继承.我想为其中的一些设置其他文本对齐方式,例如 text-align:center;
,但是我不能.Firebug显示父样式已被覆盖,但是嵌套的内联元素仍然合理.我观察到在许多不同的浏览器中都有这种奇怪的行为,很明显,它们是按规范进行的?这真的是设计使然吗?如何解决呢?
I have some text with text-align: justify;
the property is inherited in links and other nested inline elements in that text. I want to set other text-align mode to some of them, for example text-align: center;
, but I cannot. Firebug shows that the parent style is overridden, but the nested inline element is still justified. I observed that strange behavior in many different browsers and obviously they are doing this by spec? Is that really by design? How to work around it?
一些示例代码.ID = span1的范围不能定义其自己的文本对齐方式.它应右对齐,但应居中.在进行实验时,我注意到内联元素根本无法定义任何文本对齐方式.很奇怪.
Some example code. The span with ID=span1 cannot define its own text align. It should be right aligned, but it is centered instead. While I was experimenting I noticed that inline elements cannot define any text alignment at all. Very strange.
<html>
<head>
<style type="text/css">
#cubic { width: 495px; height: 200px; background-color: green; text-align: center}
#span1 {text-align: right; color: red}
</style>
</head>
<body>
<p id="cubic">
<span id="span1">This is span 1</span>
</p>
</body>
</html>
推荐答案
正确;内联元素不能设置文本对齐方式,除非将其设置为显示块.
Correct; inline elements cannot have a text-align set, unless they're set to display block.
简单的例子:
<html>
<style>
#spanInline {text-align:right;}
#spanBlock {text-align:right;display:block;}
#divBlock {text-align:right;}
#divInline {text-align:right;display:inline;}
</style>
<body>
<span id="spanInline">asdf</span><br />
<span id="spanBlock">asdf</span><br />
<div id="divBlock">asdf</div><br />
<div id="divInline">asdf</div><br />
</body>
</html>
如果在元素周围加上边框,则会看到更多关于为什么不起作用的信息.
If you throw borders around the elements, you'll see more information on why this doesn't work.
这篇关于文本对齐对齐,无法覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!