8.1、3D变换之旋转立方体

方法一:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			
			#wrap{
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
				width: 300px;
				height: 300px;
				/*border: 1px solid;*/
				perspective: 200px;
			}
			
			#wrap > .inner{
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
				width: 100px;
				height: 100px;
				transition-duration: 3s;
				transform-style: preserve-3d;
				transform-origin: center center -50px;
			}
			
			#wrap > .inner > div{
				position: absolute;
				width: 100px;
				height: 100px;
				text-align: center;
				background: red;
				font: 50px/100px "微软雅黑";
				/*backface-visibility:hidden*/
			}
			
			#wrap > .inner > div:nth-child(2){
				top: -100px;
				transform-origin: bottom;
				transform: rotateX(90deg);
			}
			
			#wrap > .inner > div:nth-child(4){
				bottom: -100px;
				transform-origin: top;
				transform: rotateX(-90deg);
			}
			
			#wrap > .inner > div:nth-child(5){
				left: -100px;
				transform-origin: right;
				transform: rotateY(-90deg);
			}
			
			#wrap > .inner > div:nth-child(6){
				right: -100px;
				transform-origin: left;
				transform: rotateY(90deg);
			}
			
			#wrap > .inner > div:nth-child(3){
				transform: translateZ(-100px);
				transform: rotateY(180);
			}
			
			#wrap > .inner > div:nth-child(1){
				z-index: 1;
			}
			
			#wrap > .inner:hover{
				transform: rotateX(360deg);
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="inner">
				<div>1</div>
				<div>2</div>
				<div>3</div>
				<div>4</div>
				<div>5</div>
				<div>6</div>
			</div>
		</div>
	</body>
</html>

方法二:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			
			#wrap{
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
				width: 300px;
				height: 300px;
				/*border: 1px solid;*/
				perspective: 200px;
			}
			
			#wrap > .inner{
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
				width: 100px;
				height: 100px;
				transition-duration: 3s;
				transform-style: preserve-3d;
				transform-origin: center center -50px;
			}
			
			#wrap > .inner > div{
				position: absolute;
				width: 100px;
				height: 100px;
				text-align: center;
				background: red;
				font: 50px/100px "微软雅黑";
				/*backface-visibility:hidden*/
				transform-origin: center center -50px;
			}
			
			#wrap > .inner > div:nth-child(2){
				transform: rotateX(270deg);
			}
			
			#wrap > .inner > div:nth-child(4){
				transform: rotateX(90deg);
			}
			
			#wrap > .inner > div:nth-child(5){
				transform: rotateY(270deg);
			}
			
			#wrap > .inner > div:nth-child(6){
				transform: rotateY(90deg);
			}
			
			#wrap > .inner > div:nth-child(3){
				transform: rotateY(180deg) rotate(180deg);
			}
			
			#wrap > .inner > div:nth-child(1){
			}
			
			#wrap > .inner:hover{
				transform: rotateX(360deg);
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="inner">
				<div>1</div>
				<div>2</div>
				<div>3</div>
				<div>4</div>
				<div>5</div>
				<div>6</div>
			</div>
		</div>
	</body>
</html>
展开阅读全文

没有更多推荐了,返回首页