Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hover this + after and this (n+1) and before

Tags:

css

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?

like image 284
Peter Avatar asked Jan 27 '13 22:01

Peter


People also ask

What is the difference between before and after and hover in CSS?

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.

Which condition is used for a before and a after?

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.

What is the use of before and after selectors in CSS?

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.

How to use before and after in SCSS?

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.


1 Answers

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/

like image 74
cimmanon Avatar answered Oct 05 '22 04:10

cimmanon