Using media breakpoints in Bootstrap 4-alpha

前端 未结 3 834
无人共我
无人共我 2020-11-30 19:47

In Bootstrap 3 I use this:

.something {
    padding: 5px;
    @media screen and (min-width: $screen-sm-min) { 
        padding: 20px;
    }
    @media screen         


        
3条回答
  •  北海茫月
    2020-11-30 20:22

    Use breakpoint mixins like this:

    .something {
        padding: 5px;
        @include media-breakpoint-up(sm) { 
            padding: 20px;
        }
        @include media-breakpoint-up(md) { 
            padding: 40px;
        }
    }
    

    v4 breakpoints reference

    v4 alpha6 breakpoints reference


    Below full options and values.

    Breakpoint & up (toggle on value and above):

    @include media-breakpoint-up(xs) { ... }
    @include media-breakpoint-up(sm) { ... }
    @include media-breakpoint-up(md) { ... }
    @include media-breakpoint-up(lg) { ... }
    @include media-breakpoint-up(xl) { ... }
    

    breakpoint & up values:

    // Extra small devices (portrait phones, less than 576px)
    // No media query 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) { ... }
    
    // Extra large devices (large desktops, 1200px and up)
    @media (min-width: 1200px) { ... }
    

    breakpoint & down (toggle on value and down):

    @include media-breakpoint-down(xs) { ... }
    @include media-breakpoint-down(sm) { ... }
    @include media-breakpoint-down(md) { ... }
    @include media-breakpoint-down(lg) { ... }
    

    breakpoint & down values:

    // Extra small devices (portrait phones, less than 576px)
    @media (max-width: 575px) { ... }
    
    // Small devices (landscape phones, less than 768px)
    @media (max-width: 767px) { ... }
    
    // Medium devices (tablets, less than 992px)
    @media (max-width: 991px) { ... }
    
    // Large devices (desktops, less than 1200px)
    @media (max-width: 1199px) { ... }
    
    // Extra large devices (large desktops)
    // No media query since the extra-large breakpoint has no upper bound on its width
    

    breakpoint only:

    @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) { ... }
    

    breakpoint only values (toggle in between values only):

    // Extra small devices (portrait phones, less than 576px)
    @media (max-width: 575px) { ... }
    
    // Small devices (landscape phones, 576px and up)
    @media (min-width: 576px) and (max-width: 767px) { ... }
    
    // Medium devices (tablets, 768px and up)
    @media (min-width: 768px) and (max-width: 991px) { ... }
    
    // Large devices (desktops, 992px and up)
    @media (min-width: 992px) and (max-width: 1199px) { ... }
    
    // Extra large devices (large desktops, 1200px and up)
    @media (min-width: 1200px) { ... }
    

提交回复
热议问题