优惠券样式
实现的代码
<!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实现代码在下载文件中,感兴趣的自行下载!