2016-09-18 39 views
0

This is an image of description.(css):我可以通過觸發一個事件或兩個事件包含的類名同時觸發兩個css事件嗎?

我想兩個區域背景獲得黃色背景。但它僅適用在鼠標上的「這是實際區域」,並

什麼是問題,它不會對「section_tr_inbody區」

在section_tr_inbody區,黃色的背景上只有部分工作......我的工作碼?

(CSS)

#Actual { 
      padding: 20px; 
      font-weight: bold; 

     } 


.together:hover { 
    background-color: yellow; 
    } 

(HTML)

(...) 
    <tr id="section_tr_intbody" class="together"> 
    (...) 




(...) 
<div class="Slider slideup"> 
     <div id="Actual" class="together"> 
(...) 

每兩個元件具有相同的類名 '合' 我認爲要細,這些的1)的CSS捕捉一個元素然後,2)它同時對它們應用效果

在實際的一面,css catch <div id="Actual" class="together">然後應用效果。

在另一方面

<tr id="section_tr_intbody" class="together">側,CSS抓<tr id="section_tr_intbody" class="together">但其應用效果不包括實際的一面。

謝謝

+0

嘗試應用類的TDS,而不是TR。 – SchattenJager

+0

嗨,我想通過觸發它們中的一個,使它們中的兩個一起工作(同時),並且它在實際方面工作良好,但它不能在另一方工作(tr id =「section_tr_int body」class =「together」 )。他們有相同的班名,應該是同等的 –

回答

0

我不認爲這可以用CSS來完成,因爲你不能用CSS遍歷DOM。

可以做到這一點很容易與jQuery,但:

$('.together').hover(function() { 
 
     $('.together').addClass('yellow'); 
 
    }, 
 
    function(){ 
 
     $('.together').removeClass('yellow'); 
 
    });
#Actual, #fake, #random { 
 
      padding: 10px; 
 
      font-weight: bold; 
 
     } 
 
td { padding: 10px; } 
 
.yellow { 
 
    background-color: yellow; 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr id="section_tr_intbody" class="together"> 
 
     <td>Table cell stuff</td> 
 
     </tr> 
 
    <tr id="section_tr_intbodyagain" class="nottogether"> 
 
     <td>More table cell stuff</td> 
 
     </tr> 
 
    <tr id="section_tr_intbodystill" class="together"> 
 
     <td>Even more table cell stuff</td> 
 
     </tr> 
 
    </table> 
 

 

 
<div class="Slider slideup"> 
 
     <div id="Actual" class="together"> 
 
     Div stuff 
 
     </div> 
 
     <div id="fake" class="nottogether"> 
 
     more Div Stuff 
 
     </div> 
 
     <div id="random" class="together"> 
 
     Even more Div Stuff 
 
     </div> 
 
</div>

+0

嗯。謝謝。你的回覆對我很有幫助。 –