search

Home  >  Q&A  >  body text

Customize Bootstrap 4’s grid system breakpoints

I have an application where the design requires 1280 breakpoints from desktop to tablet or xl to lg respectively. However, Bootstrap itself has an xl breakpoint at 1200.

I need to change xl breakpoints globally for boot. Do I have to recompile Bootstrap 4 from source?

I tried setting this in my Sass build:

$grid-breakpoints: (
  // Extra small screen / phone
  xs: 0,
  // Small screen / phone
  sm: 576px,
  // Medium screen / tablet
  md: 768px,
  // Large screen / desktop
  lg: 992px,
  // Extra large screen / wide desktop
  xl: 1280px
);

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

However, there is no change in the global xl breakpoint, it will still break at 1200px wide.

P粉696891871P粉696891871520 days ago813

reply all(2)I'll reply

  • P粉043566314

    P粉0435663142023-10-19 20:06:59

    Change the $grid-breakpoints variable and it will work fine. Remember you have to import /bootstrap or bootstrap/variables in custom.scss and then after @import bootstrap. < /em>

    For example:

    $grid-breakpoints: (
      xs: 0,
      sm: 600px,
      md: 800px,
      lg: 1000px,
      xl: 1280px
    );

    Demo:https://codeply.com/go/MlIRhbJYGj

    See also: How to extend/use SASS to modify (customize) Bootstrap 4

    reply
    0
  • P粉052686710

    P粉0526867102023-10-19 00:57:43

    Bootstrap 4.x and 5.x

    Before importing the Bootstrap source, you need to override the $grid-breakpoints and $container-max-widths variables. Here is a working example (scss):

    // File: theme.scss
    // Override default BT variables:
    $grid-breakpoints: (
            xs: 0,
            sm: 576px,
            md: 768px,
            lg: 992px,
            xl: 1200px,
            xxl: 1900px
    );
        
    $container-max-widths: (
            sm: 540px,
            md: 720px,
            lg: 960px,
            xl: 1140px,
            xxl: 1610px
    );
        
    // Import BT sources
    @import "../node_modules/bootstrap/scss/bootstrap";
    
    // Your CSS (SASS) rules here...
    

    reply
    0
  • Cancelreply