Skip to main content

Nested style rules

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

        .card {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            transition: transform 0.3s ease-in-out;
            width: 300px;

            &:hover {
                transform: translateY(-5px);

                .card-image {
                    filter: brightness(1.1);
                }

                .card-content {
                    background-color: #f8f8f8;

                    h2 {
                        color: #2c3e50;
                    }

                    p {
                        color: #34495e;
                    }

                    .btn {
                        background-color: #3498db;
                    }
                }
            }
        }

        .card-image {
            width: 100%;
            height: 200px;
            object-fit: cover;
            transition: filter 0.3s ease-in-out;
        }

        .card-content {
            padding: 20px;
            transition: background-color 0.3s ease-in-out;

            h2 {
                margin: 0 0 10px;
                color: #333;
                transition: color 0.3s ease-in-out;
            }

            p {
                color: #666;
                margin-bottom: 20px;
                transition: color 0.3s ease-in-out;
            }

            .btn {
                display: inline-block;
                padding: 10px 20px;
                background-color: #2ecc71;
                color: white;
                text-decoration: none;
                border-radius: 4px;
                transition: background-color 0.3s ease-in-out;

                &:hover {
                    background-color: #27ae60;
                }
            }
        }
    </style>
</head>
<body>
    <div class="card">
        <img src="https://placehold.co/600x400" alt="Card image" class="card-image">
        <div class="card-content">
            <h2>Interactive Card</h2>
            <p>This card demonstrates nested CSS rules and hover effects using CSS3 features.</p>
            <a href="#" class="btn">Learn More</a>
        </div>
    </div>
</body>
</html>

Live view