不规则形状(缎带形状)

HTML:

<div class="ribbon">
  <div class="body">Pure CSS Ribbon</div>
  <div class="blocks">
    <div class="block"></div>
    <div class="block"></div>
    <div class="block"></div>
    <div class="block"></div>
  </div>
</div>

CSS:

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  background: hsl(240, 56%, 98%);
}

:root {
  --yellow-color-1: #f9bb00;
  --yellow-color-2: #ef7e06;
  --yellow-color-3: #f7ac00;
}

.ribbon {
  --ribbon-color-1: var(--yellow-color-1);
  --ribbon-color-2: var(--yellow-color-2);
  --ribbon-color-3: var(--yellow-color-3);

  position: relative;

  .body {
    padding: 0.5rem 1rem;
    color: white;
    white-space: nowrap;
    background: var(--ribbon-color-1);
  }

  .block {
    &:nth-child(1),
    &:nth-child(2) {
      position: absolute;
      z-index: 1;
      bottom: -20%;
      width: 2rem;
      height: 20%;
      background: var(--ribbon-color-2);
      clip-path: polygon(0 0, 100% 100%, 100% 0);
    }

    &:nth-child(1) {
      left: 0;
    }

    &:nth-child(2) {
      right: 0;
      transform: scaleX(-1);
    }

    &:nth-child(3),
    &:nth-child(4) {
      position: absolute;
      z-index: -1;
      top: 20%;
      width: 4rem;
      height: 100%;
      background: var(--ribbon-color-3);
      clip-path: polygon(0 0, 25% 50%, 0 100%, 100% 100%, 100% 0);
    }

    &:nth-child(3) {
      left: -2rem;
    }

    &:nth-child(4) {
      right: -2rem;
      transform: scaleX(-1);
    }
  }
}
© 版权声明
THE END
喜欢就支持以下吧
点赞21赞赏 分享
吐槽 抢沙发

请登录后发表评论