Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select not first tr and not last td

#MyTable tr+tr:hover {    background: #dfdfdf;  }
<table id="myTable">    <tr>      <td>A</td>      <td>B</td>      <td>C</td>    </tr>    <tr>      <td>1</td>      <td>2</td>      <td>X</td>    </tr>    <tr>      <td>3</td>      <td>4</td>      <td>X</td>    </tr>  </table>

I managed to hover row 2 and 3 but while hover on 2 and 3, how can I skip the td (X). Preferable not using jQuery selector.

like image 939
Gian Avatar asked Feb 20 '12 14:02

Gian


People also ask

How do you select every element except first?

How to Select all Elements Except the First With the CSS :not(:first-child) Selector. Learn how to select all HTML elements except the first with the CSS `:not(:first-child) selector. If you add the following rule-set to your CSS stylesheet, every h2 element on your entire website will get a 64px top margin.

How do you choose your first and last child?

Using the following pseudo classes: :first-child means "select this element if it is the first child of its parent". :last-child means "select this element if it is the last child of its parent". Only element nodes (HTML tags) are affected, these pseudo-classes ignore text nodes.

How do I select the first TR in CSS?

With <tr> tag In this CSS :first-child example, the first row (ie: the first <tr> tag) will have a yellow background color. All other rows in the table will not be styled by the :first-child selector.

How do I select all except first in CSS?

The trick is very easy, in CSS we have the sibling selector ("+"), if i will make selector that choose "li + li" it will select all list-items except the first . That's all!


1 Answers

Use the :not(), :first-child and :last-child.

#myTable tr:not(:first-child):hover td:not(:last-child) {       background: #dfdfdf; } 

Also see this example.

like image 163
scessor Avatar answered Sep 26 '22 13:09

scessor