2009-06-11 4 views

答えて

3

おかげで、すべて、ここで

は、私は最終的に、このソリューションのために使用されるJavaScriptのバージョンです。

<script> 

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

    }); 
    </script> 
10

セマンティッククラス名を使用すると、IE6での苦労を緩和できます。何かのように:あなたのCSSを使用している

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

そして:

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

これは間違いなく、あなたの子要素があまり変更されていない(またはまったく)解決策ではありません。 – noluckmurphy

+0

JSのない素晴らしいソリューション。かなりスマートです。 +1 –

+0

これは解決策ではありません。firts-childまたはlast-childを使用している場合は、特定のクラスを静的に追加できない場合がほとんどです –

0

IEの不整合の束を修正し、より汎用的なライブラリは、ディーン・エドワーズIE7です:http://dean.edwards.name/IE7/

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/を参照してください:ここでは例です。

関連する問題