【问题标题】:Bootstrap vue cards bottom buttons to be alignedBootstrap vue卡底部按钮对齐
【发布时间】:2021-06-10 12:49:51
【问题描述】:

我正在使用带有 vue 的 bootstrap vue 来编写 4 x 4 卡。目前,其中一张卡片中的标题与卡片底部的一个按钮相混淆。下面的媒体宽度约为 1000 像素。

请参考下图

但是,当我将标题更改为较短的标题时,它是对齐的。请参考下图

我知道这与宽度有关,但我似乎无法弄清楚是什么原因造成的。

我尝试解决问题的步骤是在父级上使用 flex grow 并为标题使用自动换行,但仍然没有。希望有人能解释一下。

附加是我的代码沙箱的 url。 https://codesandbox.io/s/vue-cards-hx5c9

我还将在下面附上我的代码。谢谢。 更新:我已经在我的沙盒中更新了我的字体系列,然后问题就出现了

<template>
  <b-container fluid class="bv-example-row cards-row">
    <b-row cols="1" cols-sm="1" cols-md="1" cols-lg="4">
      <b-col class="desktop-col">
        <div>
          <b-card
            title="Stock & ETFs"
            img-src="https://picsum.photos/600/300/?image=25"
            img-alt="Image"
            img-bottom
            class="mb-2 h-100"
          >
            <b-card-text>
              0% commission means there’s no markup on stocks & ETFs – no matter
              how much you invest
            </b-card-text>

            <div class="cta_wrap">
              <div class="row">
                <a variant="primary" href="#">Learn More</a>
              </div>
              <div class="row mt-2">
                <b-button href="#" variant="primary">Invest in Stocks</b-button>
              </div>
            </div>
          </b-card>
        </div>
      </b-col>
      <b-col class="desktop-col">
        <div>
          <b-card
            title="Cryptocurrencies"
            img-src="https://picsum.photos/600/300/?image=25"
            img-alt="Image"
            img-bottom
            class="mb-2 h-100"
          >
            <b-card-text>
              Buy, sell and store Bitcoin and other leading cryptos with ease
            </b-card-text>

            <div class="cta_wrap">
              <div class="row">
                <a variant="primary" href="#">Learn More</a>
              </div>
              <div class="row mt-2">
                <b-button href="#" variant="primary"
                  >Buy Cryptocurrencies</b-button
                >
              </div>
            </div>
          </b-card>
        </div>
      </b-col>
      <b-col class="desktop-col">
        <div>
          <b-card
            title="CFD Trading"
            img-src="https://picsum.photos/600/300/?image=25"
            img-alt="Image"
            img-bottom
            class="mb-2 h-100"
          >
            <b-card-text>
              Go long or short on FX from just 1 pip. Trade commodities and
              indices with flexible leverage
            </b-card-text>

            <div class="cta_wrap">
              <div class="row">
                <a variant="primary" href="#">Learn More</a>
              </div>
              <div class="row mt-2">
                <b-button href="#" variant="primary">Trade Now</b-button>
              </div>
            </div>
          </b-card>
        </div>
      </b-col>
      <b-col class="desktop-col">
        <div>
          <b-card
            title="Forex"
            img-src="https://picsum.photos/600/300/?image=25"
            img-alt="Image"
            img-bottom
            class="mb-2 h-100"
          >
            <b-card-text>
              Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim nam
              qui illum. Ipsa aliquam quas magnam est perferendis a, repellendus
              unde, nemo expedita doloremque suscipit ut dolore consequuntur
              amet vero!
            </b-card-text>

            <div class="cta_wrap">
              <div class="row">
                <a variant="primary" href="#">Learn More</a>
              </div>
              <div class="row mt-2">
                <b-button href="#" variant="primary">Buy Forex</b-button>
              </div>
            </div>
          </b-card>
        </div>
      </b-col>
    </b-row>
  </b-container>
</template>
<script>
export default {
  name: "Content",
  data() {
    return {};
  },
};
</script>
<style scoped>
.cards-row {
  position: relative;
  bottom: 50px;
}

.card-text {
  min-height: auto;
  flex-grow: 1;
}

.card-body {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.cta_wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
}

@media screen and (max-width: 992px) {
  .cta_wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
}

@media screen and (min-width: 992px) {
  .desktop-col {
    display: flex;
    justify-content: center;
  }
}
</style>

【问题讨论】:

  • 我没有看到你所说的这个“对齐”版本。无论“加密货币”标题的宽度如何,每个“卡片”页脚中的所有按钮/文本看起来都相同。
  • 您可以在截屏时指定您使用的浏览器。我一直在用不同的浏览器测试你的代码框,它在我的电脑上运行。
  • 你好。我在 Safari 和 Chrome 中检查了您的问题,正如我在屏幕截图中看到的那样,它们看起来很好。我无法理解问题是什么?你能再解释一下吗?
  • 抱歉,我忘记更新沙盒中的字体系列了,如果你现在进入沙盒并将其缩小到 1000 像素 - 1072 像素,你会发现问题。

标签: html css vue.js flexbox bootstrap-vue


【解决方案1】:

我认为问题在于图像大小。为了控制这一点,我们可以为 card-img 赋予 ma​​x-height: 112px 样式。但是我们必须给它一个大于 991px 的尺寸。这样我们就可以在 flex-direction 返回 column 时保护我们的图像尺寸。这是我为您的风格添加的内容;

@media screen and (min-width: 992px) {
  .card-img,
  .card-img-top,
  .card-img-bottom {
    max-height: 112px !important;
  }
}

 

【讨论】:

  • 非常感谢您。你是个天才 :) 它解决了我的问题。
猜你喜欢
  • 2018-07-02
  • 1970-01-01
  • 2023-03-12
  • 2018-09-23
  • 2019-03-11
  • 2017-01-29
  • 1970-01-01
  • 2020-08-22
相关资源
最近更新 更多