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

Bootstrap 4列内带min-width元素实现横向滚动且不溢出问题咨询

修复方案

问题根源

overflow-x属性仅能控制当前容器内部内容的溢出展示规则,你将该属性加在了设置了min-width:1000px的内容容器上,内容容器本身宽度会被min-width撑到1000px,直接顶开外层col-4列容器,最终导致布局重叠、内容溢出到列外。

调整方法

调整属性配置的层级即可:

  • 给外层带黑色边框的col-4列容器添加overflow-x: auto属性,限制列容器内内容超出列宽时滚动展示
  • 移除橙色内容容器上的overflow-x: scroll属性,仅保留min-width配置

修正后核心代码

<!-- 仅修改第一列的配置即可 -->
<div style="border: solid 1px black;overflow-x: auto" class="col-4">
  Col container 1
  <div style="min-width: 1000px;border: solid 1px orange">Col content 1</div>
</div>

完整可运行代码

<!doctype html>
<html lang="en">
<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <title>Hello, world!</title>
</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div style="border: solid 1px black;overflow-x: auto" class="col-4">
        Col container 1
        <div style="min-width: 1000px;border: solid 1px orange">Col content 1</div>
      </div>
      <div style="border: solid 1px blue" class="col-4">
        Col container 2
      </div>
      <div style="border: solid 1px yellow" class="col-4">
        Col container 3
      </div>
    </div>
  </div>
  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

修改后列容器宽度会严格遵循Bootstrap网格规则占屏幕宽度的1/3,内部内容超出列宽时会自动在列容器内部展示横向滚动条,不会溢出到列外,也不会和其余两列发生布局重叠。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 10:27:01