How to use pure CSS to implement a paper crane (source code attached)
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!
Two Images and an API: Everything We Need for Recoloring ProductsApr 15, 2025 am 11:27 AMI recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show
Weekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsApr 15, 2025 am 11:19 AMIn this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds
Options for Hosting Your Own Non-JavaScript-Based AnalyticsApr 15, 2025 am 11:09 AMThere are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used
It's All In the Head: Managing the Document Head of a React Powered Site With React HelmetApr 15, 2025 am 11:01 AMThe document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its
What is super() in JavaScript?Apr 15, 2025 am 10:59 AMWhat's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its
Comparing the Different Types of Native JavaScript PopupsApr 15, 2025 am 10:48 AMJavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:
Why Are Accessible Websites so Hard to Build?Apr 15, 2025 am 10:45 AMI was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard
The `hidden` Attribute is Visibly WeakApr 15, 2025 am 10:43 AMThere is an HTML attribute that does exactly what you think it should do:


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 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software







