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

Bootstrap列布局异常:col-md-4无法位于col-md-6右侧却换行

问题:Bootstrap布局中col-md-4无法显示在col-md-6右侧

问题根源

  • Bootstrap栅格系统的正确层级是:container/container-fluid → row → col-*,你把列直接放在container-fluid里,而container-fluid又嵌套在row里,结构完全不符合规范,导致栅格布局失效
  • 不存在col-16这个类,Bootstrap栅格是12列体系,最大列宽类是col-12
  • justify-content-right和order类没生效,是因为列的父容器不是row(只有row是flex容器,才能让这些flex相关类起作用)

修复后的代码

<body>
    <div class="container-fluid">
        <!-- 顶部标题行 -->
        <div class="row">
            <div class="col-12 bg-dark">
                <div class="d-flex justify-content-center">
                    <h1 class="text-white">Welcome to the Website</h1>
                </div>
            </div>
        </div>
        <!-- 内容行:col-md-6和col-md-4并排 -->
        <div class="row">
            <div class="col-md-6 bg-dark">
                <div class="d-flex justify-content-center">
                    <h1 class="text-white">Rate our website</h1>
                </div>
                <div class="d-flex justify-content-between">
                    <button onclick="increasenumber()" id="coolbutton" type="button" class="btn btn-success">Upvote</button>
                    <button onclick="decreasenumber()" id="coolbutton1" type="button" class="btn btn-danger">Downvote</button>
                    <button onclick="resetcount()" id="coolbutton2" type="button" class="btn btn-info">Reset</button>
                </div>
                <div class="d-flex justify-content-center">
                    <h1 class="text-white" id="counter">0</h1>
                </div>
            </div>
            <div class="col-md-4 bg-dark">
                <!-- 这里可以添加内容 -->
            </div>
        </div>
    </div>
</body>

关键修复点

  • 调整结构:把container-fluid作为最外层容器,内部嵌套row,列直接放在row里
  • 替换col-16为col-12,符合12列栅格规则
  • 给需要使用justify-content-*的容器加上d-flex类(这些类只有在flex容器里才生效)
  • 现在row作为flex容器,col-md-6和col-md-4会自动在同一行排列(总宽度6+4=10 ≤12,满足栅格要求)

内容的提问来源于stack exchange,提问作者DM23545

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 23:30:04