Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="page-wrapper">
    <div class="page-layout">
        <main class="demo-section main-content">
            <h1>Main Content</h1>
            <p>On a wide screen, this card looks correct.</p>
            
            <article class="card">
                <img class="card-image" src="https://placehold.co/600x400/22c55e/ffffff?text=Looks+Good" alt="Correctly laid out card">
                <div class="card-content">
                    <h2 class="card-title">Adaptive Card</h2>
                    <p class="card-description">My layout is based on the wide viewport.</p>
                    <button class="card-button">Learn More</button>
                </div>
            </article>
        </main>
        
        <aside class="demo-section sidebar">
            <h1>Sidebar</h1>
            <p>On a wide screen, this card's layout is broken.</p>
            
            <article class="card">
                <img class="card-image" src="https://placehold.co/600x400/ef4444/ffffff?text=Broken!" alt="Broken layout card">
                <div class="card-content">
                    <h2 class="card-title">Adaptive Card</h2>
                    <p class="card-description">My container is narrow, but the media query breaks my layout!</p>
                    <button class="card-button">Learn More</button>
                </div>
            </article>
        </aside>
    </div>
</div>
              
            
!

CSS

              
                :root {
            --surface-color: #ffffff;
            --background-color: #f1f5f9;
            --primary-color: #4f46e5;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --border-color: #e2e8f0;
        }

        body {
            font-family: 'Inter', system-ui, sans-serif;
            background-color: var(--background-color);
            color: var(--text-primary);
            margin: 0;
            padding: 2rem;
        }

        .page-wrapper {
            max-width: 1200px;
            margin: 0 auto;
        }

        .page-layout {
            display: grid;
            grid-template-columns: 1fr;
            gap: 2rem;
        }

        /* On wider screens, create a main content area and a sidebar */
        @media (min-width: 960px) {
            .page-layout {
                grid-template-columns: minmax(0, 2.5fr) minmax(0, 1fr);
            }
        }

        .demo-section h1 {
            font-size: 1.5rem;
            font-weight: 700;
            margin-top: 0;
            margin-bottom: 0.25rem;
            color: var(--text-primary);
        }

        .demo-section p {
            font-size: 1rem;
            color: var(--text-secondary);
            margin-top: 0;
        }

        /* 2. Enhanced Card Component Styles */
        .card {
            display: grid;
            grid-template-columns: 1fr; /* Default is single column */
            background-color: var(--surface-color);
            border-radius: 0.75rem; /* Softer corners */
            border: 1px solid var(--border-color);
            box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.02);
            overflow: hidden;
            margin-top: 1.5rem;
        }

        .card-image {
            width: 100%;
            height: auto;
            display: block;
            aspect-ratio: 16 / 9;
            object-fit: cover;
        }

        .card-content {
            padding: 1.5rem;
        }

        .card-title {
            font-size: 1.25rem;
            font-weight: 700;
            margin: 0 0 0.5rem 0;
        }
        
        .card-description {
            color: var(--text-secondary);
            line-height: 1.6;
            margin: 0 0 1.5rem 0;
        }

        .card-button {
            display: inline-block;
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 0.5rem;
            font-weight: 500;
            text-align: center;
            cursor: pointer;
            transition: background-color 0.2s ease;
        }
        
        .card-button:hover {
            background-color: #4338ca;
        }


        /* 3. THE BRITTLE MEDIA QUERY */
        /* This rule applies to BOTH cards when the viewport is > 960px,
           even though the sidebar card doesn't have enough space. */
        @media (min-width: 960px) {
            .card {
                grid-template-columns: 140px 1fr; /* Horizontal layout */
                align-items: center;
                gap: 0; /* Gaps handled by padding now */
            }

            .card-image {
                height: 100%;
            }

            /* Adjust padding for horizontal layout */
            .card-content {
                padding: 1.5rem;
            }
        }
              
            
!

JS

              
                
              
            
!
999px

Console