gpt4 book ai didi

css - bootstrap 上的偏移量和边距

转载 作者:行者123 更新时间:2023-11-28 01:34:03 25 4
gpt4 key购买 nike

我在 bootstrap 4 上玩偏移量和边距,我想实现 像这张照片一样,除了盒子之间的空白,一切正常,当你变成中等尺寸时,蓝色和黄色的盒子彼此相邻,但是当我放 mr-md-2 时,蓝色的盒子就消失了,为什么?我想要所有框和尺寸之间的空白,如图中所示 enter image description here

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.css">

<style>

</style>

</head>

<body>
<div class="container-fluid">
<div class="row grid " >
<div class="col-xs-12 col-sm-6 col-md-4 mr-md-2 col-lg-3 offset-lg-3 " style="background-color:burlywood; height:200px;"></div>
<div class="col-xs-12 col-sm-6 col-md-4 ml-md-2 col-lg-3 " style="background-color:orange; height:200px;"></div>
</div>

<div class="row grid">
<div class="col-xs-12 col-sm-6 mt-md-2 mt-md-3 col-md-4 col-lg-6 " style="background-color:black;height:200px; "></div>
<div class="col-xs-12 col-sm-6 col-md-4 mt-md-2 offset-md-4 col-lg-3 offset-lg-3 " style="height:200px;background-color:red; "></div>
</div>

<div class="row grid">
<div class="col-xs-12 col-sm-6 col-md-4 mt-md-2 offset-md-4 col-lg-3 offset-lg-0 " style="background-color:yellow;height:200px; "></div>

<div class="col-xs-12 col-sm-6 col-md-4 mt-md-2 mr- col-lg-3 mr-lg-0 offset-lg-6 " style="background-color:blue; height:200px;"></div>
</div>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>

最佳答案

请考虑在 BS 网格系统中,columns 之间(或 row 之间)没有边距,但有间距:

全屏运行此代码段并调整窗口大小:

.row > div {
/* background-color: lightsteelblue; */
margin-top:20px;
}

.content {
background-color: burlywood;
height: 200px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>


<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 offset-lg-3">
<div class="content">r1c1</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
<div class="content">r1c2</div>
</div>
</div>

<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-6">
<div class="content">r2c1</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 offset-md-4 col-lg-3 offset-lg-3 ">
<div class="content">r2c2</div>
</div>
</div>

<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 offset-md-4 col-lg-3 offset-lg-0 ">
<div class="content">r3c1</div>
</div>

<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 offset-lg-6">
<div class="content">r3c2</div>
</div>
</div>
</div>

关于css - bootstrap 上的偏移量和边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50784787/

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