Missing visible-** and hidden-** in Bootstrap v4

后端 未结 10 2460
小蘑菇
小蘑菇 2020-11-22 06:39

In Bootstrap v3 I often use the hidden-** classes combined with clearfix to control multi column layouts at different screen widths. For example,

I could combine mu

10条回答
  •  孤城傲影
    2020-11-22 07:29

    The user Klaro suggested to restore the old visibility classes, which is a good idea. Unfortunately, their solution did not work in my project.

    I think that it is a better idea to restore the old mixin of bootstrap, because it is covering all breakpoints which can be individually defined by the user.

    Here is the code:

    // Restore Bootstrap 3 "hidden" utility classes.
    @each $bp in map-keys($grid-breakpoints) {
      .hidden-#{$bp}-up {
        @include media-breakpoint-up($bp) {
          display: none !important;
        }
      }
      .hidden-#{$bp}-down {
        @include media-breakpoint-down($bp) {
          display: none !important;
        }
      }
      .hidden-#{$bp}-only{
        @include media-breakpoint-only($bp){
          display:none !important;
        }
      }
    }
    

    In my case, I have inserted this part in a _custom.scss file which is included at this point in the bootstrap.scss:

    /*!
     * Bootstrap v4.0.0-beta (https://getbootstrap.com)
     * Copyright 2011-2017 The Bootstrap Authors
     * Copyright 2011-2017 Twitter, Inc.
     * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
     */
    
    @import "functions";
    @import "variables";
    @import "mixins";
    @import "custom"; // <-- my custom file for overwriting default vars and adding the snippet from above
    @import "print";
    @import "reboot";
    [..]
    

提交回复
热议问题