Commit 33a4e8ff authored by Mark Otto's avatar Mark Otto
Browse files

Rewrite grid docs to account for new grid tier

- Breaks grid content across multiple pages
- Updates mentions of grid tiers from five to six
- Rewrites how it works sections to reference new options and tiers
parent bb3e5f71
Showing with 961 additions and 490 deletions
+961 -490
...@@ -55,7 +55,7 @@ Bootstrap includes several components that function as an overlay of some kind. ...@@ -55,7 +55,7 @@ Bootstrap includes several components that function as an overlay of some kind.
Each overlay component increases its `z-index` value slightly in such a way that common UI principles allow user focused or hovered elements to remain in view at all times. For example, a modal is document blocking (e.g., you cannot take any other action save for the modal's action), so we put that above our navbars. Each overlay component increases its `z-index` value slightly in such a way that common UI principles allow user focused or hovered elements to remain in view at all times. For example, a modal is document blocking (e.g., you cannot take any other action save for the modal's action), so we put that above our navbars.
Learn more about this in our [`z-index` layout page]({{< docsref "/layout/overview#z-index" >}}). Learn more about this in our [`z-index` layout page]({{< docsref "/layout/z-index" >}}).
## HTML and CSS over JS ## HTML and CSS over JS
......
...@@ -67,7 +67,7 @@ Be sure to have your pages set up with the latest design and development standar ...@@ -67,7 +67,7 @@ Be sure to have your pages set up with the latest design and development standar
</html> </html>
{{< /highlight >}} {{< /highlight >}}
That's all you need for overall page requirements. Visit the [Layout docs]({{< docsref "/layout/overview" >}}) or [our official examples]({{< docsref "/examples" >}}) to start laying out your site's content and components. That's all you need for overall page requirements. Visit the [Layout docs]({{< docsref "/layout/grid" >}}) or [our official examples]({{< docsref "/examples" >}}) to start laying out your site's content and components.
## Important globals ## Important globals
......
...@@ -61,7 +61,7 @@ When you don't want to use the includes, there are also two functions: ...@@ -61,7 +61,7 @@ When you don't want to use the includes, there are also two functions:
- `rfs-value()` converts a value into a `rem` value if a `px` value is passed, in other cases it returns the same result. - `rfs-value()` converts a value into a `rem` value if a `px` value is passed, in other cases it returns the same result.
- `rfs-fluid-value()` returns the fluid version of a value if the property needs rescaling. - `rfs-fluid-value()` returns the fluid version of a value if the property needs rescaling.
In this example, we use one of Bootstrap's built-in [responsive breakpoint mixins]({{< docsref "/layout/overview#responsive-breakpoints" >}}) to only apply styling below the `lg` breakpoint. In this example, we use one of Bootstrap's built-in [responsive breakpoint mixins]({{< docsref "/layout/breakpoints" >}}) to only apply styling below the `lg` breakpoint.
```scss ```scss
.selector { .selector {
......
---
layout: docs
title: Breakpoints
description: Breakpoints are the triggers in Bootstrap for how your layout responsive changes across device or viewport sizes.
group: layout
aliases: "/docs/4.3/layout/"
toc: true
---
## Core concepts
- **Breakpoints are the building blocks of responsive design.** Use them to control when your layout can be adapted at a particular viewport or device size.
- **Use media queries to architect your CSS by breakpoint.** Media queries are a feature of CSS that allow you to conditionally apply styles based on a set of browser and operating system parameters. We most commonly use `min-width` in our media queries.
- **Mobile first, responsive design is the goal.** Bootstrap's CSS aims to apply the bare minimum of styles to make a layout work at the smallest breakpoint, and then layers on styles to adjust that design for larger devices. This optimizes your CSS, improves rendering time, and provides a great experience for your visitors.
## Available breakpoints
Bootstrap includes six default breakpoints, sometimes referred to as _grid tiers_, for building responsively. These breakpoints can be customized if you're using our source Sass files.
<table class="table">
<thead>
<tr>
<th>Breakpoint</th>
<th>Class infix</th>
<th>Dimensions</th>
</tr>
</thead>
<tbody>
<tr>
<td>X-Small</td>
<td><em>None</em></td>
<td>0–576px</td>
</tr>
<tr>
<td>Small</td>
<td><code>sm</code></td>
<td>&ge;576px</td>
</tr>
<tr>
<td>Medium</td>
<td><code>md</code></td>
<td>&ge;768px</td>
</tr>
<tr>
<td>Large</td>
<td><code>lg</code></td>
<td>&ge;992px</td>
</tr>
<tr>
<td>Extra large</td>
<td><code>xl</code></td>
<td>&ge;1200px</td>
</tr>
<tr>
<td>Extra extra large</td>
<td><code>xxl</code></td>
<td>&ge;1400px</td>
</tr>
</tbody>
</table>
Each breakpoint size was chosen to be a multiple of 12 and to be representative of a subset of common device sizes and viewport dimensions. They don't specifically target every use case or device, but the provide ranges provide a strong and consistent foundation to build on for any nearly device.
These breakpoints are customizable via Sass—you'll find them in a Sass map in our `_variables.scss` stylesheet.
{{< highlight scss >}}
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px
) !default;
{{< /highlight >}}
For more information and examples on how to modify our Sass maps and variables, please refer to [the Sass section of the Grid documentation]({{< docsref "/layout/grid#sass" >}}).
## Media queries
Since Bootstrap is developed to be mobile first, we use a handful of [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.
### Min-width
Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components.
{{< highlight scss >}}
// Source mixins
// No media query necessary for xs breakpoint as it's effectively `@media (min-width: 0) { ... }`
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }
@include media-breakpoint-up(xxl) { ... }
// Usage
// Example: Hide starting at `min-width: 0`, and then show at the `sm` breakpoint
.custom-class {
display: none;
}
@include media-breakpoint-up(sm) {
.custom-class {
display: block;
}
}
{{< /highlight >}}
These Sass mixins translate in our compiled CSS using the values declared in our Sass variables. For example:
{{< highlight scss >}}
// X-Small devices (portrait phones, less than 576px)
// No media query for `xs` since this is the default in Bootstrap
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// X-Large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
// XX-Large devices (larger desktops, 1400px and up)
@media (min-width: 1400px) { ... }
{{< /highlight >}}
### Max-width
We occasionally use media queries that go in the other direction (the given screen size *or smaller*):
{{< highlight scss >}}
@include media-breakpoint-down(xs) { ... }
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }
@include media-breakpoint-down(xl) { ... }
// No media query necessary for xxl breakpoint as it has no upper bound on its width
// Example: Style from medium breakpoint and down
@include media-breakpoint-down(md) {
.custom-class {
display: block;
}
}
{{< /highlight >}}
These mixins take those declared breakpoints, subtract `.02px` from them, and use them as our `max-width` values. For example:
{{< highlight scss >}}
// X-Small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }
// Small devices (landscape phones, less than 768px)
@media (max-width: 767.98px) { ... }
// Medium devices (tablets, less than 992px)
@media (max-width: 991.98px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }
// X-Large devices (large desktops, less than 1400px)
@media (max-width: 1399.98px) { ... }
// XX-Large devices (larger desktops)
// No media query since the xxl breakpoint has no upper bound on its width
{{< /highlight >}}
{{< callout info >}}
{{< partial "callout-info-mediaqueries-breakpoints.md" >}}
{{< /callout >}}
### Single breakpoint
There are also media queries and mixins for targeting a single segment of screen sizes using the minimum and maximum breakpoint widths.
{{< highlight scss >}}
@include media-breakpoint-only(xs) { ... }
@include media-breakpoint-only(sm) { ... }
@include media-breakpoint-only(md) { ... }
@include media-breakpoint-only(lg) { ... }
@include media-breakpoint-only(xl) { ... }
@include media-breakpoint-only(xxl) { ... }
{{< /highlight >}}
Similarly, media queries may span multiple breakpoint widths:
{{< highlight scss >}}
// Example
// Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199.98px) { ... }
{{< /highlight >}}
### Between breakpoints
The Sass mixin for targeting the same screen size range would be:
{{< highlight scss >}}
@include media-breakpoint-between(md, xl) { ... }
{{< /highlight >}}
---
layout: docs
title: Columns
description: Learn how to modify columns with a handful of options for alignment, ordering, and offsetting thanks to our flexbox grid system. Plus, see how to use column classes to manage widths of non-grid elements.
group: layout
toc: true
---
{{< callout info >}}
**Heads up!** Be sure to [read the Grid page]({{< docsref "/layout/grid" >}}) first before diving into how to modify and customize your grid columns.
{{< /callout >}}
## How they work
- **Columns build on the grid's flexbox architecture.** Flexbox means we have options for changing individual columns and [modifying groups of columns at the row level]({{< docsref "/layout/grid#row-columns" >}}). You choose how columns grow, shrink, or otherwise change.
- **When building grid layouts, all content goes in columns.** The hierarchy of Bootstrap's grid goes from [container]({{< docsref "/layout/containers" >}}) to row to column to your content. On rare ocassions, you may combine content and column, but be aware there can be unintended consequences.
- **Bootstrap includes predefined classes for creating fast, responsive layouts.** With [six breakpoints]({{< docsref "/layout/breakpoints" >}}) and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts. This can be disabled via Sass if you wish.
## Alignment
Use flexbox alignment utilities to vertically and horizontally align columns.
### Vertical alignment
{{< example class="bd-example-row bd-example-row-flex-cols" >}}
<div class="container">
<div class="row align-items-start">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-center">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-end">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div>
{{< /example >}}
{{< example class="bd-example-row bd-example-row-flex-cols" >}}
<div class="container">
<div class="row">
<div class="col align-self-start">
One of three columns
</div>
<div class="col align-self-center">
One of three columns
</div>
<div class="col align-self-end">
One of three columns
</div>
</div>
</div>
{{< /example >}}
### Horizontal alignment
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row justify-content-start">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-center">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-end">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-around">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-between">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
</div>
{{< /example >}}
### Column wrapping
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-9">.col-9</div>
<div class="col-4">.col-4<br>Since 9 + 4 = 13 &gt; 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
<div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
</div>
</div>
{{< /example >}}
### Column breaks
Breaking columns to a new line in flexbox requires a small hack: add an element with `width: 100%` wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple `.row`s, but not every implementation method can account for this.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<!-- Force next columns to break to new line -->
<div class="w-100"></div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
</div>
</div>
{{< /example >}}
You may also apply this break at specific breakpoints with our [responsive display utilities]({{< docsref "/utilities/display" >}}).
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<!-- Force next columns to break to new line at md breakpoint and up -->
<div class="w-100 d-none d-md-block"></div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
</div>
</div>
{{< /example >}}
## Reordering
### Order classes
Use `.order-` classes for controlling the **visual order** of your content. These classes are responsive, so you can set the `order` by breakpoint (e.g., `.order-1.order-md-2`). Includes support for `1` through `5` across all six grid tiers.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col">
First in DOM, no order applied
</div>
<div class="col order-5">
Second in DOM, with a larger order
</div>
<div class="col order-1">
Third in DOM, with an order of 1
</div>
</div>
</div>
{{< /example >}}
There are also responsive `.order-first` and `.order-last` classes that change the `order` of an element by applying `order: -1` and `order: 6`, respectively. These classes can also be intermixed with the numbered `.order-*` classes as needed.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col order-last">
First in DOM, ordered last
</div>
<div class="col">
Second in DOM, unordered
</div>
<div class="col order-first">
Third in DOM, ordered first
</div>
</div>
</div>
{{< /example >}}
### Offsetting columns
You can offset grid columns in two ways: our responsive `.offset-` grid classes and our [margin utilities]({{< docsref "/utilities/spacing" >}}). Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.
#### Offset classes
Move columns to the right using `.offset-md-*` classes. These classes increase the left margin of a column by `*` columns. For example, `.offset-md-4` moves `.col-md-4` over four columns.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>
</div>
</div>
{{< /example >}}
In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in [the grid example]({{< docsref "/examples/grid" >}}).
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
<div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
<div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div>
</div>
</div>
{{< /example >}}
#### Margin utilities
With the move to flexbox in v4, you can use margin utilities like `.mr-auto` to force sibling columns away from one another.
{{< example class="bd-example-row" >}}
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
</div>
<div class="row">
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
</div>
<div class="row">
<div class="col-auto mr-auto">.col-auto .mr-auto</div>
<div class="col-auto">.col-auto</div>
</div>
</div>
{{< /example >}}
## Standalone column classes
The `.col-*` classes can also be used outside a `.row` to give an element a specific width. Whenever column classes are used as non direct children of a row, the paddings are omitted.
{{< example >}}
<div class="col-3 bg-light p-3 border">
.col-3: width of 25%
</div>
<div class="col-sm-9 bg-light p-3 border">
.col-sm-9: width of 75% above sm breakpoint
</div>
{{< /example >}}
The classes can be used together with utilities to create responsive floated images. Make sure to wrap the content in a [`.clearfix`]({{< docsref "/helpers/clearfix" >}}) wrapper to clear the float if the text is shorter.
{{< example >}}
<div class="clearfix">
{{< placeholder width="100%" height="210" class="col-md-6 float-md-right mb-3 ml-md-3" text="Responsive floated image" >}}
<p>
Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris paddenstoel nibh, ut fermentum massa justo sit amet risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p>
Sed posuere consectetur est at lobortis. Etiam porta sem malesuada magna mollis euismod. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Id nullam tellus relem amet commodo telemque olemit. Sed posuere consectetur est at lobortis. Maecenas sed diam eget risus varius blandit sit amet non magna. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
</p>
<p>
Donec id elit non mi porta gravida at eget metus. Aenean eu leo quam. Pellentesque ornare sem lantaarnpaal quam venenatis vestibulum. Donec sed odio dui. Maecenas faucibus mollis interdum. Nullam quis risus eget urna salsa tequila vel eu leo. Donec id elit non mi porta gravida at eget metus.
</p>
</div>
{{< /example >}}
--- ---
layout: docs layout: docs
title: Overview title: Containers
description: Components and options for laying out your Bootstrap project, including wrapping containers, a powerful grid system, and responsive utility classes. description: Containers are a fundamental building block of Bootstrap that contain, pad, and align your content withing a given device or viewport.
group: layout group: layout
aliases: "/docs/4.3/layout/"
toc: true toc: true
--- ---
## Containers ## How they work
Containers are the most basic layout element in Bootstrap and are **required when using our default grid system**. Containers are used to contain, pad, and (sometimes) center the content within them. While containers *can* be nested, most layouts do not require a nested container. Containers are the most basic layout element in Bootstrap and are **required when using our default grid system**. Containers are used to contain, pad, and (sometimes) center the content within them. While containers *can* be nested, most layouts do not require a nested container.
...@@ -42,9 +41,13 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -42,9 +41,13 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<span class="font-weight-normal">&ge;992px</span> <span class="font-weight-normal">&ge;992px</span>
</th> </th>
<th> <th>
Extra large<br> X-Large<br>
<span class="font-weight-normal">&ge;1200px</span> <span class="font-weight-normal">&ge;1200px</span>
</th> </th>
<th>
XX-Large<br>
<span class="font-weight-normal">&ge;1400px</span>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -55,6 +58,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -55,6 +58,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td>720px</td> <td>720px</td>
<td>960px</td> <td>960px</td>
<td>1140px</td> <td>1140px</td>
<td>1320px</td>
</tr> </tr>
<tr> <tr>
<td><code>.container-sm</code></td> <td><code>.container-sm</code></td>
...@@ -63,6 +67,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -63,6 +67,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td>720px</td> <td>720px</td>
<td>960px</td> <td>960px</td>
<td>1140px</td> <td>1140px</td>
<td>1320px</td>
</tr> </tr>
<tr> <tr>
<td><code>.container-md</code></td> <td><code>.container-md</code></td>
...@@ -71,6 +76,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -71,6 +76,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td>720px</td> <td>720px</td>
<td>960px</td> <td>960px</td>
<td>1140px</td> <td>1140px</td>
<td>1320px</td>
</tr> </tr>
<tr> <tr>
<td><code>.container-lg</code></td> <td><code>.container-lg</code></td>
...@@ -79,6 +85,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -79,6 +85,7 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td>960px</td> <td>960px</td>
<td>1140px</td> <td>1140px</td>
<td>1320px</td>
</tr> </tr>
<tr> <tr>
<td><code>.container-xl</code></td> <td><code>.container-xl</code></td>
...@@ -87,6 +94,16 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -87,6 +94,16 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td>1140px</td> <td>1140px</td>
<td>1320px</td>
</tr>
<tr>
<td><code>.container-xxl</code></td>
<td class="text-muted">100%</td>
<td class="text-muted">100%</td>
<td class="text-muted">100%</td>
<td class="text-muted">100%</td>
<td class="text-muted">100%</td>
<td>1320px</td>
</tr> </tr>
<tr> <tr>
<td><code>.container-fluid</code></td> <td><code>.container-fluid</code></td>
...@@ -95,11 +112,12 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples ...@@ -95,11 +112,12 @@ See them in action and compare them in our [Grid example]({{< docsref "/examples
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td class="text-muted">100%</td> <td class="text-muted">100%</td>
<td class="text-muted">100%</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
### All-in-one ## Default container
Our default `.container` class is a responsive, fixed-width container, meaning its `max-width` changes at each breakpoint. Our default `.container` class is a responsive, fixed-width container, meaning its `max-width` changes at each breakpoint.
...@@ -109,169 +127,58 @@ Our default `.container` class is a responsive, fixed-width container, meaning i ...@@ -109,169 +127,58 @@ Our default `.container` class is a responsive, fixed-width container, meaning i
</div> </div>
{{< /highlight >}} {{< /highlight >}}
### Fluid ## Responsive containers
Use `.container-fluid` for a full width container, spanning the entire width of the viewport. Responsive containers allow you to specify a class that is 100% wide until the specified breakpoint is reached, after which we apply `max-width`s for each of the higher breakpoints. For example, `.container-sm` is 100% wide to start until the `sm` breakpoint is reached, where it will scale up with `md`, `lg`, `xl`, and `xxl`.
{{< highlight html >}}
<div class="container-fluid">
...
</div>
{{< /highlight >}}
### Responsive
Responsive containers are new in Bootstrap v4.4. They allow you to specify a class that is 100% wide until the specified breakpoint is reached, after which we apply `max-width`s for each of the higher breakpoints. For example, `.container-sm` is 100% wide to start until the `sm` breakpoint is reached, where it will scale up with `md`, `lg`, and `xl`.
{{< highlight html >}} {{< highlight html >}}
<div class="container-sm">100% wide until small breakpoint</div> <div class="container-sm">100% wide until small breakpoint</div>
<div class="container-md">100% wide until medium breakpoint</div> <div class="container-md">100% wide until medium breakpoint</div>
<div class="container-lg">100% wide until large breakpoint</div> <div class="container-lg">100% wide until large breakpoint</div>
<div class="container-xl">100% wide until extra large breakpoint</div> <div class="container-xl">100% wide until extra large breakpoint</div>
<div class="container-xxl">100% wide until extra extra large breakpoint</div>
{{< /highlight >}} {{< /highlight >}}
## Responsive breakpoints ## Fluid containers
Since Bootstrap is developed to be mobile first, we use a handful of [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.
Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components.
{{< highlight scss >}}
// Extra small devices (portrait phones, less than 576px)
// No media query for `xs` since this is the default in Bootstrap
// Small devices (landscape phones, 576px and up) Use `.container-fluid` for a full width container, spanning the entire width of the viewport.
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1200px and up) {{< highlight html >}}
@media (min-width: 1200px) { ... } <div class="container-fluid">
...
</div>
{{< /highlight >}} {{< /highlight >}}
Since we write our source CSS in Sass, all our media queries are available via Sass mixins: ## Sass
{{< highlight scss >}}
// No media query necessary for xs breakpoint as it's effectively `@media (min-width: 0) { ... }`
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }
// Example: Hide starting at `min-width: 0`, and then show at the `sm` breakpoint As shown above, Bootstrap generates a series of predefined container classes to help you build the layouts you desire. You may customize these predefined container classes by modifying the Sass map (found in `_variables.scss`) that powers them:
.custom-class {
display: none;
}
@include media-breakpoint-up(sm) {
.custom-class {
display: block;
}
}
{{< /highlight >}}
We occasionally use media queries that go in the other direction (the given screen size *or smaller*):
{{< highlight scss >}} {{< highlight scss >}}
// Extra small devices (portrait phones, less than 576px) $container-max-widths: (
@media (max-width: 575.98px) { ... } sm: 540px,
md: 720px,
// Small devices (landscape phones, less than 768px) lg: 960px,
@media (max-width: 767.98px) { ... } xl: 1140px,
xxl: 1320px
// Medium devices (tablets, less than 992px) ) !default;
@media (max-width: 991.98px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }
// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width
{{< /highlight >}} {{< /highlight >}}
{{< callout info >}} In addition to customizing the Sass, you can also create your own containers with our Sass mixin.
{{< partial "callout-info-mediaqueries-breakpoints.md" >}}
{{< /callout >}}
Once again, these media queries are also available via Sass mixins:
{{< highlight scss >}} {{< highlight scss >}}
@include media-breakpoint-down(xs) { ... } // Source mixin
@include media-breakpoint-down(sm) { ... } @mixin make-container($padding-x: $container-padding-x) {
@include media-breakpoint-down(md) { ... } width: 100%;
@include media-breakpoint-down(lg) { ... } padding-right: $padding-x;
// No media query necessary for xl breakpoint as it has no upper bound on its width padding-left: $padding-x;
margin-right: auto;
// Example: Style from medium breakpoint and down margin-left: auto;
@include media-breakpoint-down(md) {
.custom-class {
display: block;
}
} }
{{< /highlight >}}
There are also media queries and mixins for targeting a single segment of screen sizes using the minimum and maximum breakpoint widths.
{{< highlight scss >}}
// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767.98px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991.98px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199.98px) { ... }
// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
{{< /highlight >}}
These media queries are also available via Sass mixins:
{{< highlight scss >}} // Usage
@include media-breakpoint-only(xs) { ... } .custom-container {
@include media-breakpoint-only(sm) { ... } @include make-container();
@include media-breakpoint-only(md) { ... } }
@include media-breakpoint-only(lg) { ... }
@include media-breakpoint-only(xl) { ... }
{{< /highlight >}}
Similarly, media queries may span multiple breakpoint widths:
{{< highlight scss >}}
// Example
// Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199.98px) { ... }
{{< /highlight >}}
The Sass mixin for targeting the same screen size range would be:
{{< highlight scss >}}
@include media-breakpoint-between(md, xl) { ... }
{{< /highlight >}}
## Z-index
Several Bootstrap components utilize `z-index`, the CSS property that helps control layout by providing a third axis to arrange content. We utilize a default z-index scale in Bootstrap that's been designed to properly layer navigation, tooltips and popovers, modals, and more.
These higher values start at an arbitrary number, high and specific enough to ideally avoid conflicts. We need a standard set of these across our layered components—tooltips, popovers, navbars, dropdowns, modals—so we can be reasonably consistent in the behaviors. There's no reason we couldn't have used `100`+ or `500`+.
We don't encourage customization of these individual values; should you change one, you likely need to change them all.
{{< highlight scss >}}
$zindex-dropdown: 1000 !default;
$zindex-sticky: 1020 !default;
$zindex-fixed: 1030 !default;
$zindex-modal-backdrop: 1040 !default;
$zindex-modal: 1050 !default;
$zindex-popover: 1060 !default;
$zindex-tooltip: 1070 !default;
{{< /highlight >}} {{< /highlight >}}
To handle overlapping borders within components (e.g., buttons and inputs in input groups), we use low single digit `z-index` values of `1`, `2`, and `3` for default, hover, and active states. On hover/focus/active, we bring a particular element to the forefront with a higher `z-index` value to show their border over the sibling elements. For more information and examples on how to modify our Sass maps and variables, please refer to [the Sass section of the Grid documentation]({{< docsref "/layout/grid#sass" >}}).
This diff is collapsed.
---
layout: docs
title: Gutters
description: Gutters are the padding between your columns, used to responsively space and align content in the Bootstrap grid system.
group: layout
toc: true
---
## How they work
- **Gutters are the gaps between column content, created by horizontal `padding`.** We set `padding-right` and `padding-left` on each column, and use negative `margin` to offset that at the start and end of each row to align content.
- **Gutters start are `1.5rem` (`20px`) wide.** This allows us to match our grid to the [padding and margin spacers]() scale.
- **Gutters can be responsively adjusted.** Use breakpoint-specific gutter classes to modify horizontal gutters, vertical gutters, and all gutters.
## Horizontal gutters
`.gx-*` classes can be used to control the horizontal gutter widths. The `.container` or `.container-fluid` parent may need to be adjusted if larger gutters are used too to avoid unwanted overflow, using a matching padding utility. For example, in the following example we've increased the padding with `.px-4`:
{{< example >}}
<div class="container px-4">
<div class="row gx-5">
<div class="col">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
</div>
</div>
{{< /example >}}
An alternative solution is to add a wrapper around the `.row` with the `.overflow-hidden` class:
{{< example >}}
<div class="container overflow-hidden">
<div class="row gx-5">
<div class="col">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
</div>
</div>
{{< /example >}}
## Vertical gutters
`.gy-*` classes can be used to control the vertical gutter widths. Like the horizontal gutters, the vertical gutters can cause some overflow below the `.row` at the end of a page. If this occurs, you add a wrapper around `.row` with the `.overflow-hidden` class:
{{< example >}}
<div class="container overflow-hidden">
<div class="row gy-5">
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
</div>
</div>
{{< /example >}}
## Horizontal & vertical gutters
`.g-*` classes can be used to control the horizontal gutter widths, for the following example we use a smaller gutter width, so there won't be a need to add the `.overflow-hidden` wrapper class.
{{< example >}}
<div class="container">
<div class="row g-2">
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">Custom column padding</div>
</div>
</div>
</div>
{{< /example >}}
## Row columns gutters
Gutter classes can also be added to [row columns](#row-columns). In the following example, we use responsive row columns and responsive gutter classes.
{{< example >}}
<div class="container">
<div class="row row-cols-2 row-cols-lg-5 g-2 g-lg-3">
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
<div class="col">
<div class="p-3 border bg-light">Row column</div>
</div>
</div>
</div>
{{< /example >}}
## No gutters
The gutters between columns in our predefined grid classes can be removed with `.g-0`. This removes the negative `margin`s from `.row` and the horizontal `padding` from all immediate children columns.
**Need an edge-to-edge design?** Drop the parent `.container` or `.container-fluid`.
In practice, here's how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).
{{< example class="bd-example-row" >}}
<div class="row g-0">
<div class="col-sm-6 col-md-8">.col-sm-6 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
{{< /example >}}
## Change the gutters
Classes are built from the `$gutters` Sass map which is inherited from the `$spacers` Sass map.
```sass
$grid-gutter-width: 1.5rem;
$gutters: (
0: 0,
1: $spacer * .25,
2: $spacer * .5,
3: $spacer,
4: $spacer * 1.5,
5: $spacer * 3,
);
```
...@@ -12,13 +12,13 @@ Use our [display utilities]({{< docsref "/utilities/display" >}}) for responsive ...@@ -12,13 +12,13 @@ Use our [display utilities]({{< docsref "/utilities/display" >}}) for responsive
## Flexbox options ## Flexbox options
Bootstrap 4 is built with flexbox, but not every element's `display` has been changed to `display: flex` as this would add many unnecessary overrides and unexpectedly change key browser behaviors. Most of [our components]({{< docsref "/components/alerts" >}}) are built with flexbox enabled. Bootstrap is built with flexbox, but not every element's `display` has been changed to `display: flex` as this would add many unnecessary overrides and unexpectedly change key browser behaviors. Most of [our components]({{< docsref "/components/alerts" >}}) are built with flexbox enabled.
Should you need to add `display: flex` to an element, do so with `.d-flex` or one of the responsive variants (e.g., `.d-sm-flex`). You'll need this class or `display` value to allow the use of our extra [flexbox utilities]({{< docsref "/utilities/flex" >}}) for sizing, alignment, spacing, and more. Should you need to add `display: flex` to an element, do so with `.d-flex` or one of the responsive variants (e.g., `.d-sm-flex`). You'll need this class or `display` value to allow the use of our extra [flexbox utilities]({{< docsref "/utilities/flex" >}}) for sizing, alignment, spacing, and more.
## Margin and padding ## Margin and padding
Use the `margin` and `padding` [spacing utilities]({{< docsref "/utilities/spacing" >}}) to control how elements and components are spaced and sized. Bootstrap 4 includes a five-level scale for spacing utilities, based on a `1rem` value default `$spacer` variable. Choose values for all viewports (e.g., `.mr-3` for `margin-right: 1rem`), or pick responsive variants to target specific viewports (e.g., `.mr-md-3` for `margin-right: 1rem` starting at the `md` breakpoint). Use the `margin` and `padding` [spacing utilities]({{< docsref "/utilities/spacing" >}}) to control how elements and components are spaced and sized. Bootstrap includes a six-level scale for spacing utilities, based on a `1rem` value default `$spacer` variable. Choose values for all viewports (e.g., `.mr-3` for `margin-right: 1rem`), or pick responsive variants to target specific viewports (e.g., `.mr-md-3` for `margin-right: 1rem` starting at the `md` breakpoint).
## Toggle `visibility` ## Toggle `visibility`
......
---
layout: docs
title: Z-index
description: While not a part of Bootstrap's grid system, z-indexes play an important part in how our components overlay and interact with one another.
group: layout
---
Several Bootstrap components utilize `z-index`, the CSS property that helps control layout by providing a third axis to arrange content. We utilize a default z-index scale in Bootstrap that's been designed to properly layer navigation, tooltips and popovers, modals, and more.
These higher values start at an arbitrary number, high and specific enough to ideally avoid conflicts. We need a standard set of these across our layered components—tooltips, popovers, navbars, dropdowns, modals—so we can be reasonably consistent in the behaviors. There's no reason we couldn't have used `100`+ or `500`+.
We don't encourage customization of these individual values; should you change one, you likely need to change them all.
{{< highlight scss >}}
$zindex-dropdown: 1000 !default;
$zindex-sticky: 1020 !default;
$zindex-fixed: 1030 !default;
$zindex-modal-backdrop: 1040 !default;
$zindex-modal: 1050 !default;
$zindex-popover: 1060 !default;
$zindex-tooltip: 1070 !default;
{{< /highlight >}}
To handle overlapping borders within components (e.g., buttons and inputs in input groups), we use low single digit `z-index` values of `1`, `2`, and `3` for default, hover, and active states. On hover/focus/active, we bring a particular element to the forefront with a higher `z-index` value to show their border over the sibling elements.
...@@ -12,7 +12,7 @@ Change the value of the [`display` property](https://developer.mozilla.org/en-US ...@@ -12,7 +12,7 @@ Change the value of the [`display` property](https://developer.mozilla.org/en-US
## Notation ## Notation
Display utility classes that apply to all [breakpoints]({{< docsref "/layout/overview#responsive-breakpoints" >}}), from `xs` to `xl`, have no breakpoint abbreviation in them. This is because those classes are applied from `min-width: 0;` and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation. Display utility classes that apply to all [breakpoints]({{< docsref "/layout/breakpoints" >}}), from `xs` to `xl`, have no breakpoint abbreviation in them. This is because those classes are applied from `min-width: 0;` and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
As such, the classes are named using the format: As such, the classes are named using the format:
......
...@@ -14,9 +14,14 @@ ...@@ -14,9 +14,14 @@
- title: Layout - title: Layout
pages: pages:
- title: Overview - title: Breakpoints
- title: Containers
- title: Grid - title: Grid
- title: Utilities for layout # - title: Rows
- title: Columns
- title: Gutters
- title: Utilities
- title: Z-index
- title: Content - title: Content
pages: pages:
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<p class="lead lead-lg mw-md-75 mx-auto"> <p class="lead lead-lg mw-md-75 mx-auto">
Use the <a href="https://www.bootstrapcdn.com/">BootstrapCDN</a> to deliver fast, cached, and compiled versions of Bootstrap’s CSS and JavaScript. No jQuery is required, but don't forget to include Popper.js for some components. Use the <a href="https://www.bootstrapcdn.com/">BootstrapCDN</a> to deliver fast, cached, and compiled versions of Bootstrap’s CSS and JavaScript. No jQuery is required, but don't forget to include Popper.js for some components.
</p> </p>
<a class="btn btn-lg btn-outline-primary mb-4" href="/docs/{{ .Site.Params.docs_version }}/layout/overview/">Explore the docs</a> <a class="btn btn-lg btn-outline-primary mb-4" href="/docs/{{ .Site.Params.docs_version }}/getting-started/introduction">Explore the docs</a>
<div class="text-left mx-md-5 px-md-5"> <div class="text-left mx-md-5 px-md-5">
<h5>CSS only</h5> <h5>CSS only</h5>
{{ highlight (printf (`<link rel="stylesheet" href="%s" integrity="%s" crossorigin="anonymous">`) .Site.Params.cdn.css .Site.Params.cdn.css_hash) "html" "" }} {{ highlight (printf (`<link rel="stylesheet" href="%s" integrity="%s" crossorigin="anonymous">`) .Site.Params.cdn.css .Site.Params.cdn.css_hash) "html" "" }}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment