自适应分层商品列表效果

代码语言:html

所属分类:布局界面

代码描述:自适应分层商品列表效果

代码标签: 商品 列表 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="http://repo.bfw.wiki/bfwrepo/css/reset.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Abel&display=swap');

:root {
  --columns: 1;
}

body {
  color: #56626B;
  background-color: #edf9f9;
  font-family: 'Abel', sans-serif;
  font-size: calc(4.3vw/(var(--columns)));
}

h1{
  font-size: 30px;
  text-align: center;
  margin: 4vw;
}

ul{
  display:grid;
  grid-template-columns: repeat(var(--columns),1fr);
}

li{
  position: relative;
  padding-bottom: 50%;
  margin-top: 25%;
}

li::before, li::after {
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  content: '';
}


li::before {
  top: 50%;
}
li::after {
  top: 100%;
}

img{
  position: absolute;
  height: calc(115vw/(var(--columns)));
  left: 30%;
  top: 80%;
  transform: translateX(-50%) translateY(-50%);
  -webkit-filter: drop-shadow(2px -2px 5px  rgba(0, 0, 0, 0.3));
  filter: drop-shadow(2px -2px 5px  rgba(0, 0, 0, 0.3));
}

div{
  position: absolute;
  background: #f2f4f3;
  padding: 3% 2%;
  border: #8fa0A9 solid 1px;
  border-radius: 8%;
  width: 30%;
  height: 70%;
  left: 60%;
  top: 50%;
  transform: translateX(-50%);
  -webkit-filter: drop-shadow(2px -2px 5px  rgba(0, 0, 0, 0.3));
  filter: drop-shadow(2px -2px 5px  rgba(0, 0, 0, 0.3));
}

p{
  position: absolute;
  font-size: 1.6em;
  top:42%;
  right: 8%
}

li:nth-child(2n) img{
  left: 70%;
}
li:nth-child(2n) div{
  left: 40%;
}
.filler{
  display:none;
}

.bottom{
  grid-column: 1/-1;
  background-size: calc(100%/(var(--columns)));
  background-repeat: repeat-x;
  padding-bottom:  calc(25%/(var(--columns)));
  margin-top:   calc(25%/(var(--columns)));
}
.bottom:before,.bottom:after {
  content: none;
}

@media (min-width:600px){
  :root {
    --columns: 2;
  }
  h1{
    font-size: 40px;
  }
  li:nth-child(n) img{
    left: 30%;
  }
  li:nth-child(n) div{
    left: 60%;
  }
  li:nth-child(4n-1) img,li:nth-child(4n) img{
    left: 70%;
  }
  li:nth-child(4n-1) div,li:nth-child(4n) div{
    left: 40%;
  }
}
@media (min-width:900px){
  :root {
    --columns: 3;
  }
  li:nth-child(n) img{
    left: 30%;
  }
  li:nth-child(n) div{
    left: 60%;
  }
  li:nth-child(6n-2) img,li:nth-child(6n-1) img,li:nth-child(6n) img{
    left: 70%;
  }
  li:nth-child(6n-2) div,li:nth-child(6n-1) div,li:nth-child(6n) div{
    left: 40%;
  }
}
@media (min-width:1200px){
  :root {
    --columns: 4;
  }
  li:nth-child(n) img{
    left: 30%;
  }
  li:nth-child(n) div{
    left: 60%;
  }
  li:nth-child(8n-3) img,li:nth-child(8n-2) img,li:nth-child(8n-1) img,li:nth-child(8n) img{
    left: 70%;
  }
  li:nth-child(8n-3) div,li:nth-child(8n-2) div,li:nth-child(8n-1) div,li:nth-child(8n) div{
    left: 40%;
  }
}
@media (min-width:1500px){
  :root {
    --columns: 5;
  }
  li:nth-child(n) img{
    left: 30%;
  }
  li:nth-child(n) div{
    left: 60%;
  }
  li:nth-child(10n-4) img,li:nth-child(10n-3) img,li:nth-child(10n-2) img,li:nth-child(10n-1) img,li:nth-child(10n) img{
    left: 70%;
  }
  li:nth-child(10n-4) div,li:nth-child(10n-3) div,li:nth-child(10n-2) div,li:nth-child(10n-1) div,li:nth-child(10n) div{
    left: 40%;
  }
  .filler{
    display:block;
  }
}
@media (min-width:1800px){
  :root {
    --columns: 6;
  }
  li:nth-child(n) img{
    left: 30%;
  }
  li:nth-child(n) div{
    left: 60%;
  }
  li:nth-child(12n-5) img,li:nth-child(12n-4) img,li:nth-child(12n-3) img,li:nth-child(12n-2) img,li:nth-child(12n-1) img,li:nth-child(12n) img{
    left: 70%;
  }
  li:nth-child(12n-5) div,li:nth-child(12n-4) div,li:nth-child(12n-3) div,li:nth-child(12n-2) div,li:nth-child(12n-1) div,li:nth-child(12n) div{
    left: 40%;
  }
  .filler{
    display:none;
  }
}

li, li::before, li::after {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 640 243' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='1.5'%3E%3Cpath fill='none' d='M0 0h640v242.833H0z'/%3E%3CclipPath id='a'%3E%3Cpath d='M0 0h640v242.833H0z'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23a)'%3E%3Cpath fill='none' d='M0-20h640v262.833H0z'/%3E%3CclipPath id='b'%3E%3Cpath d='M0-20h640v262.833H0z'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23b)' fill='%23f2f4f3' stroke='%238fa0a9'%3E%3Cpath d='M79.482 80.741s-28.484-67.76-28.145-67.923c-3.759-9.037 17.221-14.96 18.54-4.959l.002.003c.089-.236 9.603 72.879 9.603 72.879zM79.482 80.741s28.483 67.76 28.144 67.922c3.76 9.037-17.221 14.96-18.54 4.959l-.002-.002c-.089.236-9.602-72.879-9.602-72.879z'/%3E%3Cpath d='M79.482 80.741S69.506 7.918 69.876 7.848c-1.293-9.702 20.506-9.993 19.192.009-.001.001.001.002.001.003.146-.205-9.587 72.881-9.587 72.881z'/%3E%3Cpath d='M79.482 80.741s9.975 72.823 9.605 72.892c1.293 9.702-20.506 9.993-19.191-.008l-.002-.003c-.146.205 9.588-72.881 9.588-72.881z'/%3E%3Cpath d='M79.482 80.741s9.212-72.923 9.587-72.895c1.263-9.706 22.394-4.345 18.536 4.975v.004c.195-.161-28.123 67.916-28.123 67.916zM79.482 80.741s-9.213 72.923-9.588 72.895c-1.263 9.706-22.394 4.345-18.536-4.976v-.003c-.195.16 28.124-67.916 28.124-67.916z'/%3E%3Cpath d='M79.482 80.741s27.772-68.054 28.127-67.93c3.732-9.048 22.755 1.599 16.616 9.603v.004c.229-.105-44.743 58.323-44.743 58.323zM79.482 80.741s-27.773 68.054-28.128 67.929c-3.732 9.049-22.755-1.598-16.616-9.603v-.003c-.229.104 44.744-58.323 44.744-58.323z'/%3E%3Cpath d='M79.482 80.741s44.44-58.547 44.75-58.335c5.946-7.775 21.566 7.434 13.565 13.576l-.002.004c.249-.042-58.313 44.755-58.313 44.755z'/%3E%3Cpath d='M79.482 80.741s-44.441 58.547-44.751 58.335c-5.946 7.774-21.566-7.434-13.565-13.577l.002-.003c-.249.042 58.314-44.755 58.314-44.755zM79.482 80.741s58.078-45.05 58.323-44.765c7.756-5.971 18.908 12.762 9.589 16.624l-.002.003c.251.024-67.91 28.138-67.91 28.1.........完整代码请登录后点击上方下载按钮下载查看

网友评论0