引导程序框之间的填充/边距不起作用

时间:2018-06-09 15:09:19

标签: html css html5 twitter-bootstrap

我提高了我的引导技能,我根据那张照片完成了这些盒子,但是需要在盒子之间放置白色空格,就像你可以看到的图片一样,我尝试过填充和边距,但它并没有影响每一个某种方式,任何想法,如何在盒子之间放置空格? 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="row grid " >
    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 offset-lg-3 " style="background-color:red; height:200px;"></div>
    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 " style="background-color:blue; height:200px;"></div>
	

  </div>

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

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

  <script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

在col- * div中添加另一个div并在其上添加高度和颜色而不是col- * div。同时将p-1类添加到所有col div。

一个样本如下所示

    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 offset-lg-3 p-1" >
         <div style="background-color:red; height:200px;"></div>
    </div>

还有一件事,因为您的内容包含row元素,它必须包含在container-fluid div中。由于您尚未添加,因此可以看到水平滚动条。我已在答案中解决了这个问题。

&#13;
&#13;
<!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 col-lg-3 offset-lg-3 p-1" ><div style="background-color:red; height:200px;"></div></div>
    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 p-1" ><div style="background-color:blue; height:200px;"></div></div>
	

  </div>

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

  <div class="row grid">
    <div class="col-xs-12 col-sm-6 col-md-4 offset-md-4 col-lg-3 offset-lg-0 p-1" ><div style="background-color:black;height:200px; "></div></div>
    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 offset-lg-6 p-1"><div style="background-color:orange; height:200px;"></div></div>
  </div>
</div>
  <script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
&#13;
&#13;
&#13;