-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[Edit] CSS Transform Functions: rotate() #7344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4738fc6
[Edit] CSS Transform Functions: rotate()
Sriparno08 5a386cf
SEO changes
Sriparno08 8b7665a
content fixes
mamtawardhani b6fe75c
Apply suggestions
Sriparno08 c0dc7e3
Merge branch 'main' into rotate
Sriparno08 504fba9
Merge branch 'main' into rotate
mamtawardhani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 100 additions & 15 deletions
115
content/css/concepts/transform-functions/terms/rotate/rotate.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,124 @@ | ||
--- | ||
Title: 'rotate()' | ||
Description: 'Rotates an element around a fixed point in a 2D space.' | ||
Description: 'Rotates an element around a fixed point by a specified angle.' | ||
Subjects: | ||
- 'Web Development' | ||
- 'Web Design' | ||
- 'Web Development' | ||
Tags: | ||
- 'Elements' | ||
- 'Functions' | ||
- 'Positioning' | ||
- 'Values' | ||
CatalogContent: | ||
- 'learn-css' | ||
- 'paths/front-end-engineer-career-path' | ||
- 'paths/full-stack-engineer-career-path' | ||
--- | ||
|
||
The `rotate()` function rotates an element around a fixed point in a two-dimensional space. | ||
The CSS **`rotate()`** function rotates an element around a fixed point by a specified angle. This rotation can either be clockwise or anticlockwise and is commonly used in [animations](https://www.codecademy.com/resources/docs/css/animations), UI interactions, or creative web layouts. | ||
|
||
## Syntax | ||
## CSS `rotate()` Syntax | ||
|
||
```css | ||
transform: rotate(<angle>); | ||
```pseudo | ||
transform: rotate(angle); | ||
``` | ||
|
||
where a required `<angle>` can be one of the following: | ||
**Parameters:** | ||
|
||
- Degree value: `90deg` | ||
- Radian value: `0.78rad` | ||
- Gradian value: `200grad` | ||
- Turn value: `.25turn` | ||
- `angle`: Defines the degree of rotation. It accepts values in degrees (`deg`), radians (`rad`), gradians (`grad`), or turns (`turn`). | ||
- Positive values = Clockwise rotation | ||
- Negative values = Anticlockwise rotation | ||
|
||
## Example 1 | ||
## Example 1: Basic Rotation in CSS Using `rotate()` | ||
|
||
Rotate image 45 degrees clockwise: | ||
In this example, the `.box` element is rotated 45 degrees clockwise from its original position using CSS `rotate()`, creating a diamond-like appearance: | ||
|
||
```css | ||
.hero-image { | ||
.box { | ||
width: 100px; | ||
height: 100px; | ||
background-color: coral; | ||
transform: rotate(45deg); | ||
margin: 50px; | ||
} | ||
``` | ||
|
||
Here is the output: | ||
|
||
 | ||
|
||
## Example 2: Using `rotate()` to Rotate on Hover | ||
|
||
When a user hovers on the `.box` element, it rotates 90 degrees, thanks to the smooth [transition](https://www.codecademy.com/resources/docs/css/transition) defined in the CSS: | ||
|
||
```css | ||
.box { | ||
width: 100px; | ||
height: 100px; | ||
background-color: mediumseagreen; | ||
transition: transform 0.3s ease-in-out; | ||
margin: 50px; | ||
} | ||
|
||
.box:hover { | ||
transform: rotate(90deg); | ||
} | ||
``` | ||
|
||
Here is the output: | ||
|
||
 | ||
|
||
## Example 3: Continuous Rotation in CSS With the Help of `rotate()` | ||
|
||
This example creates a spinning loader by continuously rotating a styled circle using a CSS animation: | ||
|
||
```css | ||
.box { | ||
width: 80px; | ||
height: 80px; | ||
margin: 50px; | ||
border: 5px solid lightgray; | ||
border-top: 5px solid steelblue; | ||
border-radius: 50%; | ||
animation: spin 2s linear infinite; | ||
} | ||
|
||
@keyframes spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
``` | ||
|
||
Here is the output: | ||
|
||
 | ||
|
||
## Frequently Asked Questions | ||
|
||
### 1. Does CSS `rotate()` affect layout or just visual appearance? | ||
|
||
CSS `rotate()` is part of the `transform` property and only affects visual appearance. It doesn't change the element's position in the document flow. | ||
|
||
### 2. Can I combine CSS `rotate()` with other transform functions? | ||
|
||
Absolutely. You can combine CSS `rotate()` with other transform functions by separating them with a space: | ||
|
||
```css | ||
transform: scale(1.2) rotate(30deg) translateX(20px); | ||
``` | ||
|
||
### 3. Is CSS `rotate()` supported across all browsers? | ||
|
||
Yes. Modern browsers like Chrome, Firefox, Safari, Edge, and even Internet Explorer 9+ support CSS `rotate()`. | ||
|
||
### 4. How to rotate 45 degrees in CSS? | ||
|
||
Here's how you can use CSS `rotate()` to rotate 45 degrees: | ||
|
||
```css | ||
transform: rotate(45deg); | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the faq should be " How to rotate 45 degrees in CSS?"