You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap 4垂直表单网格问题:嵌套行(col-lg-9)大于父列col-lg-6

Fixing Bootstrap 4 Grid Nesting: Nested col-lg-9 Overflowing Parent 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 internal row cancels 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 border and bg-* 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 col directly inside another col without an intermediate row; 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:16:27