gogreen
gogreen

Reputation: 75

How to override CSS style during hover in a table row?

I saw several questions on this forum related to my problem but neither of them were helpful, so am posting here.

I have a table where a style is applied at table level(.tblSignal) and td level (.tdSignalName). Here is jsfiddler link

My problem is, when I hover on the table, all the text should turn to white color. But since there is a style applied on .tdSignalName as "#0072c6", it does not override the color to white. I tried "!important" but it did not work. Please advise !

.tblSignal{
/* border-width:1px; */
border-style:solid;
}
.tblSignal:hover{
background-color:#0072c6;
color:#FFFFFF !important;
font-size:initial;
}
.tdSignalName{
font-weight:bold;
height:30px;
font-size:16px;
color:#0072c6;
}
/* .tdSignalName:hover{
color:#FFFFFF !important;
} */

.tdSignalDescription{

}
.tdSigButton{
text-align:center;
vertical-align:middle;
}
<table class="tblSignal" width="500px">
<tr >
<td class="tdSignalName" width="400px">						
	<div>Title</div>
</td>

<td rowspan="2" class="tdSigButton" width="100px">
	<div id="divButton">						 						 
	 <button id="btnReport" onclick="window.open('_#=SignalReportURL=#_')">Run Report</button>
	</div>
</td>
</tr>	
<tr>
<td class="tdSignalDescription" width="400px">
	<!-- _#=ctx.RenderBody(ctx)=#_                 -->
	<div><i>SignalDescription </i></div>
</td>					

</tr>		
					
</table>

Upvotes: 2

Views: 3362

Answers (1)

Turnip
Turnip

Reputation: 36642

You need to also override the .tdSignalName colour declaration when the parent is hovered...

.tblSignal:hover .tdSignalName {
    color:#FFFFFF;
}

Example...

.tblSignal {
    border-style: solid;
}
.tblSignal:hover {
    background-color: #0072c6;
    color: #FFFFFF !important;
    font-size: initial;
}
.tdSignalName {
    font-weight: bold;
    height: 30px;
    font-size: 16px;
    color: #0072c6;
}
.tblSignal:hover .tdSignalName {
    color: #FFFFFF;
}

.tdSigButton {
    text-align: center;
    vertical-align: middle;
}
<table class="tblSignal" width="500px">
<tr>
    <td class="tdSignalName" width="400px">
        <div>Title</div>
    </td>
    <td rowspan="2" class="tdSigButton" width="100px">
        <div id="divButton">						 						 
            <button id="btnReport" onclick="window.open('_#=SignalReportURL=#_')">Run Report</button>
        </div>
    </td>
</tr>
<tr>
    <td class="tdSignalDescription" width="400px">
        <!-- _#=ctx.RenderBody(ctx)=#_                 -->
        <div><i>SignalDescription </i></div>
    </td>
</tr>
</table>

Upvotes: 3

Related Questions