When should I use container and row in Twitter Bootstrap 3?

后端 未结 5 1132
清酒与你
清酒与你 2020-12-07 10:12

Please explain to me when to use the classes container and row. I\'m not sure because the documentation of Bootstrap is quite unclear about this pa

5条回答
  •  轮回少年
    2020-12-07 10:57

    I was wondering about the same and to understand that I went through the bootstrap.css of version 3. The answer lies in from line no. 1585 to 1605. I'll post those lines here for better understanding as below.

    .container
    {
      padding-right: 15px;
      padding-left: 15px;
      margin-right: auto;
      margin-left: auto;
    }
    @media (min-width: 768px) {
      .container {
        width: 750px;
      }
    }
    @media (min-width: 992px) {
      .container {
        width: 970px;
      }
    }
    @media (min-width: 1200px) {
      .container {
        width: 1170px;
      }
    }
    

    Whole of the code is self explanatory. However, to elaborate on this, container would take 750px if screen width is between 768px and 992px and so forth as the code shows. Now, for common screen resolution of more than 1200, container would take 1170px, but subtracting the padding of 30 px (15px+15px), the effective space left is 1140px, which is centered on the screen as the margin of left and right is set to auto.

    Now, in case of class="row", there is below code:

    .row {
      margin-right: -15px;
      margin-left: -15px;
    }
    

    So, if row is inside the container, it would effectively snatch the padding of 15px each side from the container and use the full space. But if the class row is inside the body tag, it would tend to move out of the visible area into both the left and right side of the browser due to negative margins.

    I hope it was made clear.

提交回复
热议问题