Bootstrap - Removing padding or margin when screen size is smaller

后端 未结 12 1305
深忆病人
深忆病人 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: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

提交回复
热议问题