What is it?
Bootstrap's responsive classes react to the viewport. This library adds classes that react to the width of a parent container instead, using CSS container queries. This is the 3.x line, for Bootstrap 5.
Install
npm i bootstrap-container-queries@3
With CSS, after Bootstrap 5:
<link href="bootstrap-container-queries.min.css" rel="stylesheet" />
With Sass (@use or @import):
@use "bootstrap-container-queries/scss/bootstrap-container-queries";
Usage
Add .bcq to the parent, then use the
bcq- classes. They follow the Bootstrap names with the
bcq- prefix, and base classes exist too
(bcq-d-none).
<div class="bcq row">
<div class="bcq-sm-6 bcq-lg-3">...</div>
</div>
<div class="bcq">
<div class="bcq-d-none bcq-d-md-block">Visible from md</div>
</div>
Reference
Breakpoints: sm 30em, md 48em,
lg 62em, xl 75em, xxl 90em (em of
the container).
| Feature | Classes |
|---|---|
| Grid | bcq-{size}, bcq-{bp}-{size} |
| Display | bcq-d-{value}, bcq-d-{bp}-{value} |
| Flex direction | bcq-flex-{bp}-{value} |
| Text align | bcq-text-{bp}-{start|center|end} |
| Float | bcq-float-{bp}-{start|end|none} |
| Margin, padding |
bcq-m{sides}-{bp}-{n},
bcq-p{sides}-{bp}-{n}
|
Customize
$container-queries-breakpoints: (sm: 30em, md: 48em, lg: 62em, xl: 75em, xxl: 90em);
Frozen builds of this version are in the package:
bootstrap-container-queries/dist/v3/bootstrap-container-queries.css.
Good to know
-
.bcqcreates a stacking context, which can affectz-indexand Z-axis transforms of descendants.
Live demo
Resize the box below (drag its corner) or use the buttons.