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

Bootstrap中d-flex类在极简HTML代码中无法生效的问题求助

问题原因及解决方法

你的代码中缺少Bootstrap样式文件的引入,这是d-flex、justify-content-around等工具类无法生效的关键——浏览器没有这些类对应的CSS规则,自然无法渲染出预期的Flex布局效果。

修正后的完整代码

<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Association Capucine - Gagner contre la leucémie</title>
  <!-- 引入Bootstrap CSS文件 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <div class="d-flex justify-content-around">
    <div class="p-2 bg-info">Flex item 1</div>
    <div class="p-2 bg-warning">Flex item 2</div>
    <div class="p-2 bg-primary">Flex item 3</div>
  </div>
  <main>
  </main>
  <footer>
  </footer>
</body>
</html>

关键说明

  • 必须在<head>标签内引入Bootstrap的CSS文件,所有Bootstrap工具类的样式都定义在这个文件中。
  • 如果你使用的是Bootstrap 4版本,只需替换对应的CDN链接即可,核心逻辑一致。
  • 若选择本地引入Bootstrap文件,需确保文件路径正确,避免因路径错误导致样式加载失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 14:52:00