Do you need to use Bootstrap's “container” and “row” if your content is to span the whole width?

后端 未结 4 1119
旧巷少年郎
旧巷少年郎 2020-12-09 12:11

I think the standard of Bootstrap 3 and 4 is

...
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 12:46

    Short answer: you do need to use container, but you don't need to use row.

    You can put elements directly in the container or container-fluid. You aren't required to use the grid (.row and .col-*), and the container alone can be used as a container of content. Only use the grid when you need the responsive 12-unit structure.

    For example, this is valid Bootstrap...

    Hello World

    Some other content...

    From the Bootstrap docs...

    "Bootstrap requires a containing element to wrap site contents and house our grid system."

    So, the purpose of container is two-fold: 1) to "house the grid system", and 2) to "wrap site contents". However, when you do use the grid (.row and .col-*), a container is required to wrap the .row.

    Even the basic starter template utilizes container without the grid.

    In summary...

    • You can use .container or .container-fluid alone to contain elements and page content.
    • If you use the grid (.row and .col-*), .row must be inside a .container or .container-fluid, and .col-* must be inside a .row.

提交回复
热议问题