The content of this article is about how to use pure CSS to realize a paper crane (with source code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
Effect preview
Source code download
https://github.com/comehope/front-end-daily -challenges
Code Interpretation
Define dom, the container contains 6 elements, representing the head, neck, body side, wings, tail, and chest:
<div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div>
Centered display :
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: dodgerblue; }
Define the container size:
.cranes { width: 52em; height: 50em; font-size: 7px; }
Set the color of the paper crane to white:
.cranes { color: white; }
Draw the head:
.cranes { position: relative; } .head { border-left: 13em solid transparent; border-right: 6em solid transparent; border-bottom: 2em solid; position: absolute; left: 0; top: 21; transform: rotate(-5deg); }
Create a triangle with the above The code is abstracted into a template, and then the data is changed into variables, similar to calling a function:
.cranes span { border-left: calc(var(--left) * 1em) solid transparent; border-right: calc(var(--right) * 1em) solid transparent; border-bottom: calc(var(--bottom) * 1em) solid; position: absolute; transform: rotate(calc(var(--rotation) * 1deg)); left: calc(var(--x) * 1em); top: calc(var(--y) * 1em); } .head { --left: 13; --right: 6; --bottom: 2; --x: 0; --y: 21; --rotation: -5; }
Set the transparency so that there is an origami effect where the elements are overlaid:
.cranes span { filter: opacity(0.6); }
The next step is one by one Call the function that generates triangles to create other triangles:
Neck:
.neck { --left: 6; --right: 6; --bottom: 12; --x: 14; --y: 19; --rotation: 75; }
Sides of body:
.side { --left: 1.5; --right: 11.5; --bottom: 20; --x: 18.8; --y: 15.1; --rotation: 20; }
Wings:
.wing { --left: 18.7; --right: 30; --bottom: 8; --x: 6.7; --y: 9.2; --rotation: -41.9; }
Tail:
.tail { --left: 18.6; --right: 7.7; --bottom: 3.9; --x: 19.6; --y: 38.1; --rotation: -126.5; }
Chest:
.belly { --left: 6.2; --right: 1.8; --bottom: 11.5; --x: 17.5; --y: 27.8; --rotation: -99; }
At this point, the paper crane is finished.
Finally, add a little interactive effect. When the mouse is hovered, it will transform from an isosceles right triangle into a crane:
.cranes:hover span { animation: appear 1s ease-in; } @keyframes appear { from { border-left: 3em solid transparent; border-right: 3em solid transparent; border-bottom: 3em solid; position: absolute; transform: rotate(0deg); left: calc((52em - 3em) / 2); top: calc((50em - 3em) / 2); } }
You're done!
Related recommendations:
How to use pure CSS to implement the album icon of the Apple system (code)
How to use CSS and D3 to implement a small Interactive animation of fish swimming (with code)
The above is the detailed content of How to use pure CSS to implement a paper crane (source code attached). For more information, please follow other related articles on the PHP Chinese website!

JavaScript 不提供任何内存管理操作。相反,内存由 JavaScript VM 通过内存回收过程管理,该过程称为垃圾收集。

vscode自身是支持vue文件组件跳转到定义的,但是支持的力度是非常弱的。我们在vue-cli的配置的下,可以写很多灵活的用法,这样可以提升我们的生产效率。但是正是这些灵活的写法,导致了vscode自身提供的功能无法支持跳转到文件定义。为了兼容这些灵活的写法,提高工作效率,所以写了一个vscode支持vue文件跳转到定义的插件。

Node 19已正式发布,下面本篇文章就来带大家详解了解一下Node.js 19的 6 大特性,希望对大家有所帮助!

选择一个Node的Docker镜像看起来像是一件小事,但是镜像的大小和潜在漏洞可能会对你的CI/CD流程和安全造成重大的影响。那我们如何选择一个最好Node.js Docker镜像呢?

本篇文章给大家整理和分享几个前端文件处理相关的实用工具库,共分成6大类一一介绍给大家,希望对大家有所帮助。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools