css to achieve diamond rotation effect
css diamond rotation implementation:
<!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> <p class="wrap"> <p class="tuoluo"> <p class="tuoluo-top"> <p class="face-top"></p> <p class="face-top"></p> <p class="face-top"></p> <p class="face-top"></p> <p class="face-top"></p> <p class="face-top"></p> </p> <p class="tuoluo-bottom"> <p class="face-bottom"></p> <p class="face-bottom"></p> <p class="face-bottom"></p> <p class="face-bottom"></p> <p class="face-bottom"></p> <p class="face-bottom"></p> </p> </p> </p> </body> </html>
The above is the detailed content of css to achieve diamond rotation effect. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
