我有一个CSS帮助器类,旨在强制最后一行“text”(或在预期用途,内联块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之后。我做错了什么?
答案 0 :(得分:4)
工作解决方案:
.justify-all-lines
{
/* This element will need layout for the text-justify
* to take effect in IE7 (and possibly previous versions);
* this will force it, for more info Google "hasLayout in IE"
*/
overflow: hidden;
text-align: justify;
/* For IE6 to IE7 since they don't support :after */
-ms-text-justify: distribute-all-lines; /* IE8+ */
text-justify: distribute-all-lines; /* IE5+ */
}
.justify-all-lines:after
{
/*
* We don't need IE6 and IE7 inline-block hack support here
* since they don't support :after anyways (the text-justify
* properties for them are above)... IE8 and above have native
* inline-block support so for IE8+, both the text-justify and
* :after will take effect but it doesn't have any negative
* effects since this element is invisible
*/
display: inline-block;
width: 100%;
content: '.';
font-size: 0;
height: 0;
line-height: 0;
visibility: hidden;
}