-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[Term Entry] CSS Transform Functions: rotateY() #8244
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
Open
JakevB88
wants to merge
7
commits into
Codecademy:main
Choose a base branch
from
JakevB88:rotateY
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6bbbcd0
created rotatey.md and started the content
JakevB88 62093a3
[add term] rotateY.md updated and added .png and .gif files
JakevB88 4fb934f
rotateY.md spelling/grammer check
JakevB88 ec08259
Delete FAQ section from rotateY documentation
mamtawardhani 8ad098f
Remove 'Transform' tag from rotateY documentation
mamtawardhani 0692a19
Address comments: add perspective and romove FAQ and Tag
JakevB88 a4438c8
resolve merge conflict rotateY.md
JakevB88 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
203 changes: 203 additions & 0 deletions
203
content/css/concepts/transform-functions/terms/rotateY/rotateY.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 |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| --- | ||
| Title: 'rotateY()' | ||
| Description: 'Rotates an element around the Y-axis in 3D space.' | ||
| Subjects: | ||
| - 'Web Design' | ||
| - 'Web Development' | ||
| Tags: | ||
| - 'Animation' | ||
| - 'CSS' | ||
| - 'Functions' | ||
| CatalogContent: | ||
| - 'learn-css' | ||
| - 'paths/front-end-engineer-career-path' | ||
| --- | ||
|
|
||
| The **`rotateY()`** function is a CSS transform function that rotates an element around the Y-axis, which runs vertically through the element. It is primarily used to create 3D rotation effects, especially when combined with the **`perspective()`** transform function. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```pseudo | ||
| transform: rotateY(angle); | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `angle`: A CSS `<angle>` value (e.g., `45deg`, `0.785rad`, `0.125turn` ) that specifies the amount of rotation around the Y-axis. Using a positive angle results in clockwise rotation (the right moves back, and the left moves forward). Using a negative angle causes counter-clockwise rotation (the right moves forward, and the left moves back). | ||
|
|
||
| **Return value:** | ||
|
|
||
| The `rotateY()` function returns a `<transform-function>` value that can be used with the `transform` property. | ||
|
|
||
| ## Example 1: Rotating a Card left | ||
|
|
||
| In this example, a card element is rotated left along the Y-axis to create a spinning effect. The HTML code is: | ||
|
|
||
| ```html | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>RotateY Card Example</title> | ||
| </head> | ||
| <body> | ||
| <div class="card">Rotated Card</div> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| The CSS code is: | ||
|
|
||
| ```css | ||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| background-color: #f0f0f0; | ||
| } | ||
|
|
||
| .card { | ||
| width: 200px; | ||
| height: 120px; | ||
| background-color: #3498db; | ||
| color: white; | ||
| font-size: 20px; | ||
| font-weight: bold; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| transform: perspective(150) rotateY(30deg); | ||
| } | ||
| ``` | ||
|
|
||
| This example results in the following output: | ||
|
|
||
|  | ||
|
|
||
| ## Example 2: Interactive Turn on Hover | ||
|
|
||
| In this example, a card rotates left when hovered over, we use **`perspective()`** to give it more of a 3D affect highlighting the rotation. | ||
| The HTML code is: | ||
|
|
||
| ```html | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>RotateY Hover Animation</title> | ||
| </head> | ||
| <body> | ||
| <div class="turn-card">Hover Me</div> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| The CSS code is: | ||
|
|
||
| ```css | ||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| background-color: #ecf0f1; | ||
| } | ||
|
|
||
| .turn-card { | ||
| width: 150px; | ||
| height: 80px; | ||
| font-size: 18px; | ||
| font-weight: bold; | ||
| background-color: #e74c3c; | ||
| color: white; | ||
| border-radius: 8px; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| transition: transform 2s ease; | ||
| transform: perspective(150px); | ||
| } | ||
|
|
||
| .turn-card:hover { | ||
| transform: rotateY(180deg); | ||
| } | ||
| ``` | ||
|
|
||
| This example results in the following output: | ||
|
|
||
|  | ||
|
|
||
| ## Example 3: Image Panel Stack with 3D Rotation | ||
|
|
||
| In this example, multiple images are stacked and rotated along the Y-axis for a layered 3D effect. The HTML code is: | ||
|
|
||
| ```html | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>3D Image Stack</title> | ||
| </head> | ||
| <body> | ||
| <div class="image-stack"> | ||
| <div class="image-panel panel1">1</div> | ||
| <div class="image-panel panel2">2</div> | ||
| <div class="image-panel panel3">3</div> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| The CSS code is: | ||
|
|
||
| ```css | ||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: flex-start; | ||
| height: 100vh; | ||
| background: linear-gradient(120deg, #ff7e5f, #feb47b); | ||
| } | ||
|
|
||
| .image-stack { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 20px; | ||
| } | ||
|
|
||
| .image-panel { | ||
| width: 100px; | ||
| height: 100px; | ||
| background-color: #3498db; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| color: white; | ||
| font-size: 18px; | ||
| font-weight: bold; | ||
| border-radius: 6px; | ||
| transition: transform 0.5s ease; | ||
| } | ||
|
|
||
| .panel1 { | ||
| transform: rotateY(15deg); | ||
| } | ||
|
|
||
| .panel2 { | ||
| transform: rotateY(30deg); | ||
| } | ||
|
|
||
| .panel3 { | ||
| transform: rotateY(45deg); | ||
| } | ||
|
|
||
| .image-panel:hover { | ||
| transform: rotateY(60deg); | ||
| } | ||
| ``` | ||
|
|
||
| This example results in the following output: | ||
|
|
||
|  | ||
|
|
||
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.
Hey @JakevB88, if we look at the image we don't see the rotation. I feel we can add perspective, if we don't, it won’t produce true depth.
so, can you add that and upload the new output image?