Home >Web Front-end >CSS Tutorial >How to Customize Bootstrap 4 Breakpoints Without Recompiling?

How to Customize Bootstrap 4 Breakpoints Without Recompiling?

Susan Sarandon
Susan SarandonOriginal
2024-11-03 06:36:30974browse

How to Customize Bootstrap 4 Breakpoints Without Recompiling?

How to Customize Bootstrap 4 Breakpoints

You wish to modify the xl breakpoint from 1200 to 1280 globally in Bootstrap 4. However, assigning new values to Bootstrap's $grid-breakpoints variable doesn't seem to change the xl breakpoint. Do you need to recompile Bootstrap from scratch to accomplish this?

The Solution: Override Variables Before Import

The key to customizing Bootstrap 4 breakpoints is to override the $grid-breakpoints and $container-max-widths variables before importing the Bootstrap sources. Here's how to do it in Sass:

<code class="scss">// theme.scss
// Override default Bootstrap variables:
$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1280px
);

$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1220px
);

// Import Bootstrap sources
@import "~bootstrap/scss/bootstrap";

// Custom CSS rules here...</code>

Now, the xl breakpoint will be globally set to 1280px, and any Bootstrap styles dependent on breakpoints, such as container widths, will adjust accordingly.

The above is the detailed content of How to Customize Bootstrap 4 Breakpoints Without Recompiling?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn