html - 如何增加一个人的高度与行中的其他人对齐?
问题描述
我目前正在建立一个网站,它是一个电子商务网站,而我目前正停留在实际的商店建设部分。相关代码如下:
.storeItems{
display: inline-flex;
padding-top: 5%;
justify-content: space-evenly;
margin-left: 10%;
margin-right: 10%;
align-items: stretch;
padding-left: 2%;
padding-right: 2%;
}
.storeitem{
padding-top: 1%;
border-radius: 10px;
background-color:#c1d8ee;
display: inline-flex;
flex-flow: row wrap;
justify-content: center;
align-items: stretch;
text-align: center;
width: 20%;
height: 30%;
}
.storeitem:hover{
opacity: 0.5;
}
.productImage{
display: inline-flex;
text-align: center;
align-self: center;
width: 90%;
height: 75%;
}
.productTitle{
display: block;
text-align: center;
}
.productPrice{
display: block;
text-align: center;
}
<div class="storeItems"> <!-- The store item, containing an image, the title of the item and the price.-->
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/book.png"></a>
<div class="productInfo">
<h2 class="productTitle">SEAFRET Book</h1>
<h2 class="productPrice">$14.99</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/bundle.png"></a>
<div class="productInfo">
<h2 class="productTitle">SEAFRET Bundle</h2>
<h2 class="productPrice">$30.00</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/sweater.png"></a>
<div class="productInfo">
<h2 class="productTitle"> SEAFRET Sweater</h2>
<h2 class="productPrice">$15.99</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/totebag.png"></a>
<div class="productInfo">
<h2 class="productTitle"> SEAFRET Totebag</h2>
<h2 class="productPrice">$15.99</h2>
</div>
</div>
</div>
首先,我非常清楚我的代码读起来有多糟糕,对此我感到非常抱歉,我对 HTML 或 CSS 的编码标准一点也不熟悉。我也知道我的大部分 CSS 很可能是多余的,因为我使用的是 flexbox,但我不知道哪些部分有用,哪些部分没用,我不想再次破坏它,所以现在我要离开它。
正如你所看到的,中间的两块瓷砖没有外面的两块那么长,那么我该如何让中间的两块更高一些呢?设计需要具有响应性,以便可以调整大小,所以我很确定它不像仅仅增加高度那么简单。
解决方案
您需要做的就是从商店项目类中删除宽度和高度——这就是缩小它的原因。
此外,您可能想考虑在此应用程序中使用 CSS Grid – 如果您想知道如何做,请告诉我!
.storeItems{
display: inline-flex;
padding-top: 5%;
justify-content: space-evenly;
margin-left: 10%;
margin-right: 10%;
align-items: stretch;
padding-left: 2%;
padding-right: 2%;
}
.storeitem{
padding-top: 1%;
border-radius: 10px;
background-color:#c1d8ee;
display: inline-flex;
flex-flow: row wrap;
justify-content: center;
align-items: stretch;
text-align: center;
margin: 1em;
padding: 1em;
}
.storeitem:hover{
opacity: 0.5;
}
.productImage{
display: inline-flex;
text-align: center;
align-self: center;
width: 90%;
height: 75%;
}
.productTitle{
display: block;
text-align: center;
}
.productPrice{
display: block;
text-align: center;
}
<div class="storeItems"> <!-- The store item, containing an image, the title of the item and the price.-->
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/book.png"></a>
<div class="productInfo">
<h2 class="productTitle">SEAFRET Book</h1>
<h2 class="productPrice">$14.99</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/bundle.png"></a>
<div class="productInfo">
<h2 class="productTitle">SEAFRET Bundle</h2>
<h2 class="productPrice">$30.00</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/sweater.png"></a>
<div class="productInfo">
<h2 class="productTitle"> SEAFRET Sweater</h2>
<h2 class="productPrice">$15.99</h2>
</div>
</div>
<div class="storeitem">
<a class="product" href="productPage.html"><img class="productImage" src="img/totebag.png"></a>
<div class="productInfo">
<h2 class="productTitle"> SEAFRET Totebag</h2>
<h2 class="productPrice">$15.99</h2>
</div>
</div>
</div>
推荐阅读
- python - 从不以图像扩展名结尾的 URL 保存图像
- json - 在 dart 中使用嵌套哈希映射时,如何跟踪一系列键以获取当前嵌套映射?
- plot - 在 glmtree 中表示 20 多个级别
- javascript - 获取图像中选定区域的平均颜色
- python - 如何在 Python 中使用 numpy for 循环手动计算相关系数?
- swift - 带有自定义数据的 Firebase 推送通知不会在 iOS 中正确显示
- swiftui - 按钮不会显示禁用的样式
- vba - 如何使用 Selenium 和 VBA 识别包含特殊字符的元素类名
- xml - powershell,xml,如何区分和元素
- kubernetes - 我们可以通过 Kiali 在代理后面使用 Istio 跟踪外部 API 调用吗?