如何用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
相关产品推荐
相关产品推荐

