Home > Web Front-end > Front-end Q&A > How to set rotate at the rotation center point in css3

How to set rotate at the rotation center point in css3

WBOY
Release: 2022-04-24 10:50:22
Original
8942 people have browsed it

In CSS3, you can use the "transform-origin" attribute to set the rotation center point of rotate. This attribute can change the position of the transformed element. The first parameter sets the rotation position of the x-axis, and the second parameter sets Y-axis rotation position, the syntax is "transform-origin:x-axis position y-axis position".

How to set rotate at the rotation center point in css3

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

How to set the rotation center point of rotate in css3

The rotate() function is a built-in function used to rotate elements based on a given angle as a parameter. Angle can be set in degrees, ticks, radians or turns.

Usage:

rotate( angle )
Copy after login

Parameters: This function accepts a single parameter angle representing the rotation angle. Positive and negative angles rotate the element clockwise and counterclockwise respectively.

The following example illustrates the rotate() function in CSS:

Example 1:

<!DOCTYPE html>  
<html>  
<head>  
    <title>CSS rotate() function</title>  
    <style>  
        body { 
            text-align:center; 
        } 
        h1 { 
            color:green; 
        } 
        .rotate_image { 
            transform:rotate(45deg); 
        } 
    </style>  
</head>  
  
<body>  
    <h1>GeeksforGeeks</h1> 
    <h2>CSS rotate() function</h2> 
    <br><br> 
      
    <img class="rotate_image" src=  
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
        alt="GeeksforGeeks logo">  
</body>  
</html>
Copy after login

Output:

How to set rotate at the rotation center point in css3

The transform-Origin attribute allows you to change the position of the transformed element.

2D transform elements can change the X and Y axes of the element. Transform elements in 3D and also change the Z-axis of the element.

The syntax is:

transform-origin: x-axis y-axis z-axis;
Copy after login

x-axis defines where the view is placed on the X-axis.

y-axis defines where the view is placed on the Y-axis.

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>123</title>
<style>
#div1
{
position: relative;
height: 200px;
width: 200px;
margin: 100px;
padding:10px;
border: 1px solid black;
}
#div2
{
padding:50px;
position: absolute;
border: 1px solid black;
background-color: red;
transform: rotate(45deg);
transform-origin:20% 40%;
-ms-transform: rotate(45deg); /* IE 9 */
-ms-transform-origin:20% 40%; /* IE 9 */
-webkit-transform: rotate(45deg); /* Safari and Chrome */
-webkit-transform-origin:20% 40%; /* Safari and Chrome */
}
</style>
</head>
<body>
<div id="div1">
  <div id="div2">HELLO</div>
</div>
</body>
</html>
Copy after login

Output result:

How to set rotate at the rotation center point in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set rotate at the rotation center point in css3. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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