2009-06-11 50 views

回答

3

感謝所有,

這裏是我最後用於此解決方案的JavaScript版本。

是修復了一大堆IE不一致的
<script> 

    $(document).ready(function(){ 
    $("ul li:last-child").addClass("last"); 
    $("ul li:first-child").addClass("first"); 

    }); 
    </script> 
10

您可以使用語義類名來緩解IE6中的痛苦。喜歡的東西:

<ul> 
    <li class="first">First Item</li> 
    <li>Second Item</li> 
    <li class="last">Last Item</li> 
    </ul> 

然後在你的CSS使用:

ul .first { color: #F00; } 
ul .last { color: #00F; } 
+0

這絕對是一個快速修復的解決方案,其中您的子元素變化不大(或根本不變)。 – noluckmurphy 2009-06-11 18:21:15

3

有不需要改變你的HTML一個確切的解決方案。使用Microsoft「動態樣式」。以下是一個示例:

<html> 
<head> 
<style type="text/css"> 
tr td:first-child {font-weight:bold; background-color:green;} 
tr td:last-child {background-color:orange;} 
tr td {_font-weight:expression(this.previousSibling==null?'bold':'normal'); _background-color:expression(this.previousSibling==null?'lightgreen':(this.nextSibling==null?'orange':''));} 
</style> 
</head> 
<body> 
<table> 
<tr><td>First</td><td>Second</td><td>Third</td><td>Last</td></tr> 
<tr><td>First</td><td>Second</td><td>Third</td><td>Last</td></tr> 
<tr><td>First</td><td>Second</td><td>Third</td><td>Last</td></tr> 
</body> 
</html> 

另請參閱http://mauzon.com/pseudoclasses-first-child-and-last-child-for-ie6/

相關問題