CSS: Hover effect only for filled table cells
Question by Guest | 2017-05-23 at 16:26
I have a table consisting of cells with or without content. Now, I want to implement some hover effect that should only be active when there is content within the <td> element:
CSS
td:hover { background-color: red; }
HTML
<td> <p>I am content</p> </td> <td> <input type="text" value="I am also content" name="test" /> </td> <td> // No hover effect here! </td>
In this example, the hover effect should only be applied to the first and the second td-cell. The empty third cell should not have any hover color.
Thank you for your help.
Related Topics
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
Website Performance: Deliver JavaScript and CSS files compressed to reduce loading times
Tutorial | 0 Comments
Mouseover buttons using CSS without reloading
Tutorial | 0 Comments
MySQL: Delete Data from Table - Difference between TRUNCATE, DELETE and DROP
Tutorial | 0 Comments
CSS: :hover for :before and :after
Question | 3 Answers
CSS: Colorize Table Rows Alternately only with CSS
Tutorial | 0 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can work with the CSS selector :empty. This selector selects all empty elements and when combined with :not, you get all not empty elements - that are those elements with content.
In your case it would be:
That should select all non-empty table cells.
2017-05-23 at 17:51