使用Flex布局制作响应式电商商品展示页面 - 简单易懂的教程
<div class='goods-container'>
<div class='goods-item'>
<div class='goods-image'></div>
<div class='goods-info'>
<h3 class='goods-name'>商品名称</h3>
<p class='goods-price'>¥99.99</p>
</div>
</div>
<!-- 其他商品 -->
</div>
<style>
.goods-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 1200px;
margin: 0 auto;
}
.goods-item {
width: calc(25% - 10px);
margin-bottom: 20px;
display: flex;
}
@media screen and (max-width: 1000px) {
.goods-item {
width: calc(33.33% - 10px);
}
}
@media screen and (max-width: 800px) {
.goods-item {
width: calc(50% - 10px);
}
}
@media screen and (max-width: 500px) {
.goods-item {
width: 100%;
}
}
.goods-image {
width: 100%;
padding-top: 100%;
background-color: #f5f5f5;
background-size: cover;
background-position: center;
border-radius: 5px;
}
.goods-info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
margin-left: 10px;
}
.goods-name {
font-size: 18px;
margin: 0;
}
.goods-price {
font-size: 24px;
color: red;
margin: 0;
}
</style>
原文地址: https://www.cveoy.top/t/topic/npbQ 著作权归作者所有。请勿转载和采集!