CSS3之3D立方体效果
下面代码可实现3D立方体,比较好理解,就是让每个面先平移到指定位置,然后旋转90度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D转换模块-正方体</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
width: 200px;
height: 200px;
border: 1px solid #000;
box-sizing: border-box;
margin: 100px auto;
position: relative;
transform: rotateY(0deg) rotateX(0deg);
transform-style: preserve-3d;
}
ul li{
list-style: none;
width: 200px;
height: 200px;
font-size: 60px;
text-align: center;
line-height: 200px;
position: absolute;
left: 0;
top: 0;
}
ul li:nth-child(1){
background-color: red;
transform: translateX(-100px) rotateY(90deg);
}
ul li:nth-child(2){
background-color: green;
transform: translateX(100px) rotateY(90deg);
}
ul li:nth-child(3){
background-color: blue;
transform: translateY(-100px) rotateX(90deg);
}
ul li:nth-child(4){
background-color: yellow;
transform: translateY(100px) rotateX(90deg);
}
ul li:nth-child(5){
background-color: purple;
transform: translateZ(-100px);
}
ul li:nth-child(6){
background-color: pink;
transform: translateZ(100px);
} </style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</body>
</html>
但是缺点是 如果我们旋转每个面面对自己的时候,里面的数字可能并不是正序的,如图:

这里的5就是反的,为了解决这个问题,我们需要做的是 针对 上,后,下,前 四个面进行先旋转在平移的处理,就可以保证转向我们的面始终是正序的
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D转换模块-正方体终极</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
width: 200px;
height: 200px;
border: 1px solid #000;
box-sizing: border-box;
margin: 100px auto;
position: relative;
transform: rotateY(0deg) rotateX(0deg);
transform-style: preserve-3d;
}
ul li{
list-style: none;
width: 200px;
height: 200px;
font-size: 60px;
text-align: center;
line-height: 200px;
position: absolute;
left: 0;
top: 0;
}
/*上面*/
ul li:nth-child(1){
background-color: red;
transform: rotateX(90deg) translateZ(100px);
}
/*后面*/
ul li:nth-child(2){
background-color: green;
transform: rotateX(180deg) translateZ(100px);
}
/*下面*/
ul li:nth-child(3){
background-color: blue;
transform: rotateX(270deg) translateZ(100px);
}
/*
前面*/
ul li:nth-child(4){
background-color: yellow;
transform: rotateX(360deg) translateZ(100px);
}
/*
左面
*/
ul li:nth-child(5){
background-color: purple;
transform: translateX(-100px) rotateY(90deg);
}
/*
右面
*/
ul li:nth-child(6){
background-color: pink;
transform: translateX(100px) rotateY(90deg);
} </style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</body>
</html>
如果实现旋转效果,就需要加上CSS3中的animation属性,代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>110-3D转换模块-练习</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
/*想看到整个立方的近大远小效果, 就给ul的父元素添加透视*/ perspective: 500px; }
ul{
width: 200px;
height: 200px;
box-sizing: border-box;
margin: 100px auto;
position: relative;
transform: rotateY(0deg) rotateX(0deg);
transform-style: preserve-3d;
animation: sport 5s linear 0s infinite normal;
}
ul li{
list-style: none;
width: 200px;
height: 200px;
font-size: 60px;
text-align: center;
line-height: 200px;
position: absolute;
left: 0;
top: 0;
}
ul li:nth-child(1){
background-color: red;
transform: rotateX(90deg) translateZ(100px) scale(2, 1);
}
ul li:nth-child(2){
background-color: green;
transform: rotateX(180deg) translateZ(100px) scale(2, 1);
}
ul li:nth-child(3){
background-color: blue;
transform: rotateX(270deg) translateZ(100px) scale(2, 1);
}
ul li:nth-child(4){
background-color: yellow;
transform: rotateX(360deg) translateZ(100px) scale(2, 1);
}
ul li:nth-child(5){
background-color: purple;
transform: translateX(-200px) rotateY(90deg);
}
ul li:nth-child(6){
background-color: pink;
transform: translateX(200px) rotateY(90deg);
}
ul li img{
/*
注意点:
只要父元素被拉伸了,子元素也会被拉伸
*/
width: 200px;
height: 200px;
}
@keyframes sport {
from{
transform: rotateX(0deg);
}
to{
transform: rotateX(360deg);
}
}
</style>
</head>
<body>
<ul>
<li><img src="data:images/banner11.jpg" alt=""></li>
<li><img src="data:images/banner21.jpg" alt=""></li>
<li><img src="data:images/banner31.jpg" alt=""></li>
<li><img src="data:images/banner41.jpg" alt=""></li>
<li></li>
<li></li>
</ul>
</body>
</html>
CSS3之3D立方体效果的更多相关文章
- 基于css3的3D立方体旋转特效
今天给大家分享一款基于css3的3D立方体旋转特效.这款特效适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. 不支持IE8及以下浏览器.效果图如下 : ...
- 【CSS3】3D立方体动画
关于CSS3的3D立方体动画 知识点: 1.每个元素有独立的坐标系 2.坐标系随当前元素的改变而发生改变 3.立方体由静态transform参数构成 4.通过给容器添加动画使立方体运动 效果图: &l ...
- CSS3 3D立方体效果-transform也不过如此
CSS3系列已经学习了一段时间了,第一篇文章写了一些css3的奇技淫巧,原文戳这里,还获得了较多网友的支持,在此谢过各位,你们的支持是我写文章最大的动力^_^. 那么这一篇文章呢,主要是通过一个3D立 ...
- css3之3D翻牌效果
最近一直在学css3,发现他真的是越来越牛逼.现在的css3已经不在是以前的css了,它能做出的功能效果是我们没法想象的了.它可以实现flash,可以制作一些js能做出来的效果,还可以写出ps做出 ...
- HTML5和CSS3实现3D转换效果 CSS3的3D效果
上次,我们一起研究了css3的2d模块,这次我们一起来看一下css3的3d模块. 首先,我们来了解一下3d的坐标系,x轴在屏幕上为水平方向,y轴为垂直方向,而z轴为垂直于屏幕的方向. 不理解的话可以参 ...
- 简单几步用纯CSS3实现3D翻转效果
作为前端开发人员的必修课,CSS3翻转能带我们完成许多基本动效,本期我们将用CSS3实现hover翻转效果~ 第一步非常简单,我们简单画1个演示方块,为其 添加transition和transform ...
- CSS3 3D立方体效果
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- CSS3 实现3D旋转木马效果
基本原理: 1.首先我们需要让图片能旋转的效果,我们让所有图片绝对定位(position:absolute),共用一个中心点. 2.对于舞台我们加一个视距,比如下面的demo是 perspective ...
- Html5+css3实现3D转动效果
由于最近一直在忙着筹划去上海工作的事情,所以博客更新的速度也就慢了下来.前几天面试了几家公司,也拿到几份offer,总结了一些面试中遇到的问题,最近整理一下会和大家一起分享.今天呢,就和大家分享一下前 ...
随机推荐
- python标准库之random模块
Python中的random模块用于生成随机数. 下面具体介绍random模块的功能: 1.random.random() #用于生成一个0到1的 随机浮点数:0<= n < 1.0 1 ...
- elasticsearch(es) 集群恢复触发配置(Local Gateway参数)
elasticsearch(es) 集群恢复触发配置(Local Gateway) 当你集群重启时,几个配置项影响你的分片恢复的表现. 首先,我们需要明白如果什么也没配置将会发生什么. 想象一下假设你 ...
- AndroidStudio3.0 修改项目包名
进入 Androidmanifest.xml,找到 package 名称,选中需要修改的部分. 如原包名为com.demo.musicplayer,如果改为com.musicplayer.那么选中当前 ...
- 通过for 来获取数组里面的电话
//存放的是电话号码包含的数字 , , , , , }; //电话号码出现的下标 , , , , , , , , , , }; //方式1 ; i < index.length; i++) { ...
- final、finally、以及finalize的区别
final ---修饰类.变量和方法,修饰的类不能被继承 .修饰的方法不能被重写 .修饰的成员变量不可更改 另外,修饰成员变量必须立即赋值,修饰局部变量使用之前被赋值就可以. finally通常和tr ...
- Python学习笔记,day4
Python学习第四天 一.装饰器 函数调用顺序: 其他高级语言类似,Python 不允许在函数未声明之前,对其进行引用或者调用 高阶函数: 满足下列条件之一就可成函数为高阶函数 某一函数当做参数传入 ...
- until和while 判断网段IP地址是否存在
1.使用until和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail! ...
- C++ 实验3 类和对象
Part 2 #ifndef GRAPH_H #define GRAPH_H class Graph { public: Graph(char ch, int n); void draw(); pri ...
- python的mysql小代码
我因为懒,就想写个批量insert数据的小代码 这里是代码 # _*_ encoding:utf-8 _*_ import os import MySQLdb import numpy as np d ...
- Android Studio学习之 日志工具
Log.v() 低级日志 Log.d(' ',' ') debug调试信息 第一个参数tag,当前类名 第二个参数msg,打印具体内容 Log.i() info数据 Log.w() warn警 ...