0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-12 00:08:59 +01:00
Bootstrap/docs/layout/flexbox-grid.md
Mark Otto 95f34be093 More grid updates
- Flexbox responsive behavior fixed with specific .col-{breakpoint} classes now added
- Dropped the make-col mixin in favor of a column-basics placeholder that we can extend across our grid infrastructure
- Updated docs to use required .col-xs-12 (as a safeguard for when folks enable flexbox mode--this isn't necessary in default grid mode)
- Update flexbox grid docs to include responsive docs, tweak some other bits too
2016-02-06 11:31:46 -08:00

6.0 KiB

layout title group
docs Flexbox grid system layout

Fancy a more modern grid system? Enable flexbox support in Bootstrap to take full advantage of CSS's Flexible Box module for even more control over your site's layout, alignment, and distribution of content.

Bootstrap's flexbox grid includes support for every feature from our default grid system, and then some. Please read the default grid system docs before proceeding through this page. Features that are covered there are only summarized here. Please note that Internet Explorer 9 does not support flexbox, so proceed with caution when enabling it.

{% callout warning %} Heads up! The flexbox grid documentation is only functional when flexbox support is explicitly enabled. {% endcallout %}

Contents

  • Will be replaced with the ToC, excluding the "Contents" header {:toc}

How it works

The flexbox grid system behaves similar to our default grid system, but with a few notable differences:

  • Grid mixins and predefined classes include support for flexbox. Just enable flexbox support to utilize them as you would otherwise.
  • Nesting, offsets, pushes, and pulls are all supported in the flexbox grid system.
  • Flexbox grid columns without a set width will automatically layout with equal widths. For example, four columns will each automatically be 25% wide.
  • Flexbox grid columns have significantly more alignment options available, including vertical alignment.
  • Unlike the default grid system where a grid column starts as full-width in the xs tier, flexbox requires a .col-{breakpoint} class for each tier.

Chill? Awesome—keep reading for more information and some code snippets.

Auto-layout columns

When flexbox support is enabled, you can utilize breakpoint-specific column classes for equal-width columns. Add any number of .col-{breakpoint}s for each breakpoint you need and you're good to go. For example, here's are two grid layouts that apply to every device and viewport possible.

{% example html %}
1 of 2
1 of 2
1 of 3
1 of 3
1 of 3
{% endexample %}

Auto-layout for flexbox grid columns also means you can set the width of one column and the others will automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths.

{% example html %}
1 of 3
2 of 3 (wider)
3 of 3
{% endexample %}

Responsive flexbox

Unlike the default grid system, the flexbox grid requires a class for full-width columns. If you have a .col-sm-6 and don't add .col-xs-12, your xs grid will not render correctly. Note that flexbox grid tiers still scale up across breakpoints, so if you want two 50% wide columns across sm, md, and lg, you only need to set .col-sm-6.

{% example html %}
1 of 2 (stacked on mobile)
1 of 2 (stacked on mobile)
{% endexample %}

Vertical alignment

Use the flexbox alignment utilities to vertically align columns.

{% example html %}
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
{% endexample %}
{% example html %}
One of three columns
One of three columns
One of three columns
{% endexample %}

Horizontal alignment

Flexbox utilities for horizontal alignment also exist for a number of layout options.

{% example html %}
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
{% endexample %}