【问题标题】:Bootstrap 3 column gutterBootstrap 3列装订线
【发布时间】:2017-08-09 21:21:28
【问题描述】:

我多次尝试解决此问题,但仍然出现,我只是找不到正确的解决方法。 我无法在 Bootstrap 3 中的列周围创建排水沟。这是我的小提琴:jsfiddle.net/creuxttL

我的确切问题:当我创建这三列时,我希望它们之间有一些排水沟,所以它们看起来不像一块大砖。默认情况下我没有任何排水沟,所以我尝试手动进行 - 使用 css 类 .col 。我仍然没有在盒子周围得到任何边距/填充。我该怎么办?

【问题讨论】:

  • 你的行应该是class="row" 而不是id="row"
  • 仍然没有解决我的问题...
  • 那你需要更清楚地定义你的问题。
  • 我编辑了我的原始帖子。去看看吧。
  • 但是有一个gutter,Bootstrap在col-*的两边各有15px

标签: html css twitter-bootstrap


【解决方案1】:

你的小提琴没有包含 bootstrap 3。 http://jsfiddle.net/va94exo2/ 稍作修改。

用内部 div 包装了所有 col-md-4 内容并将 ID="row" 更改为 class 并删除了额外的 .col 类,然后还设置了内部 div 的样式。

.inner-content{
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  color: white;
  text-align: center;
  background-color: #00b9ff;
  border: 1px solid black;
}
.overlay-pic {
  max-height: 200px;
  display: block;
  margin: auto;
}

.overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #44cbff;
  overflow: hidden;
  width: 100%;
  height: 0;
  transition: .5s ease;
}

.overlay p {
  font-family: 'Raleway';
  font-style: italic;
  white-space: nowrap;
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.col {
  /*gutter*/
  padding-right: 7px;
  padding-left: 7px;
}

.col:not(:first-child, :last-child) {
  padding-right: 7px;
  padding-left: 7px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <div class="row" style="margin-top: 10px;">
  
    <div class="col-md-4">
      <div class="inner-content">    
      
      <h1>Festival 2001</h1>
      <img src="event.jpg" class="overlay-pic hidden-tablet img-responsive">
      <div class="overlay">
        <p>Our event.</p>
      </div>
      </div>
    </div>

    <div class="col-md-4">
    <div class="inner-content">
      <h1>Who are we?</h1>
      <img src="question.jpg" class="overlay-pic hidden-tablet img-responsive">
      <div class="overlay">
        <p>Read more about us</p>
      </div>
      </div>
    </div>

    <div class="col-md-4">
    <div class="inner-content">
      <h1>where, when?</h1>
      <img src="calendar.jpg" class="overlay-pic hidden-tablet img-responsive">
      <div class="overlay">
        <p>Look at our calendar.</p>
      </div>
    </div>
    </div>
    </div>
 
</div>

【讨论】:

    【解决方案2】:

    不肯定这正是你正在寻找的,但如果你只是想要行之间的空间,你可以在“.col-md”中为你的css添加一个“margin-top”属性-4" 类。

    希望这会有所帮助。

    .col-md-4 {
      font-family: 'Roboto', sans-serif;
      font-weight: 100;
      color: white;
      text-align: center;
      background-color: #00b9ff;
      border: 1px solid black;
      margin-top:10px;
    }
    
    .overlay-pic {
      max-height: 200px;
      display: block;
      margin: auto;
    }
    
    .overlay {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: #44cbff;
      overflow: hidden;
      width: 100%;
      height: 0;
      transition: .5s ease;
    }
    
    .overlay p {
      font-family: 'Raleway';
      font-style: italic;
      white-space: nowrap;
      color: white;
      font-size: 20px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
    }
    
    .col {
      /*gutter*/
      padding-right: 7px;
      padding-left: 7px;
    }
    
    .col:not(:first-child, :last-child) {
      padding-right: 7px;
      padding-left: 7px;
    }
    <div class="container">
      <div id="row" style="margin-top: 10px;">
        <div class="col-md-4 col">
          <h1>Festival 2001</h1>
          <img src="event.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Our event.</p>
          </div>
        </div>
    
        <div class="col-md-4 col">
          <h1>Who are we?</h1>
          <img src="question.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Read more about us</p>
          </div>
        </div>
    
        <div class="col-md-4 col">
          <h1>where, when?</h1>
          <img src="calendar.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Look at our calendar.</p>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 我没有看到列(垂直),只有三个 div“块”堆叠在一起。您是否尝试运行我提供的代码 sn-p?我在每个 div / "block" 之间添加了一些空格..
    【解决方案3】:

    不添加引导程序。我修改了你的代码。我希望您对此有所期待。

    .col {
      font-family: 'Roboto', sans-serif;
      font-weight: 100;
      color: white;
      text-align: center;
      background-color: white;
    }
    
    .overlay-pic {
      max-height: 200px;
      display: block;
      margin: auto;
    }
    
    .overlay {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: #44cbff;
      overflow: hidden;
      width: 100%;
      height: 0;
      transition: .5s ease;
    }
    
    .overlay p {
      font-family: 'Raleway';
      font-style: italic;
      white-space: nowrap;
      color: white;
      font-size: 20px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
    }
    
    .col h1{
      margin-top:0px;
    }
    <div class="container">
      <div id="row">
        <div class="col-md-4 col">
        <div style="margin:5px; background:#00b9ff;border: 1px solid black;">
          <h1>Festival 2001</h1>
          <img src="event.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Our event.</p>
          </div>
          </div>
        </div>
    
        <div class="col-md-4 col">
        <div style="margin:5px; background:#00b9ff;border: 1px solid black;">
          <h1>Who are we?</h1>
          <img src="question.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Read more about us</p>
            </div></div>
        </div>
    
        <div class="col-md-4 col">
        <div style="margin:5px; background:#00b9ff;border: 1px solid black;">
          <h1>where, when?</h1>
          <img src="calendar.jpg" class="overlay-pic hidden-tablet img-responsive">
          <div class="overlay">
            <p>Look at our calendar.</p>
          </div>
          </div></div>
      </div>
    </div>

    【讨论】: