用css做一个小立方体

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		#box{
			width: 100px;
			height: 100px;
			padding: 100px;
			border: 1px solid red;
			margin: 100px auto;
			perspective: 300px;  
		}
		#val{
			width: 100px;
			height: 100px;
			position: relative;
			transition: 3s;
			transform-style: preserve-3d;

			transform-origin: center center -50px;
		}
		#val div{
			
			position: absolute;
			width: 100px;
			height: 100px;
			background: red;
			text-align: center;
			font: 60px/100px "simhei"
		}




		#val div:nth-of-type(1){
			top: -100px;

			transform: rotateX(90deg);
			transform-origin: bottom;
		}
		#val div:nth-of-type(2){
			left: -100px;

			transform: rotateY(-90deg);
			transform-origin: right;
		}
		#val div:nth-of-type(3){
			/*top: -100px;*/
			background: yellow;
		}
		#val div:nth-of-type(4){
			left: 100px;

			transform: rotateY(90deg);
			transform-origin: left;
		}
		#val div:nth-of-type(5){
			top: 100px;

			transform: rotateX(-90deg);
			transform-origin: top;
		}
		#val div:nth-of-type(6){
			/*top: -100px;*/
			background: blue;
			transform: translateZ(-100px) rotateY(180deg);
		}

		#box:hover #val{
			transform: rotateY(380deg) rotateX(530deg);
		}

	</style>
</head>
<body>
	<div id="box">
		<div id="val">
			<div>1</div>
			<div>2</div>
			<div>3</div>
			<div>4</div>
			<div>5</div>
			<div>6</div>
		</div>
		
	</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/q970654226/article/details/80262337