Flex子项具有不同的高度

问题描述 投票:4回答:3

我试图让flex项目(橙色div和图片div)具有相同的高度。设置100%的高度没有任何区别,当您缩小浏览器窗口时,最终橙色div变得比图片div高。

知道我哪里错了吗?我认为弹性儿童通常具有相同的高度。

感谢您的帮助。

.appShopSummaryContainer {
  display: flex;
  flex-flow: column wrap;
}

.appShopSummaryContainer .appShopSummaryProductWrap {
  flex-basis: 100%;
  background: pink;
  height: 100%;
  width: 100%;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
}

.appShopSummaryContainer .appShopSummaryImg {
  flex: 0 0 40%;
  height: auto;
  padding-bottom: 26.667%;
  background: green;
  background-size: cover !important;
  background-position: center center !important;
}

.appShopSummaryContainer .appShopSummaryInfo {
  flex: 0 0 60%;
  background: orange;
  height: 100%;
  display: flex;
  flex-flow: column wrap;
  align-items: flex-start;
}

.appShopSummaryContainer .appShopSummaryMoreInfoBtn {
  cursor: pointer;
  background: #214291;
  color: #fff;
  padding: 10px;
  border-radius: 5px;
}
<div class="appShopSummaryContainer">
  <!-- FOR EACH THING DO THIS -->
  <div class="appShopSummaryProductWrap">
    <a href="#" class="appShopSummaryImg" style="background:url('https://cml.sad.ukrd.com/image/394545.jpg')"></a>
    <div class="appShopSummaryInfo">
      <h3>title here...</h3>
      <a href="#" class="appShopSummaryMoreInfoBtn">More Information</a>
    </div>
  </div>
  <!-- ENDFOREACH -->
</div>
html css flexbox
3个回答
3
投票

这是因为你已经将你的物品与中心对齐,从你的appShopSummaryProductWrapheight:100%appShopSummaryInfo中删除它,它将起作用:

.appShopSummaryContainer .appShopSummaryProductWrap {
  background: pink;
  width: 100%;
  display: flex;
  flex-wrap:nowrap;
}

.appShopSummaryContainer .appShopSummaryImg {
  display:block;
  width:40%;
  padding-bottom: 26.667%;
  background: green;
  background-size: cover !important;
  background-position: center center !important;
}

.appShopSummaryContainer .appShopSummaryInfo {
  flex-grow:1;
  background: orange;
  display: flex;
  flex-flow: column wrap;
  align-items: flex-start;
}

.appShopSummaryContainer .appShopSummaryMoreInfoBtn {
  cursor: pointer;
  background: #214291;
  color: #fff;
  padding: 10px;
  border-radius: 5px;
}
<div class="appShopSummaryContainer">
  <!-- FOR EACH THING DO THIS -->
  <div class="appShopSummaryProductWrap">
    <a href="#" class="appShopSummaryImg" style="background:url('https://cml.sad.ukrd.com/image/394545.jpg')"></a>
    
    <div class="appShopSummaryInfo">
      <h3>title here...</h3>
      <a href="#" class="appShopSummaryMoreInfoBtn">More Information</a>
    </div>
  </div>
  <!-- ENDFOREACH -->
</div>

1
投票

尝试删除此类.appShopSummaryContainer .appShopSummaryProductWrap align-items,并在.appShopSummaryContainer .appShopSummaryInfo height删除


1
投票

几件事;

  • 在css中,对于类而不是camel Casing使用连字符是正常的。
  • 如果你在style属性中使用background,你必须在你的CSS中使用!important。如果你使用background-image你没有。
  • 您使用了列,而这是一行。
  • Flex项目需要一个高度的容器。

.appShopSummaryContainer {
  display: flex;
  flex-flow: row wrap;
}
.appShopSummaryContainer .appShopSummaryProductWrap {
  flex-basis: 100%;
  background: pink;
  width: 100%;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
}
.appShopSummaryContainer .appShopSummaryImg {
  flex: 0 0 40%;
  height: 100%;
  background: green;
  background-size: cover;
  background-position: center;
}
.appShopSummaryContainer .appShopSummaryInfo {
  flex: 0 0 60%;
  background: orange;
  height: 100%;
  display: flex;
  flex-flow: column wrap;
  align-items: flex-start;
}
.appShopSummaryContainer .appShopSummaryMoreInfoBtn {
  cursor: pointer;
  background: #214291;
  color: #fff;
  padding: 10px;
  border-radius: 5px;
}
<div class="appShopSummaryContainer">
  <!-- FOR EACH THING DO THIS -->
  <div class="appShopSummaryProductWrap">
    <a href="#" class="appShopSummaryImg" style="background-image: url('http://www.dieren-en-planten.nl/wp-content/uploads/2015/08/800px-Meerkat_feb_09.jpg')"></a>
    <div class="appShopSummaryInfo">
      <h3>title here...</h3>
      <a href="#" class="appShopSummaryMoreInfoBtn"
         >More Information</a>
    </div>
  </div>
  <!-- ENDFOREACH -->
</div>
© www.soinside.com 2019 - 2024. All rights reserved.