jsfiddle.net/rqJAY/
HTML:
<table class="table_database_edit">
<tr><td>Magazyn wycieraczek</td><td>Edytuj</td><td>Usuń</td></tr>
<tr class="more" id=""><td colspan="3">aa</td></tr>
<tr><td>test</td><td>Edytuj</td><td>Usuń</td></tr>
<tr class="more" id=""><td colspan="3">aa</td></tr>
</table>
CSS:
tr.more{
#display: none;
}
table.table_database_edit{
width: 100%;
border-collapse:collapse;
border-spacing: 0;
}
table.table_database_edit tr:nth-child(4n+3), table.table_database_edit tr:nth-child(4n+4){
background-color: #EFF0F1;
}
table.table_database_edit tr:hover:nth-child(n) + tr:nth-child(n):after{
background-color: #FFFFCC;
}
table.table_database_edit tr:hover:nth-child(n+1) + tr:nth-child(n+1):before{
background-color: #FFFFCC;
}
I have table. Every two rows is a group. The groups alternate background color. Rows 1 and 2 are white. Rows 3 and 4 are gray. Rows 5 and 6 are white. Etc.
I want to set the background-color to yellow when you hover over a group. How I can do it?
The :hover is pseudo-class and :before & :after are pseudo-elements. In CSS, pseudo-elements are written after pseudo-class. In CSS3 double colon (::) is used to denote pseudo-element. For IE8 or older use a single colon (CSS2 syntax) is used. Example 1: This example uses :hover condition for a:before and a:after in an element.
Example 1: This example uses :hover condition for a:before and a:after in an element. Example 2: This example uses :hover condition for a:before and a:after in an element.
The :before and :after selectors in CSS is used to add content before and after an element. The :hover is pseudo-class and :before & :after are pseudo-elements. In CSS, pseudo-elements are written after pseudo-class.
The same applies to other pseudo-classes such as hover. In this tutorial, we will cover how to use before and after in Scss and how we can apply the same principle to other CSS selectors. To access the ::before pseudo class of an element in Scss we can nest &:before inside an element class selector.
What you're looking for is tbody
. The tbody
element is similar to colgroup
, but used for grouping rows. From there, the CSS is simple:
<table class="table_database_edit">
<tbody>
<tr><td>Magazyn wycieraczek</td><td>Edytuj</td><td>Usuń</td></tr>
<tr class="more" id=""><td colspan="3">aa</td></tr>
</tbody>
<tbody>
<tr><td>test</td><td>Edytuj</td><td>Usuń</td></tr>
<tr class="more" id=""><td colspan="3">aa</td></tr>
</tbody>
</table>
CSS:
tr.more{
#display: none;
}
table.table_database_edit{
width: 100%;
border-collapse:collapse;
border-spacing: 0;
}
table.table_database_edit tbody:nth-child(odd) tr {
background-color: #EFF0F1;
}
table.table_database_edit tbody:hover tr {
background-color: #FFFFCC;
}
http://jsfiddle.net/rqJAY/13/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With