Pen Settings

HTML

CSS

CSS Base

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

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.

Vue

              
                <template>
    <div id="app">
        <div class="controls">
            <label class="columns">
                Columns:
                <input
                    v-model.number="columns"
                    type="number"
                >
            </label>
            <div class="breakpoints">
                <div
                    v-for="bp in breakpoints"
                    :key="bp.label"
                    class="breakpoint"
                >
                    <label>
                        Label:
                        <input
                            v-model="bp.label"
                            type="text"
                        >
                    </label>
                    <label>
                        Gap:
                        <input
                            v-model.number="bp.gap"
                            type="number"
                        >
                    </label>
                    <label>
                        Max Content Width:
                        <input
                            v-model.number="bp.contentWidth"
                            type="number"
                        >
                    </label>
                </div>
            </div>
            <button @click="addBreakpoint">
                add breakpoint
            </button>
            <button @click="removeBreakpoint">
                remove breakpoint
            </button>
        </div>

        <div class="grids">
            <div
                v-for="grid in grids"
                :key="grid.label"
                class="grid"
                :class="{'-active': grid.maxAt ? clientWidth < grid.maxAt : true}"
            >
                <div
                    class="example"
                    :style="`--columns: ${columns};
                     --max: ${grid.maxColumnWidth}px;
                     --gap: ${grid.gap}px;
                     --maxAt: ${grid.maxAt}px;
                     `"
                >
                    <div class="gutter" />
                    <div class="main">
                        <h2>
                            {{ grid.label }}
                            ({{ r(grid.minWidth) }} - {{ r(grid.maxAt) }}px)
                        </h2>
                        Columns widths from
                        {{ r(grid.minColumnWidth) }} - {{ r(grid.maxColumnWidth) }}px
                    </div>
                    <div class="gutter" />
                </div>
                <div
                    class="example"
                    :style="`--columns: ${columns};
                     --max: ${grid.maxColumnWidth}px;
                     --gap: ${grid.gap}px;
                     --maxAt: ${grid.maxAt}px;
                     `"
                >
                    <div class="gutter" />
                    <div
                        v-for="i in columns"
                        :key="i"
                        class="cell"
                    >
                        {{ i }}
                    </div>
                    <div class="gutter" />
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data: () => ({
        clientWidth: 0,
        columns: 12,
        breakpoints: [
            { label: 'sm', gap: 16, contentWidth: 560 },
            { label: 'md', gap: 32, contentWidth: 1024 },
            { label: 'lg', gap: 48, contentWidth: 1296 },
        ],
    }),
    computed: {
        grids () {
            const grids = []
            for (let i = 0; i < this.breakpoints.length; i++) {
                const bp = this.breakpoints[i]
                const nextBp = i < this.breakpoints.length - 1 ? this.breakpoints[i + 1] : null
                const prevBp = i ? this.breakpoints[i - 1] : null
                const grid = { ...bp }

                grid.maxColumnWidth = (grid.contentWidth - (this.columns - 1) * grid.gap) / this.columns
                grid.maxAt = (nextBp ? nextBp.gap : grid.gap) * 2 + grid.contentWidth
                bp.maxAt = grid.maxAt

                grid.minWidth = prevBp ? prevBp.maxAt + 1 : 11 * grid.gap
                grid.minColumnWidth = (grid.minWidth - (this.columns - 1) * grid.gap) / this.columns

                grids.push(grid)
            }

            return grids
        },
    },
    mounted () {
        addEventListener('resize', () => {
            if (document.documentElement.clientWidth != this.clientWidth) {
              this.clientWidth = document.documentElement.clientWidth
            }
        })
    },
    methods: {
        r(n) {
          return Math.round(n * 100) / 100
        },
        addBreakpoint () {
            this.breakpoints.push({ ...this.breakpoints[this.breakpoints.length - 1] })
        },
        removeBreakpoint () {
            this.breakpoints.pop()
        },
    },
}
</script>
<style lang="scss">
h2 {
    font-size: 1.25rem;
    margin: 0;
}
input[type=number] {
    width: 4rem;
    text-align: right;
}
.controls {
    margin: 1.5rem 3rem 3rem;
}
.columns {
    margin-bottom: 1rem;
}
.breakpoints {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
}
.breakpoint {
    display: contents;
}

.grid {
    opacity: .5;
  
    &.-active {
        opacity: 1;

        & + & {
            opacity: .5;
        }
    }
}

.example {
    display: grid;
    background: #0f02;
    column-gap: var(--gap);
    grid-template-columns: minmax(0, 1fr) repeat(var(--columns), minmax(0, var(--max))) minmax(0, 1fr);
    max-width: var(--maxAt);

    .main {
        grid-column: 2 / calc(var(--columns) + 2);
        background: #f002;
        text-align: center;
        line-height: 2;
        padding: 1rem 0;
    }

    .cell {
        background: #00f2;
        text-align: center;
        font-size: .875rem;
        line-height: 2;
    }
}
</style>

              
            
!
999px

Console