我在bootstrap 4上玩偏移和边距,我想实现 像这张照片之类的东西除了盒子之间的白色空间外什么都有用,当你去中等尺寸时,蓝色和黄色的盒子彼此相邻但是当我把mr-md-2然后蓝盒子掉下来,为什么呢?我希望所有方框和尺寸之间都有空格,如图
<!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>
&#13;
答案 0 :(得分:0)
考虑到在BS网格系统中,col
umns之间(或者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>