Bootstrap 4垂直表单网格问题:嵌套行(col-lg-9)大于父列col-lg-6
Hey there! I’ve run into this exact Bootstrap grid nesting issue before—let’s get it sorted out quickly.
The Root Cause
Bootstrap 4’s grid system relies on a strict hierarchy: container → row → col. When you nest columns, you must wrap the child columns in a new row inside the parent column. Skipping this internal row causes the child column’s padding to stack with the parent’s padding, combined with the default negative margins on row elements, leading to that overflow you’re seeing.
The Correct Structure
Here’s the proper way to nest your col-lg-9 inside a col-lg-6:
<!-- 外层容器和行 --> <div class="container"> <div class="row"> <!-- 父列:col-lg-6 --> <div class="col-lg-6 bg-light p-3 border border-primary"> <!-- 关键:添加内部row来包裹子列 --> <div class="row"> <!-- 子列:col-lg-9,现在会完全适配父列宽度 --> <div class="col-lg-9 bg-white p-2 border border-danger"> Your vertical form content goes here </div> </div> </div> </div> </div>
Key Notes to Remember
- Always nest columns inside a new
row: The internalrowcancels out the parent column’s padding using negative margins, ensuring the child columns fit perfectly within the parent’s bounds. - Visualize with borders/padding: I added
borderandbg-*classes in the example to make the grid structure easy to see—you can remove those once things are working. - Keep the hierarchy intact: Never place a
coldirectly inside anothercolwithout an intermediaterow; this breaks Bootstrap’s grid spacing logic.
If you were missing that inner row before, adding it should immediately fix the overflow issue. Let me know if you need further tweaks for your specific form layout!
内容的提问来源于stack exchange,提问作者Abhilash Gudapati

