<div class='container'>
  <div class='item'>
    <div class='img'></div>
    <div class='info'>
      <h3 class='name'>商品名称</h3>
      <p class='price'>¥99.99</p>
    </div>
  </div>
  <!-- 其他9个商品信息 -->
</div>
<style>
.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
}

.item {
  width: 23%;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  overflow: hidden;
}

@media (max-width: 1000px) {
  .item {
    width: 31%;
  }
}

@media (max-width: 800px) {
  .item {
    width: 48%;
  }
}

@media (max-width: 500px) {
  .item {
    width: 100%;
  }
}

.img {
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  background-image: url('商品图片地址');
  background-size: cover;
  border-radius: 5px 0 0 5px;
}

.info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-grow: 1;
}

.name {
  margin: 0;
}

.price {
  margin: 0;
  font-size: 1.2em;
  color: red;
}
</style>
Flex 布局实现响应式电商商品展示页面 - 优化用户体验

原文地址: https://www.cveoy.top/t/topic/jFdV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录