How to implement background rotation function in css3

PHPz
Release: 2023-04-21 10:22:41
Original
1715 people have browsed it

In modern web design, the use of background images is very common. In order to make the web page look more vivid and interesting, we can use many different ways to present the background image, such as tiling, repeating, stretching, etc. One of them, called Background-Rotation, is a good choice. In CSS3, we can achieve this effect by using the transform attribute and rotate() function. In this article, we'll take a closer look at this background rotation feature and give some application examples.

Basic syntax of CSS3 background rotation

The transform property of CSS3 is one of the important properties of CSS transformation, which can rotate, scale, deform, and tilt elements. Among them, the rotate() function is used to implement rotation. Its syntax is as follows:

transform: rotate(angle);
Copy after login

Among them, angle is an angle value, which is the angle you need to rotate. Here is a simple example:

.box {
    width: 200px;
    height: 200px;
    background: url("image.jpg") no-repeat center center;
    transform: rotate(45deg);
}
Copy after login

This style will rotate the box with the image "image.jpg" as the background counterclockwise 45 degrees

In this way, we can change the top background The image is rotated into a dynamic style that is interesting and vivid.

Application examples of CSS3 background rotation

CSS3 background rotation can add vividness and liveliness to our web pages. Below are some application examples.

  1. Rotating Card

Card design is widely used in modern web pages. It can compactly organize related content together so that users can see it at a glance. By using background rotation, we can make the card look more three-dimensional and enhance the user's visual experience. The following is an example:

.card {
    width: 300px;
    height: 200px;
    background: url("image.jpg") no-repeat center center;
    border-radius: 10px;
    transform-style: preserve-3d;
    transition: all .5s ease-in-out;
}

.card:hover {
    transform: rotateY(180deg);
}
Copy after login

This example uses a picture "image.jpg" as the background of the card, and uses the transform-style attribute and the transition animation attribute to achieve the rotation transition effect. When a user hovers over a card, the background image instantly rotates 180 degrees.

  1. Rotation menu

By applying background rotation, we can also add some special effects to the menu bar in the web page. In the example, we adjust the background of each item in the menu to a small square with only one black vertical line, so that the menu will not look too cumbersome. The background rotation is for visual effects. The blocks will rotate when the user hovers to increase dynamics and interest.

.nav {
    display: flex;
    justify-content: center;
}

.nav-item {
    width: 50px;
    height: 50px;
    margin: 0 10px;
    background: #fff;
    background-image: linear-gradient(to bottom, #ccc, #ccc 50%, transparent 50%, transparent);
    background-size: 10px 10px;
    border: 1px solid #ccc;
    border-radius: 50%;
    cursor: pointer;
    transition: all .5s ease-in-out;
}

.nav-item:hover {
    background-color: #ccc;
    transform: rotate(360deg);
}
Copy after login

In this example, we set the background of the menu item mainly to white, making a small square within a circular border. When hovering over a menu item, the box will rotate once, making the menu more interactive.

Summary

By using the rotate() function of the transform attribute, we can make the rotation effect of the background image very simple, thereby adding interest and vividness to the web page. And by using some creativity, such as applying it to elements such as cards and menus, we can even create very interesting interactive effects. Please try to apply this feature to your web design to bring a better sensory experience to your users.

The above is the detailed content of How to implement background rotation function in css3. 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