Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .gap utilities #32074

Merged
merged 5 commits into from Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bundlewatch.config.json
Expand Up @@ -22,15 +22,15 @@
},
{
"path": "./dist/css/bootstrap-utilities.min.css",
"maxSize": "6 kB"
"maxSize": "6.25 kB"
},
{
"path": "./dist/css/bootstrap.css",
"maxSize": "24 kB"
},
{
"path": "./dist/css/bootstrap.min.css",
"maxSize": "21.75 kB"
"maxSize": "22 kB"
},
{
"path": "./dist/js/bootstrap.bundle.js",
Expand Down
6 changes: 6 additions & 0 deletions scss/_utilities.scss
Expand Up @@ -196,6 +196,12 @@ $utilities: map-merge(
class: flex,
values: wrap nowrap wrap-reverse
),
"gap": (
responsive: true,
property: gap,
class: gap,
values: $spacers
),
"justify-content": (
responsive: true,
property: justify-content,
Expand Down
26 changes: 21 additions & 5 deletions site/content/docs/5.0/utilities/spacing.md
@@ -1,16 +1,18 @@
---
layout: docs
title: Spacing
description: Bootstrap includes a wide range of shorthand responsive margin and padding utility classes to modify an element's appearance.
description: Bootstrap includes a wide range of shorthand responsive margin, padding, and gap utility classes to modify an element's appearance.
group: utilities
toc: true
---

## How it works
## Margin and padding

Assign responsive-friendly `margin` or `padding` values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. Classes are built from a default Sass map ranging from `.25rem` to `3rem`.

## Notation
Using the CSS Grid layout module? Consider using [the gap utility](#gap).

### Notation

Spacing utilities that apply to all breakpoints, from `xs` to `xxl`, 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.

Expand Down Expand Up @@ -43,7 +45,7 @@ Where *size* is one of:

(You can add more sizes by adding entries to the `$spacers` Sass map variable.)

## Examples
### Examples

Here are some representative examples of these classes:

Expand Down Expand Up @@ -82,7 +84,7 @@ Additionally, Bootstrap also includes an `.mx-auto` class for horizontally cente
</div>
```

### Negative margin
## Negative margin

In CSS, `margin` properties can utilize negative values (`padding` cannot). These negative margins are **disabled by default**, but can be enabled in Sass by setting `$enable-negative-margins: true`.

Expand All @@ -93,3 +95,17 @@ The syntax is nearly the same as the default, positive margin utilities, but wit
margin-top: -0.25rem !important;
}
```

## Gap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move Negative margin and Horizontal centering to an h2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted for another organization to separate margin and padding from gap, since the two behave differently.


When using `display: grid`, you can make use of `gap` utilities on the parent grid container. This can save on having to add margin utilities to individual grid items (children of a `display: grid` container). Gap utilities are responsive by default, and are generated via our utilities API, based on the `$spacers` Sass map.

{{< example html >}}
<div class="d-grid gap-3">
<div class="p-2 bg-light border">Grid item 1</div>
<div class="p-2 bg-light border">Grid item 2</div>
<div class="p-2 bg-light border">Grid item 3</div>
</div>
{{< /example >}}

Support includes responsive options for all of Bootstrap's grid breakpoints, as well as six sizes from the `$spacers` map (`0`–`5`). There is no `.gap-auto` utility class as it's effectively the same as `.gap-0`.