2012-03-16 76 views
1

我犯了一些錯誤,並需要知道是否能解決這個問題:(選擇元素類依賴於它的其他類

看看這個網站

<style> 
    .error { width:32px; height:32px; display:inline-block; } 
    /* This is icon class */ 
    </style> 

    <div class="error"> this Is error icon 32px * 32px </div> 

    <div class="error"> this Is error notice 500px * 35px </div> 

我怎樣才能使它實現了第一個錯誤上課不影響第二

我這樣做

<style> 
    .error[class*='icon'] { width:32px; height:32px; display:inline-block; } 
     /* i was think it should effect the first class only but not ??? */ 
    </style> 

    <div class="icon error"> this Is error icon 32px * 32px </div> 

    <div class="notice error"> this Is error notice 500px * 35px </div> 

是有我用.error[class*='icon']

回答

4

可以使用.error.icon,而不是.error[class*='icon'],雖然我不知道你的屬性選擇可能會影響你的第二個.error元素等方式 。

或者如果您不想添加額外的類,則可以使用.error:first-child來代替,假設在同一個容器元素中沒有任何其他同級元素。

+0

謝謝@BoltClock它的工作,可能是我困了,其簡單的答案:) – 2012-03-16 19:57:52

1

div.icon.error是做

+0

太感謝您@ user1200072 :)最精確的方法 – 2012-03-16 19:58:21