[英]How to make full-width divs in bootstrap
我在我的一个项目中使用 Bootstrap。 我在列内制作 div,但它们没有跨越列的全宽。
这是一个示例代码。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<style type="text/css">
.col{
border: 1px solid black;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row justify-content-md-center">
<div class="col col-lg-2">
<div class="blue" style="background-color: blue;">
1 of 3
</div>
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
</div>
</body>
</html>
我的问题很简单:“如何使我的<div class="blue">
跨越原始列的 100% 宽度?”
我还尝试将宽度设置为 100%。
更新
我使用<div class="row no-gutters">
而不是<div class="row">
并删除了container-fluid
。 像魅力一样工作
you have to use this class in row
"row no-gutters justify-content-md-center"
您希望每个 div 占用 100% 的列吗? 如果是这样,您的 div 当前设置为col-2
,也许您应该将它们设置为col-12
(使用所需的视口前缀、lg、md 等...)
这听起来像是 CSS 问题。 默认情况下,Bootstrap 网格系统中的列具有 100% 的宽度。
我唯一的建议是检查您的 CSS 是否有“蓝色”class。 它需要是:
.blue{
margin: 0px;
...
}
我也会尝试在您的 HTML 中更改以下内容
<div class="row justify-content-md-center">
只是
<div class="row">
并在您的 CSS 文件中设置 justify-content 并查看是否有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.