Skip to main content

Pseudo selectors

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pseudo-Selectors Example</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background-color: #f0f0f0;
            margin: 0;
            font-family: Arial, sans-serif;
        }

        .button {
            padding: 15px 30px;
            font-size: 18px;
            color: #fff;
            background-color: #007BFF;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin: 10px;
            transition: background-color 0.3s, color 0.3s;
        }

        .button:hover {
            background-color: #0056b3;
            color: #ffeb3b;
        }

        .button:focus {
            outline: 2px solid #ffeb3b;
        }

        .button:active {
            background-color: #a03d73;
            color: #fff;
        }

        .list {
            list-style-type: none;
            padding: 0;
        }

        .list li {
            padding: 10px;
            background-color: #e0e0e0;
            margin: 5px 0;
        }

        .list li:first-child {
            background-color: #ffeb3b;
        }

        .list li:last-child {
            background-color: #007BFF;
            color: #fff;
        }

        .list li:nth-child(2) {
            background-color: #ff6f61;
        }

        .list li:not(:first-child):not(:last-child) {
            background-color: #6c757d;
            color: #fff;
        }
    </style>
</head>
<body>
    <button class="button">Hover over me!</button>
    <button class="button">Focus on me!</button>
    <button class="button">Click me!</button>

    <ul class="list">
        <li>First Item</li>
        <li>Second Item</li>
        <li>Third Item</li>
        <li>Fourth Item</li>
        <li>Last Item</li>
    </ul>
</body>
</html>

You can view it live here.