【发布时间】:2011-08-05 01:36:47
【问题描述】:
我有一个 CSS 帮助器类,旨在强制“文本”的最后一行(或在预期用途中,内联块 div)与其余部分一样对齐。
这是我得到的代码:
.justify-all-lines
{
text-align: justify;
/* IE-only properties that make the :after below unnecessary (we need this because IE 6/7 don't support :after, though) but if they both apply it'll be fine */
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
}
.justify-all-lines > *:last-child:after
{
display: inline-block;
width: 100%;
content: 'hello';
}
.blocky
{
display: inline-block;
/* Make inline block work in IE 6/7 */
zoom: 1;
*display: inline;
}
这是打算这样使用的:
<div class="justify-all-lines">
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
<div class="blocky">There is stuff in here.</div>
</div>
但是,我看到“hello”出现在最后一个“blocky”div 内部,而不是最后一个“blocky”div 之后。我做错了什么?
【问题讨论】:
-
.justify-all-lines > *:last-child:after { /* stuff for IE6/7 */ }很奇怪。 IE6不支持>,IE6/7都不支持:last-child或:after。 -
您目前正在测试哪些浏览器?你能做一个jsFiddle 演示来展示这个问题吗?
-
@thirtydot 我正在使用 dotless (dotlesscss.org),这只是复制和粘贴异常,因为我为了这篇文章的目的将 mixin 转换为内联 CSS。认为比 LESS 更多的人会熟悉纯 CSS。我会修复它。 ;)
-
“我看到 'hello' 出现在最后一个 'blocky' div 里面”——它应该这样做。它不会创建新元素,但(至少显然)将内容附加到指定元素。
-
这是一个显示问题的 jsFiddle 演示:jsfiddle.net/Rk79Y
标签: css