首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使两张卡片的高度相同

如何使两张卡片的高度相同
EN

Stack Overflow用户
提问于 2016-12-19 21:45:59
回答 3查看 6.9K关注 0票数 1

我如何为非洲黑人玩家制作两张牌,为白人玩家制作两张相同高度的牌所有这些牌都使用相同的等级也许有一种方法可以使其高度相同

代码语言:javascript
复制
div.card {
    overflow: hidden;
}

.card {
    width: 100%;
    padding: 9px 20px 9px 20px;
    margin-bottom: 0px;
    background: #ffffff;
    box-shadow: 1px 1px 1px #dfdfdf;
    box-sizing: border-box;
    height: 100% !important;
EN

回答 3

Stack Overflow用户

发布于 2016-12-19 21:53:43

Flexbox在这里派上了用场。注意最后一个元素(有三个<br>的高度比另外两个高,但它们都是相同的高度:

代码语言:javascript
复制
* { box-sizing: border-box; }

.container { 
  display: flex; 
  flex-flow: row wrap;
}

.card-wrap {
  flex: 0 0 33.333%;
  display: flex;
  padding: 10px; /* gutter width */
}

.card {
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
  flex: 0 0 100%;
}
代码语言:javascript
复制
<div class="container">
<div class="card-wrap">
  <div class="card"><br></div>
</div>
<div class="card-wrap">
  <div class="card"><br></div>
</div>
<div class="card-wrap">
  <div class="card"><br><br><br></div>
</div>
</div>

票数 4
EN

Stack Overflow用户

发布于 2016-12-19 21:48:49

如果它们在同一行中,则可以对该行使用display:flex;flex-direction:row;,但如果它们不在同一行中,则可以使用jQuery。下面的代码片段将使每个带有相同高度的class="card"的div

代码语言:javascript
复制
$(document).ready(function (){
  var maxHeight = 0;
  for(i=0;i<$(".card").length;i++){
    if($(".card").eq(i)){
      var currentHeight = $(".card").eq(i).height();
      if(currentHeight>=maxHeight){
        maxHeight = currentHeight;
      }
    }
    else{
      break;
    }
  }
  $(".card").height(maxHeight);
});
票数 2
EN

Stack Overflow用户

发布于 2019-08-06 02:13:34

代码语言:javascript
复制
.container {
  width: 100%;/*whatever size you want your container*/
  border: 3px solid teal;
  display: flex; /*Make sure to call this on your container*/
  align-items: stretch; /*stretches all cards same height*/
  justify-content: space-around; /*some space between cards*/
}

.card {
  width: 150px; /*or whatever size card you want*/
  border: 2px solid red;
}
代码语言:javascript
复制
<div class="container">

  <div class="card">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
  </div>
  
  <div class="card">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  </div>
  
  <div class="card">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
  </div>
  
</div>

这是对我最有效的方法,

我在卡片(不是卡片本身)的容器上设置了display: flex

当您说display: flex时,它默认是flex-direction:

然后简单地在容器上添加align-items: stretch ...

这使得我的卡片具有相同的高度。(此解决方案仅在行设置为 flex-direction 时有效)

希望这能有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41223964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档