HTML、CSS制作旋转正方形立体

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Document</title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<style type="text/css">
			.main{
				width: 200px;
				height: 200px;
				perspective: 800px;	/*给最大盒子设置景深,实现近大远小的视觉*/
				margin:200px auto;	/*调整整个盒子位置尽量居中*/
			}
			.box {
				width: 100%;
				height: 100%;
				transform-style: preserve-3d;
				/* 将盒子变成3d舞台 */
				position: relative;
				animation: run 6s linear infinite;
				/* 使用关键帧动画 ,一直动 */
				
			}

			.box>div {
				width: 200px;
				height:200px;
				text-align: center;
				line-height: 200px;
				/* 行高等于盒子高度,文字垂直居中 */
				font-size: 50px;
				opacity: 0.5;
				/* 透明度 */
				position: absolute;		/*父盒子相对定位,子盒子绝对定位*/
			}

			/*结构性伪类选择器 选择元素*/
			.box>div:nth-child(1) {
				/* 调整上面位置 */
				background: lightcoral;
				transform: translateY(-100px) rotateX(90deg);
			}

			.box>div:nth-child(2) {
				/* 调整左面位置及设置颜色 */
				background: lightcyan;	
				transform: translateX(-100px) rotateY(-90deg); 
			}

			.box>div:nth-child(3) {
				/* 背面 */
				background: lightgray;
				transform:translateZ(-100px) ;
			}

			.box>div:nth-child(4) {
				/* 右面 */
				background: lightsalmon;
				transform: translateX(100px) rotateY(90deg);
			}

			.box>div:nth-child(5) {
				/* 底面 */
				background: lightgoldenrodyellow;
				transform: translateY(100px) rotateX(-90deg);
			}

			.box>div:nth-child(6) {
				/* 调整正面位置及设置颜色 */
				background: lime;
				transform: translateZ(100px);
			}

			.box:hover {
				/* 鼠标悬停在盒子时,停止运动*/
				animation-play-state: paused;
			}

			/*创建关键帧动画*/
			@keyframes run {
				from {
					transform: rotate3d(0);	
				}
				to {
					transform: rotateX(360deg) rotateY(360deg);
				}
			}
		</style>
		<script>

		</script>
	</head>
	<body>
		<div class="main">
			<div class="box">
				<div>
					上面
				</div>
				<div>
					左面
				</div>
				<div>
					背面
				</div>
				<div>
					右面
				</div>
				<div>
					底面
				</div>
				<div>
					正面
				</div>
			</div>
		</div>
	</body>
</html>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值