[X(E)] HOVER

What is :hover?

In CSS, :hover is a pseudo-class used to select and style an element when the user designates it with a pointing device—most commonly by placing the mouse cursor over it, without necessarily clicking it.

It is widely used to create interactive feedback (such as changing button colors, underlining links, or highlighting table rows) to let the user know an element is clickable or interactive.


Complete Example

Below is a fully functional, modern HTML and CSS example that expands significantly on your sample. It demonstrates how to style a table row on hover, while also improving overall table aesthetics (such as alternating row colors, smooth transitions, and distinct header styles).

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hover Effect Example</title>
    <style>
        /* General table styling for readability */
        table {
            width: 100%;
            border-collapse: collapse;
            font-family: Arial, sans-serif;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        th,
        td {
            padding: 12px 16px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        th {
            background-color: #4a4ae2;
            color: white;
        }

        /* Default background for standard rows */
        tr {
            background-color: #ffffff;
            /* Adds a smooth transition effect when the hover state triggers */
            transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
        }

        /* Enhanced hover effect based on your sample */
        tr:hover {
            background-color: #e0e0ff;
            /* Optional extra polish: changes cursor to pointer */
            cursor: pointer;
        }
    </style>
</head>

<body>

    <h2>Interactive Table Example</h2>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Role</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>001</td>
                <td>Jane Doe</td>
                <td>Developer</td>
                <td>Active</td>
            </tr>
            <tr>
                <td>002</td>
                <td>John Smith</td>
                <td>Designer</td>
                <td>Away</td>
            </tr>
            <tr>
                <td>003</td>
                <td>Alice Johnson</td>
                <td>Manager</td>
                <td>Active</td>
            </tr>
        </tbody>
    </table>

</body>

</html>

Key Enhancements Made:

  • transition Property: Added a smooth fade-in effect (0.2s ease-in-out) so the color change isn't abrupt.
  • cursor: pointer: Changes the cursor to a pointing hand when hovering over the row, signaling to the user that the row is interactive.
  • Complete Structure: Wrapped your snippet inside a working HTML template with CSS reset styling, clear typography, and a structured table layout.

Hover Effect Example

Interactive Table Example

ID Name Role Status
001 Jane Doe Developer Active
002 John Smith Designer Away
003 Alice Johnson Manager Active

Comments

Popular posts from this blog

[MAIN PROGRAM] UNDONE HOUSEHOLD WORKs WEB-PROGRAM v2/MAIN

PENDING ITEMs [REVISION] v0