效果图:
html
<div className={styles.father_box_two}> <div className={styles.box_two}>内容内容</div> </div>
css
::after{} 和 ::before{} 两个伪类,分别实现了一种环绕效果,这里是将他俩结合在一起之后的效果,任何一个单独使用都是可以的。
::after{} 实现的是矩形围绕,但是没有渐变的感觉
::before{} 实现了渐变的效果,但是会有一个切角,不美观
.father_box_two{ width: 100px; height: 100px; line-height: 100px; // border-radius: 10%; overflow: hidden; position: relative; background-color: rgba(0,0,0,.06); .box_two{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-origin: center center; // 一中心未基点 transform: scale(0.95); // 缩小到原来的 95% // border-radius: 10%; background-color: #ffffff; z-index: 1; } &::after{ content: ""; position: absolute; display: inline-block; background-color: #1a73e8; top: 0; left: 0; width: 100px; height: 5px; animation: bgmove 5s linear infinite; @keyframes bgmove { 0% { top: 0; left: 0; width: 100px; height: 5px; } 25% { top: 0; left: 0; width: 5px; height: 100px; } 50% { top: 95px; left: 0; width: 100px; height: 5px; } 75% { top: 0px; left: 95px; width: 5px; height: 100px; } 100% { top: 0; left: 0; width: 100px; height: 5px; } } } &::before{ content: ""; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; transform-origin: center center; transform: rotate(45deg) scale(2); background: conic-gradient( #1a73e8, rgba(0,0,0,.06), rgba(0,0,0,.06), rgba(0,0,0,.06) ); animation: rotate 5s linear infinite; @keyframes rotate { 100% { transform: rotate(-315deg) scale(2); } } } }
原文:https://www.cnblogs.com/MrZhujl/p/13628523.html