css钻石旋转实现

css钻石旋转实现:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			/* 钻石旋转
			 * 要实现这个钻石旋转: 首先需要明确这个钻石分为上下两个部分,上面包含六个正三角形,下面有6个倒三角形
			 * css实现正三角形:上右下左的方向 border-style: solid;border-color:transparent;border-width: 0 50px 170px 50px; border-bottom-color: rgba(255,0,0,0.5)
			 * css实现倒三角形:上右下左的方向 border-style: solid;border-color:transparent;border-width: 170px 50px 0 50px; border-top-color: rgba(255,0,0,0.5)
			 * 然后提供一个3D环境,给外层盒子添加 transform-style: preserve-3d;flat 所有的子元素在2D平面中;preserve-3D 所有的子元素 在3D 平面中
			 * 上面的三角形设置为绝对定位 absolute
			 * 使用css3的transform 三角形按角度转动 排列成钻石的上半部分,同理实现下半部分
			 * rotateY:沿着Y轴实现旋转,translateZ:沿着Z轴移动88px;沿着X轴 旋转31度
			 * 写一个动画tuoluo 0~50%~100%  沿着z轴旋转
			 * 实现动画的循环播放animation: tuoluo 3s linear infinite; */

			/*@keysframes*/
			.wrap{
				width: 200px;
				height: 400px;
				margin: 30px auto;
			}
			@keyframes tuoluo{
				0%{
					transform: rotateY(0deg) rotateX(0deg);
				}
				50%{
					transform: rotateY(-180deg) rotateX(18deg);
				}
				100%{
					transform: rotateY(-360deg) rotateX(0deg);
				}
			}
			.wrap .tuoluo{
				width: 100%;
				height: 100%;
				transform-style: preserve-3d;
				/* flat 所有的子元素在2D平面中*/
				/* preserve-3D 所有的子元素 在3D 平面中*/
				animation: tuoluo 3s linear infinite;
			}
			.wrap .tuoluo .tuoluo-top,
			.wrap .tuoluo .tuoluo-bottom{
				position: relative;
				width: 100%;
				height: 50%;
			}
			.tuoluo-top .face-top{
				position: absolute;
				top: 29px;
				width: 0;
				height: 0;
				border-style: solid;
				border-color: transparent;
				border-width: 0 50px 170px 50px;
				border-bottom-color: rgba(65,92,162,.5);
				/*元素变形基点的位置*/
				transform-origin: center bottom;
			}
			.tuoluo-top .face-top:nth-of-type(1){
				transform: rotateY(0deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(2){
				transform: rotateY(60deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(3){
				transform: rotateY(120deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(4){
				transform: rotateY(180deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(5){
				transform: rotateY(240deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(6){
				transform: rotateY(300deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-bottom .face-bottom{
				position: absolute;
				width: 0;
				height: 0;
				border-style: solid;
				border-color: transparent;
				border-width: 170px 50px 0 50px;
				border-top-color: rgba(65,92,162,.5);
				/*元素变形基点的位置*/
				transform-origin: center top;
			}
			.tuoluo-bottom .face-bottom:nth-of-type(1){
				transform: rotateY(0deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(2){
				transform: rotateY(60deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(3){
				transform: rotateY(120deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(4){
				transform: rotateY(180deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(5){
				transform: rotateY(240deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(6){
				transform: rotateY(300deg) translateZ(88px) rotateX(-31deg);
			}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div class="tuoluo">
				<div class="tuoluo-top">
					<div class="face-top"></div>
					<div class="face-top"></div>
					<div class="face-top"></div>
					<div class="face-top"></div>
					<div class="face-top"></div>
					<div class="face-top"></div>
				</div>
				<div class="tuoluo-bottom">
					<div class="face-bottom"></div>
					<div class="face-bottom"></div>
					<div class="face-bottom"></div>
					<div class="face-bottom"></div>
					<div class="face-bottom"></div>
					<div class="face-bottom"></div>
				</div>
			</div>
		</div>
	</body>
</html>

  

时间: 2024-07-29 16:07:16

css钻石旋转实现的相关文章

CSS 3D旋转 hover 后设置transform 是相对于正常位置

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style type="text/css"> .nav{ width: 980px; margin: 50px auto; background-color: #

js+css立体旋转

纯 CSS3 制作可口可乐罐  这个效果相信大家很多人看过了,纯css实现的立体可口可乐罐,看起来相当高大上~ 于是今天我这小菜鸟试着研究下,稍微遗憾的是,没有看到源码,还是直接F12吧,貌似实现也不是那么难 大概原理图是这样: 当然代码实现起来有所不同: 图片分别如下:         左图为遮罩层,其中中间透明部分可以显示背景图,并且添加了半透明阴影,使得效果能够更逼真,相当于上图中黄色滑块, 右图为背景图,相当于灰色背景,在这段代码的实现中,实例中共用了50多个p标签来拼接,背景图像设置为

css制作旋转风车(transform 篇)

做这个案例之前首先要大概了解CSS的transform的属性 transform 属性向元素应用 2D 或 3D 转换.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 看看效果图 打开的时候自动旋转,当鼠标经过的时候加快旋转速度,鼠标移开就恢复原来的速度. 参考代码:(为了美观可以自已加上一直背景图,我这里是空白的背景显得单调) <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &

css样式-旋转rotate

一般前端经常用到例如'<'这样的箭头,然后自己通过旋转变换方向,可以让箭头向上.向下,然后有一天我是用的span,背景是ui提供的箭头图片,死活旋转不了,我就蒙圈了... 解决: 把span元素直接换成块状元素,或者给span设置inline-block或者block.让span成为块状元素就可以了. 下图是中国w3.org网上面的解释,一开始不懂atomic inline-level element是个啥,点链接看到的是inline level box的介绍,就总以为原子级内联元素就是inli

模仿iPhone中的返回按钮的css样式文件

css模拟苹果ios6风格按钮方法ios8的稍后奉上.先说ios6的.直接看代码:1.确定HTML的结构,用一个标签加伪类其实是不行的,所以我用了两个嵌套的标签 <a href="#"> <span>首页</span></a>2.首先想到的是右边一个标准Button,这个比较秒杀吧,所以不多说了,上图和代码 header_1CSS Code.btn-back span {        display: inline-block;    

Css3 - 动画旋转

常用的css动画旋转 <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <style type="text/css"> #box { background:red; color:#fff; width:100px; heig

css3 3d旋转图片立方体特效代码

一.什么是css3 3d旋转 ? 形成一个3D空间: transform-style:preserve-3d    ( 让父元素形成3D,让其子元素在3D空间进行变化 ). 3d场景,在垂直于屏幕的方法,相对于3d多出个z轴,Z轴:靠近屏幕的方向是正向,远离屏幕的方向是反向,2d场景,在屏幕上水平和垂直的交叉线x轴和y轴. 二.关于css 3d旋转的相关属性及使用方法 变形属性:transform 3D功能函数 ----3D的位移:transform:translate3d(x,y,z);   

QUICK-AP + BETTERCAP 搭建热点, 欺骗局域网内用户下载任意可执行文件

环境需求 1:kali系统 , 2.0版本 2:quick-ap 3:bettercap 4:bettercap-proxy-modules 5:博客园账号(把zip文件传到博客园的文件服务器) 主要环境搭建 目的:替换局域网用户的下载文件,变为我们自己定义的下载文件, 这个文件可以为一个恶意的exe或者apk quick-ap通过github即可下载:https://github.com/sqqihao/quick-ap 需要bettercap的第三方模块:https://github.com

CSS3-3D制作案例分析实战

一.前言 上一节,介绍了基础的CSS3 3D动画原理实现,也举了一个小小的例子来演示,但是有朋友跟我私信说想看看一些关于CSS3 3D的实例,所以在这里为了满足一下大家的需求,同时也为了以后能够更好的巩固CSS3 3D的知识,所以在这里写下这篇博文,希望能够帮助你更好的理解3D的制作和实现原理,同时也欢迎各位小伙伴对文中的错误给予指正 二.入门案例分析 这里先说一说我的规划,我打算先从入门级的案例入手,然后依次递推,最后要达到的效果是,理解完所有的例子的设计思路,基本上CSS3-3D制作就能够随