Commentary

CSS flex box was designed for one-dimensional layout and manages content flow. This primarily allows control over spacing between elements. On the other hand, CSS grid provides two dimensional layout as well as primarily being concerned with content placement!

Goldilocks-CSS uses grid to replace flexbox for one dimensional layout which gives much greater control. With grid, you can define the minimum content width and the grid will deal with adjusting widths to meet the placement requirements. This results in eliminating the need for using @media breakpoints to ensure proper content viewing.

Rather than trying to map your layout into a fixed grid (typically 12 columns and consequently spans thereof) think of your desired minimum content width first and let grid figure how to best display it for a given viewport. This then means that you only need to think about how many columns of content you require what minimum width is needed for each column.

Bootstrap Style Breakpoint Impact on Column Width

Consider that for Bootstrap, a common example sets a div with classes col-sm-8 col-md-6 col-lg-4 col-xl-3 based on a 12 grid strip layout. For this layout, the columns of content would typically provide the following sizes:

Bootstrap Breakpoints
Breakpoint Breakpoint
Pixels
Class Grid Strips /
BP
Min-width
Pixels
Max-width
Pixels
Cols /
BP
Total grid strips12
X-Small575xs125755751
Small576sm83845121
Medium768md63844962
Large992lg43314003
Extra Large1200xl33003504
Extra Extra Large1400xxl33504804
Max Full HD1920

At mobile device widths, the layout defaults to a single column of content. At larger screen sizes, the content columns are fairly constant but allow more content columns to be displayed. This method requires that the designer must compute the content column width ahead of time. Ironic considering that this type of work is what computers excel at!

Furthermore, the choice of breakpoints is subjective since the browser viewpoints are very varied and will change over time as new devices get introduced into the market.

Impact of Using Content Widths Instead of Breakpoints

Now, what if the designer only needed to think about the content column width that is needed for a particular design. If we fix the width at, let's say 300px, then for the various viewports, we will get a fixed number of columns.

Here we do not need to have any knowledge of the type of device the user may have. Gridbox will automatically adjust column widths and will fill the available space. Wrapping will also occur naturally with column width adjusted and filled as needed.

The table below shows how a classic Bootstrap grid / columns breakpoints map into the newer CSS grid capability.

Using Content Width Instead of Breakpoints
BS
Breakpoint
BS
Breakpoint
Pixels
BS
Class
Grid
Min
Cols
Grid
Max
Cols
Grid
Min-width
Pixels
Grid
Max-width
Pixels
Column Width (px)300
X-Small575xs11300575
Small576sm12300384
Medium768md23300331
Large992lg33300400
Extra Large1200xl44300350
Extra Extra Large1400xxl46300320
Max Full HD1920

Using the content column width allows for tracking more closely to the available browser viewport and ensures that the content layout remains consistent for all users. The developer / designer is also freed from the width calculation and the limitations of fixed breakpoints.

Usage

Classes:
.row Top level class defines the grid container.
.abs-width Row modifier sets minimum width to 100px width. Note: default minimum width is 5rem.
.has-Nx-minwidth N = [1 - 10]; Row modifier sets children content width in increments of minimum width (default 5rem or, if set, 100px).
.is-centered-vert Row modifier vertically centres column content in a row.
.column Child of .row that will be spaced horizontally by the grid with gridbox column gutter as spacer.
.is-span-N N = [1 - 8]; Column modifier allows a content column to span N grid columns.
.is-fullwidth Optional column modifier that allows a column to grab all of the horizontal grid space.
.has-background Optional column modifier that adds a background plus small padding. Usually not required for most content.
Dependencies:
File: grid.css
Variables: --bg-grid, --grid-background, --grid-min-px-width, --grid-min-width, --gutter

Examples

Basic Layout with Even columns

Component
Component
Component

HTML Code Example


                <div class="row">
                    <div class="column has-background">
                        <div>Component</div>
                    </div>

                    <div class="column has-background">
                        <div>Component</div>
                    </div>

                    <div class="column has-background">
                        <div>Component</div>
                    </div>
                </div>
            

Even columns with Vertical Alignment

Item 1
Item 1
Item 2
Item 1
Item 2
Item 3

                <div class="row is-centered-vert">
                    <div class="column has-background">
                        <div>Item 1</div>
                    </div>

                    <div class="column has-background">
                        <div>Item 1</div>
                        <div>Item 2</div>
                    </div>

                    <div class="column has-background">
                        <div>Item 1</div>
                        <div>Item 2</div>
                        <div>Item 3</div>
                    </div>
                </div>
            

Columns with Minimum Fixed Width

Container CSS = class="row abs-width has-3x-minwidth".
Sets minimum column width to 300px and maximum width is handled by browser rendering.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9

        <div class="row abs-width has-3x-minwidth">
            <div class="column has-background">Item 1</div>
            <div class="column has-background">Item 2</div>
            <div class="column has-background">Item 3</div>
            <div class="column has-background">Item 4</div>
            <div class="column has-background">Item 5</div>
            <div class="column has-background">Item 6</div>
            <div class="column has-background">Item 7</div>
            <div class="column has-background">Item 8</div>
            <div class="column has-background">Item 9</div>
        </div>
    

Columns with Variable Widths

Container CSS = class="row abs-width".
Column widths set to span various grid columns.
Browser rendering will ensure minimum column width and calculate maximum widths.
Columns will wrap automatically and maintain minimum column widths.

.column.is-span-1

.abs-width = 100px min width

.column.is-span-2

.abs-width = 100px x 2 cols = 200px min width

.column.is-span-3

.abs-width = 100px x 3 cols = 300px min width


        <div class="row abs-width">
            <div class="column is-span-1 has-background">
                <p>.column.is-span-1</p>
                <p>.abs-width = 100px min width</p>
            </div>

            <div class="column is-span-2 has-background">
                <p>.column.is-span-2</p>
                <p>.abs-width = 100px x 2 cols = 200px min width</p>
            </div>

            <div class="column is-span-3 has-background">
                <p>.column.is-span-3</p>
                <p>.abs-width = 100px x 3 cols = 300px min width</p>
            </div>
        </div>
    

Columns with Wider Variable Widths

Container CSS = class="row has-3x-minwidth".
Column widths set to span various grid columns.
Browser rendering will ensure minimum column width and calculate maximum widths.
Columns will wrap automatically and maintain minimum column width of 3 * 5rem.

Item 1

Item 2 + .is-span-2

rel-width = 5rem x3-min-width x 2 cols = 30rem min-width

Item 3

Rel-width = 5rem x3-min-width = 15rem min-width

Item 4

Column with a lot of text to create a wide item to show how the column gets filled out.

Item 5

Item 6

Item 7

Item 8 + .is-span-2

Rel-width = 5rem x3-min-width x 2 cols = 30rem min-width

Item 9


        <div class="row has-3x-minwidth">
            <div class="column has-background">
                <p class="is-title-5">Item 1</p>
            </div>

            <div class="column is-span-2 has-background">
                <p class="is-title-5">Item 2 + .is-span-2</p>
                <p>rel-width = 5rem x3-min-width x 2 cols = 30rem min-width</p>
            </div>

            <div class="column has-background">
                <p class="is-title-5">Item 3</p>
                <p>Rel-width = 5rem x3-min-width = 15rem min-width</p>
            </div>
            <div class="column has-background">
                <h5>Item 4</h5>
                <p>Column with a lot of text to create a wide item to show how the column gets filled out.</p>
            </div>
            <div class="column has-background"><p class="is-title-5">Item 5</p></div>
            <div class="column has-background"><p class="is-title-5">Item 6</p></div>
            <div class="column has-background"><p class="is-title-5">Item 7</p></div>
            <div class="column is-span-2 has-background">
                <p class="is-title-5">Item 8 + .is-span-2</p>
                <p>Rel-width = 5rem x3-min-width x 2 cols = 30rem min-width</p>
            </div>
            <div class="column has-background"><p class="is-title-5">Item 9</p></div>
        </div>