Table of Contents

Grid Layout: Responsive distribution of the horizontal space

About

grid is a component that permits to distribute the horizontal space in a responsive fashion (ie suitable for mobile screen).

The children:

Grid does not mean table. The children are not laid out at the intersection of rows and columns but in a linear fashion from left to right.

Example

How to split the space non-evenly with percentage ?

You can distribute the available space by giving a width percentage on the children.

This example splits the space in 3 children with:

<grid>
    <box width="50%">
        <box width="250" align="center">
            <icon name="bs:inboxes-fill" width="3rem"/>
            == A 250 width box in 50% of the available line space ==
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud. 
         </box>
    </box>
    <box width="25%">
        <icon name="bs:inboxes-fill" width="3rem"/>
        == 25% box ==
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
    </box>
    <box width="25%">
        <icon name="bs:inboxes-fill" width="3rem"/>
        == 25% box ==
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
    </box>
</grid>
A 250 width box in 50% of the available line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.

25% box

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

25% box

Lorem ipsum dolor sit amet, consectetur adipiscing elit,



The default breakpoint is the small breakpoint

A width value of 25% is then equivalent to 100%-xs 25%-sm. It means than on mobile screen (xs breakpoint) each box takes the whole available line space and are therefore stacked.

How to split the available space with a ratio?

You can even define the space distribution by giving a ratio on the width

This example splits the space into 3 via 3 children that have respectively the following space available:

<grid>
    <box width="1:4">
            <icon name="bs:inboxes-fill" width="3rem"/>
            == 1/4 line space ==
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
    </box>
    <box width="1:2" align="center-children">
        <box width="300px">
            <icon name="bs:inboxes-fill" width="3rem"/>
            == A 300px box in a half line space ==
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
         </box>
    </box>
    <box width="1:4">
            <icon name="bs:inboxes-fill" width="3rem"/>
            == 1/4 line space ==
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
    </box>
</grid>
1/4 line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor

A 300px box in a half line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

1/4 line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit,



The default breakpoint is the small breakpoint

A width value of 1:3 is then equivalent to 1-xs 1:3-sm. It means that on mobile screen (xs breakpoint) each cell takes the whole available line space and is therefore stacked.

How to center the content vertically?

The grid component is well-suited for vertical and horizontal alignment.

By default, the content is stacked to the top but if you want it to be vertically centered, you can use the children values of the align attribute.

Example:

<grid align="y-center-children">
  <box align="text-end">
     <heading d3>Headline</heading>
     <text lead>Lead</text>
  </box>
  <box>{{:docs:block:stock_image_surfer_in_the_see.png?400|}}</box>
</grid>
Headline

Lead

Stock Image Surfer In The See

Syntax

<grid max-line="numberValue" align="x-center-children" gutter="y-5">
   <component width="ratioValue" ></component>
   <component width="ratioValue" ></component>
   ....
</grid>

where:

The default values are:

You can use all styling attributes.

Support

Why a grid background is not centered ?

The gutter feature uses the padding and not margin.

Because the padding is painted by the background while the margin is not, the dimension of the background are not uniform in a grid.

If you want a background with you content grid centered, you should:

<box spacing="p-5">
  <background opacity="0.3">{{:docs:block:stock_image_surfer_in_the_see.png|}}</background>
  <grid spacing="mt-0 mb-0">
     <box spacing="mt-0">
         <icon name="bs:inboxes-fill" width="3rem"/>
         == 1/2 line space ==
         Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
     </box>
     <box spacing="mt-0">
         <icon name="bs:inboxes-fill" width="3rem"/>
         == 1/2 line space ==
         Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
     </box>
  </grid>
</box>
1/2 line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor

1/2 line space

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor