问题描述
我是网站开发的新手。我正在尝试让我的嵌入式 twitch 播放器使用它的父级全宽。高度似乎很好用,但是在使用 bootstrap 中的 d-flex 类时,它使播放器变得非常瘦。
请在此处观看我的代码: https://jsfiddle.net/Sagan_owl/nwvt2ag8/3/
不要介意播放器错误消息,这是意料之中的
<!DOCTYPE html>
<html lang="en">
<head>
<title>Brams 225</title>
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="./main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"></script>
<script src="https://embed.twitch.tv/embed/v1.js"></script>
</head>
<body>
<main class="container-fluid">
<div class="row corps">
<div class="col-lg-2 bg-warning">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#">Bio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Donations</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Professionnel</a>
</li>
</ul>
</div>
<div class="col-lg-10 d-flex flex-column">
<div class="row d-flex align-items-stretch section2-haut bg-success">
<div class="col-lg-12 d-flex align-self-center justify-content-center">
<div id="twitch-embed"></div>
<script type="text/javascript">
new Twitch.Embed("twitch-embed",{
width: "100%",height: "100%",channel: "monstercat",// only needed if your site is also embedded on embed.example.com and othersite.example.com
parent: ["embed.example.com","othersite.example.com"]
});
</script>
</div>
</div>
<div class="row section2-bas bg-info ">
<div class="col-lg-4 mt-auto text-center">
<img src="https://panels-images.twitch.tv/panel-18340583-image-9eaaa5a0-b00a-4475-bc6a-c6b5930bae48"
class="img-fluid" alt="twitter img not found">
</div>
<div class="col-lg-4 mt-auto text-center">
<img src="https://panels-images.twitch.tv/panel-18340583-image-1deed596-2b7e-4781-9628-e3a82b4cc9c2"
class="img-fluid" alt="twitter img not found">
</div>
<div class="col-lg-4 mt-auto text-center">
<img src="https://panels-images.twitch.tv/panel-18340583-image-f0ce67ba-5a55-4aa6-8d94-b628ebac530a"
class="img-fluid" alt="twitter img not found">
</div>
</div>
</div>
</div>
</main>
</body>
</html>
----------
main{
height: 100vh;
}
.corps{
height: 100vh;
}
.section2-haut{
height: 80vh;
}
.section2-bas{
height: 20vh;
}
解决方法
您需要在父 div 上设置尺寸
https://jsfiddle.net/pu5rhtxo/
#twitch-embed {
width: 100%;
}
在这个例子中,我在父 Div 上设置了一些 CSS
还修复了 JS 脚本标签中的父级,以便播放器实际工作