我的第一个博客

通过CSS制作一个3d的立方体

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CSS3制作3D立方体</title>
<style>
* {
	margin: 0;
	padding: 0;
}

body {
	width:500px;
	height:500px;
	perspective: 1500px;
	margin: 200px auto;
	border:1px solid pink;
}

.warp {
	width: 500px;
	height: 500px;
	margin: 100px auto;	
	position: relative;
	transform-style: preserve-3d;
	transform: rotateX(45deg) rotateY(45deg);
	height: 200px;
	border: 2px solid #ccc;
	text-align: center;
	animation: play 5s linear infinite;
}

.box {
	width: 200px;
	line-height: 200px;
	font-size: 150px;
	font-weight: bold;
	color: #fff;
	position: absolute;
	top: 150px;
	left: 150px;
}

.box1 {
	background: rgba(135,135,135,.3);
	transform: rotateY(90deg) translateZ(100px);
}

.box2 {
	background: rgba(135,0,255,.3);
	transform: rotateY(90deg) translateZ(-100px);
}

.box3 {
	background: rgba(255,125,125,.3);
	transform: rotateX(90deg) translateZ(-100px);
}

.box4 {
	background: rgba(125,255,125,.3);
	transform: rotateX(90deg) translateZ(100px);
}

.box5 {
	background: rgba(30,150,189,.3);
	transform: translateZ(100px);
}

.box6 {
	background: rgba(169,150,189,.3);
	transform: translateZ(-100px);
}

@keyframes play {
	from{ transform: rotateX(0) rotateY(0) rotateZ(0);}
	to {transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg);}
}
</style>
</head>
<body>
<div class="warp">
	<div class="box box1">1</div>
    <div class="box box2">2</div>
    <div class="box box3">3</div>
    <div class="box box4">4</div>
    <div class="box box5">5</div>
    <div class="box box6">6</div>
</div>
<script>
</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值