太极图HTML+CSS(可旋转)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>太极旋转图</title>
		<style type="text/css">
			body{
				margin: 0px;
				padding: 0px;
			}
			.wrap{
				width: 200px;
				height: 100px;
				margin: 50px auto;
				/*border: 2px solid red;*//*边框属性:粗细 样式 颜色*/
				border-width: 1px 1px 100px 1px;
				border-style: solid;
				border-radius: 50%;
				position: relative;
			}
			.left{
				position: absolute;
				top: 50%;
				width: 20px;
				height: 20px;
				background-color: #fff;
				border: 40px solid #000;
				border-radius: 50%;
			}
			.right{
				/*当设置绝对定位时,如果没有参考物(相对定位),
				 * 那么浏览器就是参考物,即.right这个div相对于浏览器的变化*/
				/*相对定位其实就是相对参考物:父相子绝*/
				position: absolute;
				top: 50%;
				/*left: 100px;*/
				right: 0px;
				width: 20px;
				height: 20px;
				background-color: #000;
				border: 40px solid #fff;
				border-radius: 50%;
			}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div class="left"></div>
			<div class="right"></div>
		</div>
	</body>
</html>

第二种方式:
用一个div实现(伪元素),性能更好

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>太极旋转图</title>
		<style type="text/css">
			body{
				margin: 0px;
				padding: 0px;
			}
			.wrap{
				width: 200px;
				height: 100px;
				margin: 50px auto;
				/*border: 2px solid red;*//*边框属性:粗细 样式 颜色*/
				border-width: 1px 1px 100px 1px;
				border-style: solid;
				border-radius: 50%;
				position: relative;
			}
			.wrap:before{
				content: '';/*激活伪元素的必要因素*/
				position: absolute;
				top: 50%;
				width: 20px;
				height: 20px;
				background-color: #fff;
				border: 40px solid #000;
				border-radius: 50%;
			}
			.wrap:after{
				content: '';/*激活伪元素的必要因素*/
				/*当设置绝对定位时,如果没有参考物(相对定位),
				 * 那么浏览器就是参考物,即.right这个div相对于浏览器的变化*/
				/*相对定位其实就是相对参考物:父相子绝*/
				position: absolute;
				top: 50%;
				/*left: 100px;*/
				right: 0px;
				width: 20px;
				height: 20px;
				background-color: #000;
				border: 40px solid #fff;
				border-radius: 50%;
			}
		</style>
	</head>
	<body>
		<div class="wrap"></div>
	</body>
</html>

第二个方法中,再简洁一点:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>太极旋转图</title>
		<style type="text/css">
			body{
				margin: 0px;
				padding: 0px;
			}
			.wrap{
				width: 200px;
				height: 100px;
				margin: 50px auto;
				/*border: 2px solid red;*//*边框属性:粗细 样式 颜色*/
				border-width: 1px 1px 100px 1px;
				border-style: solid;
				border-radius: 50%;
				position: relative;
			}
			.wrap:before,
			.wrap:after{
				content: '';/*激活伪元素的必要因素*/
				position: absolute;
				top: 50%;
				width: 20px;
				height: 20px;
				border-radius: 50%;
			}
			.wrap:before{
				background-color: #fff;
				border: 40px solid #000;
			}
			.wrap:after{
				/*当设置绝对定位时,如果没有参考物(相对定位),
				 * 那么浏览器就是参考物,即.right这个div相对于浏览器的变化*/
				/*相对定位其实就是相对参考物:父相子绝*/
				right: 0px;
				background-color: #000;
				border: 40px solid #fff;
				}
		</style>
	</head>
	<body>
		<div class="wrap"></div>
	</body>
</html>

接下来就需要这个太极旋转起来,这时就需要CSS中的动画属性

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>太极旋转图</title>
		<style type="text/css">
			body{
				margin: 0px;
				padding: 0px;
			}
			.wrap{
				width: 200px;
				height: 100px;
				margin: 50px auto;
				/*border: 2px solid red;*//*边框属性:粗细 样式 颜色*/
				border-width: 1px 1px 100px 1px;
				border-style: solid;
				border-radius: 50%;
				position: relative;
				/*通过属性去调用之前定义好的动画*/
				animation: rote 1s linear infinite;
				/*rote 就是这个动画的名称*/
				/*2s 表示做一次这个动画需要2s时间 决定旋转的快慢*/
				/*linear 表示匀速的旋转*/
				/*infinite 表示永久旋转*/
			}
			.wrap:before,
			.wrap:after{
				content: '';/*激活伪元素的必要因素*/
				position: absolute;
				top: 50%;
				width: 20px;
				height: 20px;
				border-radius: 50%;
			}
			.wrap:before{
				background-color: #fff;
				border: 40px solid #000;
			}
			.wrap:after{
				/*当设置绝对定位时,如果没有参考物(相对定位),
				 * 那么浏览器就是参考物,即.right这个div相对于浏览器的变化*/
				/*相对定位其实就是相对参考物:父相子绝*/
				right: 0px;
				background-color: #000;
				border: 40px solid #fff;
				}
				/*定义CSS动画*/
				@keyframes rote{
					from{
						transform: rotate(0deg);/*旋转*/
					}
					to{
						transform: rotate(360deg);/*旋转*/
					}
				}
		</style>
	</head>
	<body>
		<div class="wrap"></div>
	</body>
</html>
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值