css容器查询自适应卡片效果代码
代码语言:html
所属分类:响应式
代码描述:css容器查询自适应卡片效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link href="https://fonts.googleapis.com/css2?family=Barlow:wght@200;300&display=swap" rel="stylesheet"> <style> * { box-sizing: border-box; margin: 0; padding: 0; } h1, h2, h3, h4, p { margin-block-start: 0; margin-block-end: 0; } body { font-family: "Barlow", sans-serif; } .cards { display: grid; grid-template-columns: repeat(2, 1fr); grid-template-rows: auto; gap: 2rem 1rem; max-width: 100%; margin: 2rem auto; padding-left: 0.5rem; padding-right: 0.5rem; } .card-layout { contain: layout inline-size style; overflow: auto; } .card-layout:nth-of-type(3) { grid-column: 1/-1; } .card { display: flex; flex-direction: column; flex-wrap: wrap; gap: 0.5rem 1rem; } .card__thumb { width: 100%; } .card__thumb img { width: 100%; display: block; } .card__content { width: 100%; } .card__title { font-weight: 300; font-size: 1.5rem; margin-bottom: 0.5rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } .card__desc { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; } @container (min-width: 300px) { .card__title { -webkit-line-clamp: 3; } } @container (min-width: 575px) { .card { flex-direction: row; } .card__thumb { width: 30%; } .card__content { width: 60%; } .card__desc { -webkit-line-clamp: 5; } } @container (min-width: 800px) { .card { display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr; gap: 0; place-items: center; text-align: center; color: #fff; } .card__thumb { grid-area: 1/1/2/2; width: 100%; height: 100%; } .card__content { grid-area: 1/1/2/2; max-width: 80%; padding: 5% 8%; background-color: rgba(0, 0, 0, 0.9); } .card__title { font-weight: 300; font-size: 1.5rem; margin-bottom: 0.5rem; } } </style> </head> <body translate="no" > <div class="cards" id="container"> <div class="card-layout"> <div class="card"> <div class="card__thumb"> <img src="https://dummyimage.com/600x400/1bc/fff" alt=""> </div> <div class="card__content"> <h1 class="card__title">Lorem ipsum dolor sit amet.</h1> <p class="card__desc"> Lorem ipsum dolor sit amet consectetur, adipisicing elit. Deserunt dolor minus iste necessitatibus! Voluptatem, quo, magni quod labore veniam et possimus est architecto voluptatibus assumenda amet nobis aut facilis molestiae in. Eligendi consectetur magni veniam. Debitis a, blanditiis repellendus iusto ea deleniti, beatae nostrum illum quibusdam unde delectus. Provident nostrum quae harum ullam ipsam distinctio et natus nulla magnam sint. </p> </div> </div> </div> <div class="card-layout"> <div class="card"> <div class="card__thumb"> <img src="https://dummyimage.com/600x400/0b0/fff" alt=""> </div> <div class="card__content"> <h1 class="card__title">Lorem ipsum dolor sit amet.</h1> <p class="card__desc"> Lorem ipsum dolor sit amet consectetur, adipisicing elit. Deserunt dolor minus iste necessitatibus! Voluptatem, quo, magni quod labore veniam et possimus est architecto voluptatibus assumenda amet nobis aut facilis molestiae in. Eligendi consectetur magni veniam. Debitis a, blanditiis repellendus iusto ea deleniti, beatae nostrum illum quibusdam unde delectus. Provident nostrum quae harum ullam ipsam distinctio et natus nulla magnam sint. </p> </div> </div> </div> <div class="card-layout"> <div class="card"> <div class="card__thumb"> <img src="https://dummyimage.com/600x400/a00/fff" alt=""> </div> <div class="card__content"> <h1 class=&q.........完整代码请登录后点击上方下载按钮下载查看
网友评论0