css 梯形,平行四边形布局

思路:
通过伪元素形成三角形进行定位,通过margin控制间距


<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Documenttitle>
  <style>
    .container {
      display: flex;
      margin-bottom: 40px;
    }
    .box {
      width: 150px;
      height: 100px;
      background-color: rgb(120, 228, 213);
      position: relative;
      margin-right: 30px;
    }
    .begin::after {
      content: '';
      position: absolute;
      right: -25px;
      top: 0;
      width: 0;
      height: 0;
      border-left: 25px solid rgb(120, 228, 213);
      border-bottom: 100px solid transparent;
      border-right: 0px solid transparent;
      border-top: 0px solid transparent;
      
    }
    .item::after {
      content: '';
      position: absolute;
      left: -25px;
      top: 0;
      width: 0;
      height: 0;
      border-left: 0px solid transparent;
      border-bottom: 0px solid transparent;
      border-right: 25px solid rgb(120, 228, 213);
      border-top: 100px solid transparent;
    }
    .item::before {
      content: '';
      position: absolute;
      right: -25px;
      top: 0;
      width: 0;
      height: 0;
      border-left: 25px solid rgb(120, 228, 213);
      border-bottom: 100px solid transparent;
      border-right: 0px solid transparent;
      border-top: 0px solid transparent;
    }
    .end::after {
      content: '';
      position: absolute;
      left: -25px;
      top: 0;
      width: 0;
      height: 0;
      border-left: 0px solid transparent;
      border-bottom: 0px solid transparent;
      border-right: 25px solid rgb(120, 228, 213);
      border-top: 100px solid transparent;
    }
  
  style>
head>
<body>
 <div class="container">
  <div class="begin box">div>
  <div class="item box">div>
  <div class="end box">div>
 div>

body>
html>

最终效果:
css 梯形,平行四边形布局_第1张图片

你可能感兴趣的:(ccs使用技巧,css)