Bootstrap - Removing padding or margin when screen size is smaller

后端 未结 12 1283
深忆病人
深忆病人 2020-12-07 18:31

EDITED: Maybe I should ask which selector sets up the side padding when the screen is reduced to below 480px width? I have been browsing bootstrap-responsi

相关标签:
12条回答
  • 2020-12-07 18:41

    This thread was helpful in finding the solution in my particular case (bootstrap 3)

    @media (max-width: 767px) {
      .container-fluid, .row {
        padding:0px;
      }
      .navbar-header {
        margin:0px;
      }
    }
    
    0 讨论(0)
  • 2020-12-07 18:44

    The @media query specifically for 'phones' is..

    @media (max-width: 480px) { ... }
    

    But, you may want to remove the padding/margin for any smaller screen sizes. By default, Bootstrap adjusts margins/padding to the body, container and navbars at 978px.

    Here are some queries that have worked (in most cases) for me:

    @media (max-width: 978px) {
        .container {
          padding:0;
          margin:0;
        }
    
        body {
          padding:0;
        }
    
        .navbar-fixed-top, .navbar-fixed-bottom, .navbar-static-top {
          margin-left: 0;
          margin-right: 0;
          margin-bottom:0;
        }
    }
    

    Demo


    Update for Bootstrap 4

    Use the new responsive spacing utils which let you set padding/margins for different screen widths (breakpoints): https://stackoverflow.com/a/43208888/171456

    0 讨论(0)
  • 2020-12-07 18:46

    Heres what I do for Bootstrap 3/4

    Use container-fluid instead of container.

    Add this to my CSS

    @media (min-width: 1400px) {
        .container-fluid{
            max-width: 1400px;
        }   
    }
    

    This removes margins below 1400px width screen

    0 讨论(0)
  • 2020-12-07 18:48

    The way I get an element to go 100% width of the device is use negative left and right margins on it. The body has a padding of 24px, so that's what you can use negative margins for:

    element{
        margin-left:  -24px;
        margin-right: -24px;
        padding-left:  24px;
        padding-right:  24px;
    }
    
    0 讨论(0)
  • 2020-12-07 18:49

    The easy solution is to write something like that,

    px-lg-1

    mb-lg-5

    By adding lg, the class will be applied only on large screens

    0 讨论(0)
  • 2020-12-07 18:51

    Another css that can make the margin problem is that you have direction:someValue in your css, so just remove it by setting it to initial.

    For example:

    body {
         direction:rtl;
     }
    @media (max-width: 480px) {
        body {
         direction:initial;
        }
    }
    
    0 讨论(0)
提交回复
热议问题