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

如何用Bootstrap 5类实现卡片内audio标签100%宽度?

解决Bootstrap 5中Audio标签占满父元素宽度的问题

你可以直接给<audio>标签添加Bootstrap 5内置的宽度实用类 w-100,就能实现让它占满父元素100%宽度,不需要自定义style="width:100%"。

w-100是Bootstrap专门用来设置元素宽度为100%的内置类,完全匹配你的需求。

修改后的完整代码如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/js/bootstrap.bundle.min.js"></script>
  </head>
  <body>
    <div class="container">
      <div class="card mt-4">
        <div class="card-header">HTML5 Audio Player Example</div>
        <div class="card-body">
          <audio controls class="w-100">
            <source
              src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
              type="audio/mpeg"
            />
            <source
              src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.ogg"
              type="audio/ogg"
            />
            <source
              src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.wav"
              type="audio/wav"
            />
            Audio not supported
          </audio>
        </div>
      </div>
    </div>
  </body>
</html>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 17:00:23