2011-08-05 15 views
2

我有一個CSS幫助程序類,用於強制最後一行「文本」(或用於預期用法,內聯塊div)成爲對齊對齊以及其餘的人。使用CSS調整文本的最後一行

下面是我得到了代碼:

.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> 

但是,我看到了「你好」顯示裏面的最後一個「塊狀」而不是在最後的「塊狀」div之後。我究竟做錯了什麼?

+0

'.justify,全行> *:最後的孩子:後{/ *的東西對IE6/7 * /}'是奇數。 IE6不支持'>',IE6/7都不支持':last-child'或':after'。 – thirtydot

+0

您目前正在測試哪些瀏覽器?你可以做一個[jsFiddle](http://jsfiddle.net/)演示顯示問題? – thirtydot

+0

@thirtydot我使用無點(http://www.dotlesscss.org/),這只是一個複製和粘貼異常,因爲我爲了這篇文章的目的將一個mixin轉換爲內聯CSS。想象更多的人會比LESS更熟悉純CSS。我會解決它。 ;) –

回答

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; 
} 
+0

http://jsfiddle.net/Rk79Y/6/。似乎在IE7中無法正常工作,但是我的解決方案也一樣(除非我在鏈接到的答案中調整它)。否則就很好。 – thirtydot

+0

嗯,相同的代碼適用於我的網站,但不是在jsFiddle。我不知道它是否正在做一些CSS ... –

+0

在IE5中添加了text-justify,並且在IE8中添加了-ms-text-justify,所以它絕對可以正常工作... –

相關問題