col-sm-4不适合三列

时间:2016-06-22 02:28:59

标签: html css twitter-bootstrap col

当我使用col-sm-4时,只有两列适合。即使我查看缩小最多的网页,也会发生这种情况。有两列显示而不是三列。我试图编辑边距,但这没有用。 Here is how it looks.这似乎非常业余,但我其实是业余爱好者。感谢。

HTML

<section class="container">
  <div class="eventDisplay">
    <h2>Available Events</h2>
    <div class="eventDisplay row">

      <div class="eventDisplay col-sm-4">
        <div class="thumb">
          <span>Event Name</span>
        </div>

        <h2 style="font-weight: bold;">September 20 | 9:00am - 4:00pm <br/><br/> @Rouge Valley Park</h2>
        <hr>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dignissim nisi mauris, quis semper ex vehicula ut. Etiam cursus convallis ullamcorper. Donec a sagittis ipsum. Sed ut arcu non augue aliquam finibus nec quis massa.
        </p>

        <div class="centerButton">
          <a class="btn btn-secondary" href="mailto:tempEmail?Subject=Event Title &body=Name:">get planting</a>
        </div>
      </div>

      (this time 3)

    </div>
  </div>
</section>

CSS

.eventdisplay.row {
  margin: 30px;
}

.eventDisplay.col-sm-4 {
  margin: 50px;
  border-radius: 12px;
  box-shadow: 5px 5px 25px #B8B8B8;
  padding: 0 !important;
}

.thumb {
  -webkit-border-top-right-radius: 12px;
  -webkit-border-top-left-radius: 12px;
  display: block;
  background-image: url("img/trees.jpg");
  background-size: cover;
  height: 300px;
  width: 100%;
  position: relative;
}

2 个答案:

答案 0 :(得分:1)

这就是我至少看起来的样子:你因为某种原因将这个级别.eventDisplay 3级深度嵌套,并尝试将其与.row或{{{{{}一起使用1}}这会扰乱这些类的属性并导致网格中断。作为一般规则,将您的内容放在网格中

.col-*-*

以下是两个示例:一个用于清理当前代码,另一个用于修改Card Component

示例1:对您拥有的内容进行排序。

&#13;
&#13;
.container
  .row
    .col-*-*
      .content
&#13;
.eventDisplay {
  border-radius: 12px;
  box-shadow: 5px 5px 25px #B8B8B8;
}
.thumb {
  -webkit-border-top-right-radius: 12px;
  -webkit-border-top-left-radius: 12px;
  background-image: url("http://placehold.it/350x150");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  width: 100%;
  height: 150px;
}
&#13;
&#13;
&#13;

示例2:使用Bootstrap v4卡。

&#13;
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet" />
<section class="container">
  <div class="row">

    <div class="col-sm-4">

      <div class="eventDisplay">
        <div class="thumb">
          <span>Event Name</span>
        </div>
        <h2>Available Events</h2>
        <h2>September 20 | 9:00am - 4:00pm <br/><br/> @Rouge Valley Park</h2>
        <hr>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dignissim nisi mauris, quis semper ex vehicula ut. Etiam cursus convallis ullamcorper. Donec a sagittis ipsum. Sed ut arcu non augue aliquam finibus nec quis massa.</p>
        <div class="centerButton">
          <a class="btn btn-secondary" href="mailto:tempEmail?Subject=Event Title &body=Name:">get planting</a>
        </div>
      </div>

    </div>

    <div class="col-sm-4">

      <div class="eventDisplay">
        <div class="thumb">
          <span>Event Name</span>
        </div>
        <h2>Available Events</h2>
        <h2>September 20 | 9:00am - 4:00pm <br/><br/> @Rouge Valley Park</h2>
        <hr>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dignissim nisi mauris, quis semper ex vehicula ut. Etiam cursus convallis ullamcorper. Donec a sagittis ipsum. Sed ut arcu non augue aliquam finibus nec quis massa.</p>
        <div class="centerButton">
          <a class="btn btn-secondary" href="mailto:tempEmail?Subject=Event Title &body=Name:">get planting</a>
        </div>
      </div>

    </div>

    <div class="col-sm-4">

      <div class="eventDisplay">
        <div class="thumb">
          <span>Event Name</span>
        </div>
        <h2>Available Events</h2>
        <h2>September 20 | 9:00am - 4:00pm <br/><br/> @Rouge Valley Park</h2>
        <hr>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dignissim nisi mauris, quis semper ex vehicula ut. Etiam cursus convallis ullamcorper. Donec a sagittis ipsum. Sed ut arcu non augue aliquam finibus nec quis massa.</p>
        <div class="centerButton">
          <a class="btn btn-secondary" href="mailto:tempEmail?Subject=Event Title &body=Name:">get planting</a>
        </div>
      </div>

    </div>

  </div>
</section>
&#13;
body {
  padding-top: 50px;
}
.card.eventDisplay {
  box-shadow: .25rem .25rem 1.75rem #B8B8B8;
  border: none;
}
.btn.btn-black {
  background: #000;
  color: white;
  border-radius: 2.5rem;
}
.card-img.card-img-bottom {
  border-radius: .25rem .25rem 0 0;
}
@media (min-width: 48em) and (max-width: 61em) {
  .event:nth-child(2n+1) {
    clear: left;
  }
}
@media (min-width: 62em) {
  .event:nth-child(3n+1) {
    clear: left;
  }
}
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

检查一下:

  1. 删除任何保证金
  2. 在任何行之前添加一个包含类row的div在您的案例中将col-sm-4放入divrow
  3. 将此添加到所有元素box-sizing: border-box;