Kros的博客 Kros的博客
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云

Kros

凡心所向,素履以往,生如逆旅,一苇以航
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云
  • CSS

    • CSS绘制三角形
    • CSS排版上下文
    • CSS伪类
    • CSS伪元素
    • CSS实现列表元素分割线
    • CSS使用skew
    • CSS让物体居中
    • CSS绘制太极图
    • CSS使用实体替代预留符号
    • 动态修改after或before的content
    • CSS旋转border
    • CSS绘制空心五角星
    • CSS时钟
    • CSS图片手风琴伸缩效果
    • CSS的选择器
    • CSS波浪border
    • CSS内切圆角
    • CSS文字环绕
    • CSS outline使用详解
    • CSS使用transform缩放scale不生效
    • CSS使用linear-gradient或生成虚线
    • CSS 图片srcset属性
    • CSS object-fit属性详解
    • CSS 使用filter对颜色就行处理
    • CSS选择器的优先级
    • css与scss文件引入问题
    • CSS实现圆角梯形
    • 使用filter实现聚光灯效果
    • 利用backface-visibility hidden实现3d翻转双面card
    • 正方体3d旋转
    • 修改浏览器自动填充的背景颜色
    • CSS修改选中文字颜色
    • CSS实现打字机效果
    • marquee文字弹跳
    • logo文字图片倒影
    • 纯CSS实现popup弹窗
    • ie兼容inline-block
    • 浏览器默认样式
    • CSS效果-文字
    • CSS效果-按钮
    • css3 transition属性对linear-gradient渐变色无效
    • 不同预处理器下的样式穿透
    • 属性顺序
    • CSS重绘与回流
    • img标签与before和after
    • CSS实现文本两端对齐
    • CSS filter的contrast属性和blur属性奇特的结合
    • CSS不常用属性记录
    • CSS sprite雪碧图制作与使用
  • JavaScript

  • 工具

  • Vue

  • antdv踩坑记录

  • Vue3

  • 前端
  • CSS
kros
2021-02-24

CSS旋转border

最近实现一个border围绕内容旋转的动画,效果如下:

border

实现原理比较简单,借助于css的clip-path属性,它的作用是裁剪元素形成新的可视化区域。详细请看官方文档 首先构建border和内容区域,border需借助after和before属性避免内容被剪切,后使用clip-path裁剪after和before,最后把各个方向裁剪部分做成动画即可。

c1 c2

实现代码如下:

<template>
	<div class="page">
		<div class="box">
			<div class="content"></div>
		</div>
	</div>
</template>

<script>
</script>

<style scoped lang="scss">
	.page {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100vw;
		height: 100vh;
		.box {
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 200px;
			height: 200px;
			background: transparent;
			
			&::after {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				border: 5px solid #00FF00;
				box-sizing: border-box;
				clip-path: inset(0 0 195px 0);
				animation: clipBoderTop 5s linear infinite;
			}
			&::before {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				border: 5px solid #00FF00;
				box-sizing: border-box;
				clip-path: inset(0 0 195px 0);
				animation: clipBoderBottom 5s linear infinite;
			}
			.content {
				left: 5px;
				top: 5px;
				width: 180px;
				height: 180px;
				background: #000FFF;
			}
		}
		
	}	
	
	@keyframes clipBoderTop {
		from {
			clip-path: inset(0 0 195px 0);
		}
		25% {
			clip-path: inset(0 0 0 195px);
		}
		50% {
			clip-path: inset(195px 0 0 0);
		}
		75% {
			clip-path: inset(0 195px 0 0);
		}
		to {
			clip-path: inset(0 0 195px 0);
		}
	}
	
	@keyframes clipBoderBottom {
		from {
			clip-path: inset(195px 0 0 0);
		}
		25% {
			
			clip-path: inset(0 195px 0 0);
		}
		50% {
			clip-path: inset(0 0 195px 0);
		}
		75% {
			clip-path: inset(0 0 0 195px);
		}
		to {
			clip-path: inset(198px 0 0 0);
		}
	}
</style>

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
上次更新: 2025/09/05, 8:09:00
动态修改after或before的content
CSS绘制空心五角星

← 动态修改after或before的content CSS绘制空心五角星→

最近更新
01
Find the next perfect square
09-05
02
Regex validate PIN code
09-05
03
Find the odd int
09-05
更多文章>
Theme by Vdoing | Copyright © 2020-2025 kros king
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
icon-heart-o icon-heart icon-infinity icon-pause icon-play link next prev