产品卡看起来总是向左对齐,但它应该以有序的方式正确对齐,使它看起来更好。
我尝试使用Flex属性,但项目随后以垂直方式对齐,这使它非常不舒服。
有没有一种方法可以把这三个东西都有序地展示出来?
这是enter image description here目前的外观
下面是使用的html和css代码片段:
.product-container
{
padding-right:10vw;
display: inline-block;
overflow-x: auto;
scroll-behavior: smooth;
}
.product-container::-webkit-scrollbar{
display: none;
}
.products{
padding: 0 10vw;
}
.product-card{
flex: 0 0 auto;
width: 196px;
height: 600px;
margin-right: 40px;
}
.product-image{
position: relative;
width: 196px;
height: 350px;
overflow: hidden;
}
.product-thumb{
width:196px;
height:350px;
object-fit: cover;
}
<section class="products">
<div class="product-container">
<div class="product-card">
<div class="product-image">
<img src="images/card2.jpg" alt="" class="product-thumb" height="350px" width="220px">
<button class="addtocartbtn"> Add To Cart </button>
</div>
<div class="shoe-specs">
<span class="disprice">$59</span><span class="orgprice">$99</span>
<h2 class="brand">Adidas</h2>
<p class="spec">Running Shoes</p>
</div>
</div>
</div>
<div class="product-container">
<div class="product-card">
<div class="product-image">
<img src="images/card4.jpg" alt="" class="product-thumb" height="350px" width="220px">
<button class="addtocartbtn"> Add To Cart </button>
</div>
<div class="shoe-specs">
<span class="disprice">$69</span><span class="orgprice">$129</span>
<h2 class="brand">Reebok</h2>
<p class="spec">Running Shoes</p>
</div>
</div>
</div>
<div class="product-container">
<div class="product-card">
<div class="product-image">
<img src="images/card5.jpg" alt="" class="product-thumb" height="350px" width="220px">
<button class="addtocartbtn"> Add To Cart </button>
</div>
<div class="shoe-specs">
<span class="disprice">$89</span><span class="orgprice">$149</span>
<h2 class="brand">Nike</h2>
<p class="spec">Running Shoes</p>
</div>
</div>
</div>
2条答案
按热度按时间jogvjijk1#
现在,您可以在
products
类上使用display: flex
。imzjd6km2#
从以下位置移除衬垫:
然后在产品中应用CSS