gpt4 book ai didi

css - Bootstrap 布局移位器模式

转载 作者:行者123 更新时间:2023-11-28 15:16:43 24 4
gpt4 key购买 nike

您好,我正在尝试创建一个 layout shifter pattern使用 Bootstrap 4。

我已经设法将 2 个彩色框放在正确的位置以保持响应能力,但我无法将第 3 个框放在正确的位置。

请让我知道我该怎么做。这是我的 html 代码:

<!DOCTYPE html>
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Layout Shifter</title>
<link href="bootstrap.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>

<body>

<!-- navbar -->
<nav class="navbar fixed-top navbar-light bg-light">
<a class="navbar-brand" href="#">Layout Shifter</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row no-gutters">
<div class="col-12 col-md-2">
<div class="blue"></div>
</div>
<div class="col-12 col-md-10">
<div class="red"></div>
</div>
<div class="col-12 col-md-10">
<div class="purple"></div>
</div>
</div>
</div>



<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ"
crossorigin="anonymous"></script>
</body>

</html>

这是我的 CSS 代码:

.blue{
width:100%;height:1100px;
background-color:rgb(88, 88, 211);
}
.red{
width:100%;height:550px;
background-color:rgb(216, 90, 90);
}
.purple{
width:100%;height:550px;
background-color:rgb(168, 68, 214);
}
.orange{
width:100%;height:550px;
background-color:rgb(212, 135, 46);
}
.light-blue{
width:100%;height:550px;
background-color:rgb(160, 168, 238);
}
.container-fluid{
padding:0;
}
.img-fluid{
width:100%;
}
.bg-light{
background-color: #384f3f !important;
}
.navbar-brand{
color: white !important;
}
.nav-link{
color: white !important;
}
.img-responsive{
max-height:550px;
width:100%;
}
.navbar-toggler{
color:white !important;
border-color:white !important;
}

最佳答案

Boostrap 使用 12 网格列系统。您的代码中的问题是您有一个 2 宽的列 + 一个 10 宽的列 + 另一个 10 宽的列。前 2 个坐在单排 (2 + 10 = 12)。第三个被推倒了。为了达到预期的效果,您需要将 2 列中的行拆分为 2 宽度和 10 宽度的列,并在第二列下插入一个新行并将那些 2 10 列放在那里(但使它们成为 12 宽度“col-md -12"所以他们占据了整个空间)。这是 jsfiddle + 您感兴趣的代码: https://jsfiddle.net/Iulius90/t7vhza3g/1/

  <div class="container-fluid">
<div class="row no-gutters">
<div class="col-12 col-md-2">
<div class="blue"></div>
</div>
<div class="col-12 col-md-10">
<div class="row no-gutters">
<div class="col-12 col-md-12">
<div class="red"></div>
</div>
<div class="col-12 col-md-12">
<div class="purple"></div>
</div>
</div>
</div>
</div>

关于css - Bootstrap 布局移位器模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47022206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com