思路1 利用css三角
思路是用两个css三角一大一小,小的压住大的丝带就出来了,然后文字逆时针旋转45度就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>css丝带</title> </head> <style>
.main { position: relative; width: 100px; height: 50px; margin: 100px auto 100px; box-shadow: 1px 1px 30px #ccc; }
.bigTriangle { height: 0; width: 0; border-top: 50px solid rgb(52, 139, 238); border-right: 50px solid rgb(52, 139, 238); border-bottom: 50px solid transparent; border-right: 50px solid transparent; }
.smallTriangle { position: absolute; top: 0; left: 0; height: 0; width: 0; border-top: 25px solid #fff; border-right: 25px solid #fff; border-bottom: 25px solid transparent; border-right: 25px solid transparent; }
.title { position: absolute; top: 8px; left: -1px; transform: rotateZ(-45deg); width: 42px; color: #fff; font-size: 12px; } </style>
<body>
<div class="main"> <div class="bigTriangle"> <div class="smallTriangle"></div> <span class="title">进行中</span> </div> </div>
</body>
</html>
|
效果如下
思路二 直接div旋转
直接把一个div旋转 然后overflow: hidden;就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>css丝带</title> </head> <style> .main-2 { position: relative; margin: 0 auto; height: 200px; width: 500px; overflow: hidden; box-shadow: 1px 1px 30px #ccc; }
.triangle { position: absolute; top: 4.6em; left: -3.4em; width: 18em; height: 2em; overflow: hidden; background-color: #dc3545; box-sizing: content-box; line-height: 2em; color: #fff; font-size: 1em; text-align: center; text-decoration: none; font-weight: bold; transform: rotate(-45deg); } </style>
<body>
<div class="main-2"> <div class="triangle">css丝带</div> </div>
</body>
</html>
|