Bootstrap 3 列中的图像高度相同 (Material Kit Pro UI)

Same height for images in Bootstrap 3 columns (Material Kit Pro UI)

所以我开始使用 Material 工具包 UI 现在,正如您在图片中看到的那样,列内的图像高度不同。

还有代码:

<div class="container-fluid sec1">
    <div class="row">
        <div class="col-sm-3 col-md-2 col-lg-2">
            <div class="anime card card-blog">
                <div class="card-image animeimg">
                    <div class="timenumber">
                        <h4>2 دقیقه قبل</h4>
                    </div>
                    <a href="#" title="Sword Art Online">
                        <img class="img" src="https://i.stack.imgur.com/Ki247.jpg">
                    </a>
                    <div class="colored-shadow" style="background-image: url(&quot;https://i.stack.imgur.com/Ki247.jpg&quot;); opacity: 1;"></div>
                    <div class="ripple-container"></div>
                </div>

                <div class="card-content sectit">
                    <h6 class="category text-success">در حال پخش</h6>
                    <h4 class="card-title">
                        <a href="#" title="Sword Art Online">Sword Art Online</a>
                    </h4>

                    <div class="footer episodenumber">
                        قسمت 13
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

和 css:

    .anime {
    margin-bottom: 20px;
    background: none !important;
    box-shadow: none !important;
}
.card-blog {
    margin-top: 30px;
}
.card {
    display: inline-block;
    position: relative;
    width: 100%;
    margin-bottom: 30px;
    border-radius: 6px;
    color: rgba(0,0,0, 0.87);
    background: #fff;
    box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
.card .card-image {
    height: 60%;
    position: relative;
    z-index: 1;
    margin-left: 15px;
    margin-right: 15px;
    margin-top: -30px;
    border-radius: 6px;
}
.animeimg {
    margin-left: 0 !important;
    margin-right: 0 !important;
}
.timenumber {
    z-index: 9999;
    font-size: 12px !important;
    float: right;
    position: absolute;
    padding: 8px 10px;
    color: #fff;
}
a {
    text-decoration: none !important;
}
.card .card-image img {
    width: 100%;
    border-radius: 6px;
    pointer-events: none;
    box-shadow: 0 5px 15px -8px rgba(0, 0, 0, 0.24), 0 8px 10px -5px rgba(0, 0, 0, 0.2);
}
.card img {
    width: 100%;
    height: auto;
}
.card .card-image .colored-shadow {
    transform: scale(0.94);
    top: 12px;
    filter: blur(12px);
    position: absolute;
    width: 100%;
    height: 100%;
    background-size: cover;
    z-index: -1;
    transition: opacity .45s;
    opacity: 0;
}
.ripple-container {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}
.animeimg:after {
    border-radius: 6px;
    position: absolute;
    z-index: 1;
    width: 100%;
    height: 98.5%;
    display: block;
    left: 0;
    top: 0;
    content: "";
    background: -webkit-linear-gradient(top, rgba(0, 0, 0, .5) 0, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .5) 100%);
    background: linear-gradient(to bottom, rgba(0, 0, 0, .5) 0, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .5) 100%);
}
.card .card-content {
    padding: 15px 30px;
}
.sectit {
    padding: 0 !important;
}
.sectit > h6 {
    padding-bottom: 10px;
    font-size: 12px;
    display: none;
}
.text-success {
    color: #4caf50;
}
.text-success {
    color: #3c763d;
}
.card-blog .card-title {
    margin-top: 5px;
}
@media (min-width: 992px)
.sectit > h4 {
    width: 60%;
}
.sectit > h4 {
    margin-top: 5px !important;
    margin-bottom: 5px;
    width: 65%;
    direction: ltr;
    float: left;
    font-weight: 700;
    font-size: .9rem;
    font-family: 'Roboto Condensed';
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.title, .title a, .card-title, .card-title a, .info-title, .info-title a, .footer-brand, .footer-brand a, .footer-big h5, .footer-big h5 a, .footer-big h4, .footer-big h4 a, .media .media-heading, .media .media-heading a {
    color: #3C4858;
    text-decoration: none;
}
.title, .card-title, .info-title, .footer-brand, .footer-big h5, .footer-big h4, .media .media-heading {
    font-weight: 700;
    font-family: "Roboto Slab", "Times New Roman", serif;
}
.sectit > h4 > a {
    color: #000;
}
.title, .title a, .card-title, .card-title a, .info-title, .info-title a, .footer-brand, .footer-brand a, .footer-big h5, .footer-big h5 a, .footer-big h4, .footer-big h4 a, .media .media-heading, .media .media-heading a {
    color: #3C4858;
    text-decoration: none;
}
.card .footer {
    margin-top: 15px;
}
.episodenumber {
    float: right;
    margin-top: 8px !important;
    font-size: 12px;
}

所以我尝试更改“.card img”中的高度(从自动更改为 18rem),但图像不再有响应。 我也尝试设置 min-height 但它也没有用。

这里有两张不同高度的图片:
- https://i.stack.imgur.com/Ki247.jpg
- https://i.stack.imgur.com/vGjYd.jpg

您需要设置 .card .card-image a 的高度,然后 overflow:hidden 以隐藏多余的内容。

.card .card-image a {
  display: block;
  height: 300px;
  overflow: hidden;
  border-radius: 10px;
}

堆栈片段

.anime {
  margin-bottom: 20px;
  background: none !important;
  box-shadow: none !important;
}

.card-blog {
  margin-top: 30px;
}

.card {
  display: inline-block;
  position: relative;
  width: 100%;
  margin-bottom: 30px;
  border-radius: 6px;
  color: rgba(0, 0, 0, 0.87);
  background: #fff;
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
}

.card .card-image {
  height: 60%;
  position: relative;
  z-index: 1;
  margin-left: 15px;
  margin-right: 15px;
  margin-top: -30px;
  border-radius: 6px;
}

.animeimg {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.timenumber {
  z-index: 9999;
  font-size: 12px !important;
  float: right;
  position: absolute;
  padding: 8px 10px;
  color: #fff;
}

a {
  text-decoration: none !important;
}

.card .card-image img {
  width: 100%;
  border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 5px 15px -8px rgba(0, 0, 0, 0.24), 0 8px 10px -5px rgba(0, 0, 0, 0.2);
}

.card img {
  width: 100%;
  height: auto;
}

.card .card-image .colored-shadow {
  transform: scale(0.94);
  top: 12px;
  filter: blur(12px);
  position: absolute;
  width: 100%;
  height: 100%;
  background-size: cover;
  z-index: -1;
  transition: opacity .45s;
  opacity: 0;
}

.ripple-container {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.animeimg:after {
  border-radius: 6px;
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 98.5%;
  display: block;
  left: 0;
  top: 0;
  content: "";
  background: -webkit-linear-gradient(top, rgba(0, 0, 0, .5) 0, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .5) 100%);
  background: linear-gradient(to bottom, rgba(0, 0, 0, .5) 0, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .05) 50%, rgba(0, 0, 0, .5) 100%);
}

.card .card-content {
  padding: 15px 30px;
}

.sectit {
  padding: 0 !important;
}

.sectit>h6 {
  padding-bottom: 10px;
  font-size: 12px;
  display: none;
}

.text-success {
  color: #4caf50;
}

.text-success {
  color: #3c763d;
}

.card-blog .card-title {
  margin-top: 5px;
}

@media (min-width: 992px) .sectit>h4 {
  width: 60%;
}

.sectit>h4 {
  margin-top: 5px !important;
  margin-bottom: 5px;
  width: 65%;
  direction: ltr;
  float: left;
  font-weight: 700;
  font-size: .9rem;
  font-family: 'Roboto Condensed';
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.title,
.title a,
.card-title,
.card-title a,
.info-title,
.info-title a,
.footer-brand,
.footer-brand a,
.footer-big h5,
.footer-big h5 a,
.footer-big h4,
.footer-big h4 a,
.media .media-heading,
.media .media-heading a {
  color: #3C4858;
  text-decoration: none;
}

.title,
.card-title,
.info-title,
.footer-brand,
.footer-big h5,
.footer-big h4,
.media .media-heading {
  font-weight: 700;
  font-family: "Roboto Slab", "Times New Roman", serif;
}

.sectit>h4>a {
  color: #000;
}

.title,
.title a,
.card-title,
.card-title a,
.info-title,
.info-title a,
.footer-brand,
.footer-brand a,
.footer-big h5,
.footer-big h5 a,
.footer-big h4,
.footer-big h4 a,
.media .media-heading,
.media .media-heading a {
  color: #3C4858;
  text-decoration: none;
}

.card .footer {
  margin-top: 15px;
}

.episodenumber {
  float: right;
  margin-top: 8px !important;
  font-size: 12px;
}

.card .card-image a {
  display: block;
  height: 300px;
  overflow: hidden;
  border-radius: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid sec1">
  <div class="row">
    <div class="col-xs-6 col-md-2 col-lg-2">
      <div class="anime card card-blog">
        <div class="card-image animeimg">
          <div class="timenumber">
            <h4>2 دقیقه قبل</h4>
          </div>
          <a href="#" title="Sword Art Online">
            <img class="img" src="https://i.stack.imgur.com/Ki247.jpg">
          </a>
          <div class="colored-shadow" style="background-image: url(&quot;https://i.stack.imgur.com/Ki247.jpg&quot); opacity: 1;"></div>
          <div class="ripple-container"></div>
        </div>

        <div class="card-content sectit">
          <h6 class="category text-success">در حال پخش</h6>
          <h4 class="card-title">
            <a href="#" title="Sword Art Online">Sword Art Online</a>
          </h4>

          <div class="footer episodenumber">
            قسمت 13
          </div>
        </div>
      </div>
    </div>
    <div class="col-xs-6 col-md-2 col-lg-2">
      <div class="anime card card-blog">
        <div class="card-image animeimg">
          <div class="timenumber">
            <h4>2 دقیقه قبل</h4>
          </div>
          <a href="#" title="Sword Art Online">
            <img class="img" src="https://i.stack.imgur.com/vGjYd.jpg">
          </a>
          <div class="colored-shadow" style="background-image: url(&quot;https://i.stack.imgur.com/vGjYd.jpg&quot;); opacity: 1;"></div>
          <div class="ripple-container"></div>
        </div>

        <div class="card-content sectit">
          <h6 class="category text-success">در حال پخش</h6>
          <h4 class="card-title">
            <a href="#" title="Sword Art Online">Sword Art Online</a>
          </h4>

          <div class="footer episodenumber">
            قسمت 13
          </div>
        </div>
      </div>
    </div>
  </div>
</div>