css3優雅的實現優惠券/促銷標籤樣式

優惠券樣式

在這裏插入圖片描述

實現的代碼

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      body {
        background: #e5e5e5;
      }
      .tag,
      .tag-l,
      .tag-r {
        display: inline-block;
      }
      .tag {
        position: relative;
        margin: 50px;
      }
      .tag-l {
        position: absolute;
        top: 11px;
        left: 11px;
        width: 0px;
        height: 0px;
        border-top: 20px solid #ba3030;
        border-right: 10px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 10px solid transparent;
        transform: rotateZ(-140deg);
      }
      .tag-r {
        font-size: 24px;
        line-height: 40px;
        color: #fff;
        background: #dc2f2f;
        position: relative;
        width: auto;
        height: 40px;
        margin: 0 20px;
        padding: 0 10px;
      }
      .tag-r::before {
        content: "";
        position: absolute;
        right: 100%;
        width: 0px;
        height: 0px;
        border-top: 20px solid transparent;
        border-right: 10px solid #dc2f2f;
        border-bottom: 20px solid #dc2f2f;
        border-left: 10px solid transparent;
      }
      .tag-r::after {
        content: "";
        position: absolute;
        left: 100%;
        width: 0;
        height: 0;
        border-top: 20px solid #dc2f2f;
        border-right: 15px solid transparent;
        border-bottom: 20px solid #dc2f2f;
      }
    </style>
  </head>
  <body>
    <span class="tag">
      <span class="tag-l"></span>
      <span class="tag-r">ALL NEW ITEMS</span>
    </span>
  </body>
</html>

完整效果

在這裏插入圖片描述
在這裏插入圖片描述

附帶講解的樣式(圓角的實現)

在這裏插入圖片描述

實現的代碼

<div class="radius"></div>
.radius {
  height: 50px;
  width: 200px;
  background: #dc2f2f;
  overflow: hidden;
  position: relative;
  margin: 50px;
}
/* 注意細節:僞類的背景色應該與要使用此紅色標籤的父元素背景色保持一致,不然看起來效果很突兀 ,如上圖的淺灰色背景*/
.radius::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e5e5e5;
  left: -10px;
  bottom: -10px;
}
.radius::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e5e5e5;
  right: -10px;
  bottom: -10px;
}

圓角具體應用

在這裏插入圖片描述

圓角具體應用的完整代碼

上面這張優惠券的css實現代碼在下載文件中,感興趣的自行下載!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章