After studying this problem, I think I have a good answer to this question. Based on what I found, it looks like the Bootstrap Documentation and the Bootstrap website contradict that the container classes cannot be nested. This is confirmed in the repo. It seems that the recommendation in the documentation for nesting containers and the add problem caused by nested containers is the only real problem with this problem, since I did not find any other problems with it.
In the repo, I found another potential solution that recommended changing fields on nested containers. But I think that my decision to refuse to fill the child container, as described in this initial question, is a little more practical and straightforward, since additional markup is not required to achieve the desired effect. I will include the field solution from the repo here for reference. This is mainly due to adding a fixed class to the parent container, and then applying a negative field to the left and right on each nested container in the parent. Note that this solution does not apply to instances of containers nested in a container-liquid. Only for containers nested in other containers.
CONTAINERS FORBIDDEN IN CONTAINERS
HTML
<div class="container fixed"> <div class="container"> <div class="container"> <div class="container"></div> </div> </div> </div>
CSS
.container.fixed .container { margin-left: -15px; margin-right: -15px; }
Bootply example
CONTAINERS FORBIDDEN IN THE CONTAINER-LIQUID
CSS
.container-fluid .container { padding-left:0; padding-right:0; }
HTML
<div class="container-fluid" style="background-color:aliceblue;"> <div class="row"> <div class="col-xs-12"> <div class="container"> <div class="row"> <div class="col-xs-6" style="background-color:violet">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</div> <div class="col-xs-6" style="background-color: lightblue">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</div> </div> </div> </div> </div> <div class="row"> <div class="col-xs-4" style="background-color:pink">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</div> <div class="col-xs-4" style="background-color: red">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</div> <div class="col-xs-4" style="background-color:blue">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</div> </div> </div>
Bootply example
In conclusion, although this is not recommended, it is easy to nest containers and in the right context it can be really useful, for example, in cases where the layout has different fixed and full-sized contents. But it is necessary to carefully study and make adjustments to take into account the filling problem arising from containers for nesting.
Opaw Nako Apr 17 '15 at 13:57 2015-04-17 13:57
source share