简体   繁体   English

引导程序在列之间添加空间

[英]Bootstrap Add Space between Columns

I have closely followed the most popular example of how to add space between columns, but it doesn't work. 我密切关注有关如何在列之间添加空间的最流行示例 ,但这没有用。 You can view it in action at 您可以在以下位置查看它的实际运行情况

codepen.io codepen.io

What I've done is put a col-sm-12 inside of a col-sm-4 for each column. 我所做的是将col-sm-12放在每一列的col-sm-4 According to the most popular answer here this should automatically render some space between the 2 divs. 根据这里最流行的答案,这应该会自动在2个div之间渲染一些空间。

HTML: HTML:

<div class="row blocks-grid">
  <div class="col-xs-6 col-sm-4 item">
    <div class="col-sm-12">
      <img src="http://example.com/1MBVDF4">
      <h2>This is me</h2>
    </div>
  </div>

  <div class="col-xs-6 col-sm-4 item">
    <div class="col-sm-12">
      <img src="http://example.com/1MBVDF4">
      <h2>This is me</h2>
    </div>
  </div>

  <div class="col-xs-6 col-sm-4 item">
    <div class="col-sm-12">
      <img src="http://example.com/1MBVDF4">
      <h2>This is me</h2>
    </div>
  </div>  
</div>

CSS: CSS:

body {
  background: #BEB7A4;
}
.blocks-grid {
  max-width:75.0rem; 
  margin:0 auto;
  .item {
    cursor: pointer;
    margin-bottom:1rem;
    position:relative;
    height:34.0rem;
    padding-top:2.5rem;
    background:#FFFFFC;
    &:hover {
      background:#FF0000;
      color:white;
      img {
        display:none;
      }
    }
    h2 {
      font-size:2.0rem;
      margin-top:1rem;
      text-align: center;
    }    
    img {
      max-width: 100%;
      margin:auto;
      display:block;
    }
  }
}

Basically, I would think the result would look like the following photo, but it does not: 基本上,我认为结果看起来像下面的照片,但事实并非如此:

在此处输入图片说明

you can try this: Demo 您可以尝试以下方法: 演示

Add your "item" class with "col-sm-12" 使用“ col-sm-12”添加“ item”类

body {
  background: #BEB7A4;
}

I made some changes on your code. 我对您的代码进行了一些更改。

HTML HTML

Note the subitem class added to col-sm-12 divs. 请注意添加到col-sm-12 divs中的subitem类。

<div class="row blocks-grid">
  <div class="col-sm-4 item">
    <div class="col-sm-12 subitem">
      <img src="image_url">
      <h2>This is me</h2>
    </div>
  </div>

  <div class="col-sm-4 item">
    <div class="col-sm-12 subitem">
      <img src="image_url">
      <h2>This is me</h2>
    </div>
  </div>

  <div class="col-sm-4 item">
    <div class="col-sm-12 subitem">
      <img src="image_url">
      <h2>This is me</h2>
    </div>
  </div>  
</div>

LESS

body {
  background: #BEB7A4;
}
.blocks-grid {
  max-width:75.0rem; 
  margin:0 auto;
  .item {
    cursor: pointer;
    margin-bottom:1rem;
    position:relative;
    height:34.0rem;
    padding-top:2.5rem;
    .subitem {
      background:#FFFFFC;
      height: 100%;
      padding-top: 50px;
      &:hover {
        background:#FF0000;
        color:white;
        img {
          display:none;
        }
      }
      h2 {
        font-size:2.0rem;
        margin-top:1rem;
        text-align: center;
      }    
      img {
        max-width: 100%;
        margin:auto;
        display:block;
      }
    }    
  }
}

Take a look: http://codepen.io/anon/pen/KgzVRK 看看: http : //codepen.io/anon/pen/KgzVRK

Hope it can helps you. 希望它能对您有所帮助。

You can actually remove all the extra junk and let bootstrap do it for you... NEVER change margins / widths on the framework. 您实际上可以删除所有多余的垃圾,并让引导程序为您完成...切勿更改框架的边距/宽度。 This is all you need.... 这就是您所需要的...

HTML HTML

<div class="row">
  <div class="col-xs-6 col-sm-4">
    <img src="http://placehold.it/350x250">
    <h2>This is me</h2>
  </div> 
<div class="col-xs-6 col-sm-4">
    <img src="http://placehold.it/350x150">
    <h2>This is me</h2>
</div>  
  <div class="col-xs-6 col-sm-4">
    <img src="http://placehold.it/350x150">
    <h2>This is me</h2>
  </div>  
</div>

CSS CSS

img { width: 100%; }

You may try to move the class item from col-xs-6 to col-sm-12 您可以尝试将课程项目从col-xs-6移至col-sm-12

The snippet: 片段:

 body { background: #BEB7A4; } .blocks-grid { max-width: 75.0rem; margin: 0 auto; } .blocks-grid .item { cursor: pointer; margin-bottom: 1rem; position: relative; height: 34.0rem; padding-top: 2.5rem; background: #FFFFFC; } .blocks-grid .item:hover { background: #FF0000; color: white; } .blocks-grid .item:hover img { display: none; } .blocks-grid .item h2 { font-size: 2.0rem; margin-top: 1rem; text-align: center; } .blocks-grid .item img { max-width: 100%; margin: auto; display: block; } 
 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'> <style> body { background: #BEB7A4; } .blocks-grid { max-width: 75.0rem; margin: 0 auto; } .blocks-grid .item { cursor: pointer; margin-bottom: 1rem; position: relative; height: 34.0rem; padding-top: 2.5rem; background: #FFFFFC; } .blocks-grid .item:hover { background: #FF0000; color: white; } .blocks-grid .item:hover img { display: none; } .blocks-grid .item h2 { font-size: 2.0rem; margin-top: 1rem; text-align: center; } .blocks-grid .item img { max-width: 100%; margin: auto; display: block; } </style> </head> <body> <div class="row blocks-grid"> <div class="col-xs-6 col-sm-4"> <div class="col-sm-12 item"> <img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg"> <h2>This is me</h2> </div> </div> <div class="col-xs-6 col-sm-4"> <div class="col-sm-12 item"> <img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg"> <h2>This is me</h2> </div> </div> <div class="col-xs-6 col-sm-4"> <div class="col-sm-12 item"> <img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg"> <h2>This is me</h2> </div> </div> </div> </body> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM