Home > Web Front-end > Front-end Q&A > How to achieve rotation effect in css (code example)

How to achieve rotation effect in css (code example)

PHPz
Release: 2023-04-21 13:53:54
Original
11692 people have browsed it

CSS is a widely used web page style design language, and rotation is one of the commonly used effects. Rotation through CSS can make web pages more beautiful and intuitive. Here are some commonly used CSS rotation codes for reference.

1. Use the transform attribute

The transform attribute allows the element to rotate, scale, tilt, move, etc. The element can be rotated using the rotate() method, where deg is the angle value of rotation, a positive number indicates clockwise rotation, and a negative number indicates counterclockwise rotation.

For example:

.rotate {
transform: rotate(45deg);
}

2. Use the transition attribute and the rotate method of transform

The transition attribute can control the transition effect of the element, allowing the element to have a smooth transition effect when rotating.

For example:

.rotate {
transition: transform 0.5s ease-in-out;
}
.rotate:hover {
transform: rotate( 45deg);
}

3. Use animation attributes and @keyframes rules

@keyframes rules can define key frames in CSS animations, and animation attributes can control the performance of CSS animations. .

For example:

.rotate {
animation: rotate-ani 2s linear infinite;
}
@keyframes rotate-ani {
from {

transform: rotate(0deg);
Copy after login

}
to {

transform: rotate(360deg);
Copy after login

}
}

The above are several commonly used CSS rotation codes, which achieve the rotation effect of elements in different ways. I hope these codes can help readers in need and make the web page more beautiful and vivid.

The above is the detailed content of How to achieve rotation effect in css (code example). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template