Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is there a CSS pseudo sellector for sellecting the next element?

Featured Replies

Hey,

 

When hovering over a <tr> element in a table I'd like to apply styles to the next <tr> element in the table?

 


<table>
   <tr class="hoverTr">
       <td>Col1</td>
       <td>Col2</td>
       <td>Col3</td>
   </tr>
   <tr>
       <td colspan="3">change styles of this row</td>
   </tr>
   <tr class="hoverTr">
       <td>Col1</td>
       <td>Col2</td>
       <td>Col3</td>
   </tr>
   <tr>
       <td colspan="3">change styles of this row</td>
   </tr>

</table

 

so whenever a table row of class="hoverTr" is hovered over by the mouse I'd like to change the styles of the next row.

 

How do I do this? Can it be done with pure CSS? Is there a pseudo selector for this?

 

Thanks,

I believe you'd be looking for:

 

tr:hover + tr 

 

That's the correct syntax, anyway. Not sure about browser support, you'll have to bung together a test case.

Edited by Renaissance-Design

Thanks Renaissance,

 

This works perfectly! My actual CSS makes it a little more complex. Firstly I'm selecting on a class not all tr elements, 2 I didn't say before but I'm actually then applying styles to a div inside the td of the next tr. So my CSS looks like this..

 

.myClass:hover + tr td div

 

And it works. I have tested in IE FF Chrome Safari and Oprea and it is working perfectly in all five!

 

Many Thanks!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.