例如圆形头像,鼠标移入时以圆形从圆心向外逐渐变亮
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
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> /* 头像容器 */ .avatar { width: 200px; height: 200px; margin: 200px auto; background-image: url(https://image.cheriko.fun/post/202306042214538.jpg); background-size: cover; background-position: center; border-radius: 50%; cursor: pointer; position: relative; }
.avatar::before, .avatar::after { content: ''; position: absolute; width: 100%; height: 100%; left: 0; top: 0; border-radius: 50%; }
.avatar::before { background-color: rgba(0,0,0,.5); }
.avatar::after { /* 获取父元素(这里是.avatar)的background */ background: inherit; /* 裁剪元素 */ clip-path: circle(0%); transition: 0.3s; }
.avatar:hover::after { clip-path: circle(50%);
} </style>
<body> <div class="avatar"> </div> </body>
</html>
|
clip-path还可以裁剪出更多别的形状