自适应分层商品列表效果

代码语言: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{
    le.........完整代码请登录后点击上方下载按钮下载查看

网友评论0