rotateX()
The CSS The x-axis is the axis of rotation, so the element turns vertically. Imagine a pin is stuck to the left side of an element and it can only turn up or down. In the demo below, The The The In this demo, we have two sliders to control the In the absence of It’s also worth setting One of the most popular uses of To set the stage and give the card a projection value and 3D presence, we set the Then we position the front and back faces of the card absolutely within the container while setting Next, we pre-rotate the back face by 180 degrees, so it is ready to be revealed when the card flips And, finally, we flip the card when the parent is We can also create engaging loading indicators with the In this example, we’re not only using the Once again, we give the element’s parent a Then, we apply the animation to the element using the CSS Next, we define the keyframe, which dictates how the element rotates from one point to another. The order in which the Let’s skip the boring accordion component content reveal animation and make ours a bit interesting. We can enhance traditional accordions by adding a subtle Once again, as usual, we set the perspective on the parent Then, we define the Also, we can change the default rotation axis from the center to the top using The As the accordion opens, the By default, the The CSS The rotateX() function rotates an element around the x-axis in a three-dimensional space. Specifically, it vertically flips the element, making it tilt backward or forward, depending on the angle set. It is one of many transform functions used in the transform property.rotateX(0) is given as the element’s default rotation:.demo-element { transform: rotateY(var(--deg)); transition: transform 0.3s ease;}rotateX() function is defined in the CSS Transforms Module Level 2 specification.Syntax
rotateX() = rotateX( [ <angle>| <zero>] )Arguments
/* angle in degrees */rotateX(45deg) /* rotates 45 degrees backwards */rotateX(-90deg) /* rotates 90 degrees forwards *//* angle in turns */rotateX(0.5turn) /* rotates 180 degrees (half a full turn) */rotateX(1turn) /* Rotates a full 360-degree turn *//* angle in radians */rotateX(1.57rad) /* Approximately 90 degrees *//* angle in gradians */rotate(200grad) /* rotates 180 degrees */rotateX() function takes a single <angle> argument, which defines how much the element is rotated around its vertical axis.<angles>:values like 45deg, 0.5turn, -90deg, 1.57rad, etc. can be passed.<angle> type can be one of four units:deg:One degree is 1/360 of a full circle.grad:One gradian is 1/400 of a full circle.rad:A radian is the length of a circle’s diameter around the shape’s arc. One radian is 180deg, or 1/2 of a full circle. One full circle is 2π radians, which is equal to 6.2832rad or 360deg.turn:One turn is one full circle. So, halfway around a circle is equal to .5turn, or 180deg.Setting up 3D transforms
rotateX() is part of the CSS 3D transform functions, so it’s better represented in a 3D view. For rotateX() to produce a visible 3D effect, you need to set the perspective property on the parent element. The perspective property determines how the element is projected, adding depth to the element and making it look natural and 3D.rotateX() degree and perspective property.perspective, the element looks oddly skewed and ugly.
transform-style to preserve-3d, which determines if that element’s children are positioned in 3D space or flattened.Basic usage
rotateX() is creating flip cards that reveal content on the back when clicked or hovered. You can use this technique for pricing tables, profile cards, or interactive galleries.perspective and preserve-3d styles on the parent elements..flip-card { perspective: 1000px;}.flip-card-inner { transform-style: preserve-3d; transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);}backface-visibility to hidden:.flip-card-front,.flip-card-back { position: absolute; backface-visibility: hidden;}.flip-card-back { transform: rotateX(180deg);}:hover-ed:.flip-card:hover .flip-card-inner { transform: rotateX(180deg);}Example: 3D Loading spinner
rotateX() function..rotateX() function, but we’re combining it with the rotateY() function for a two-axis rotation animation. By continuously rotating an element horizontally and vertically, we create a 3D spinning effect.perspective:.spinner-wrapper { perspective: 1000px; margin-bottom: 2rem;}animation shorthand property..spinner { width: 80px; height: 80px; animation: spin-3d 2s ease-in-out infinite;}@keyframes spin-3d { 0% { transform: rotateX(0deg) rotateY(0deg); } 25% { transform: rotateX(180deg) rotateY(90deg); } 50% { transform: rotateX(180deg) rotateY(180deg); } 75% { transform: rotateX(360deg) rotateY(270deg); } 100% { transform: rotateX(360deg) rotateY(360deg); }}transform functions are defined is important. The effect of the first function comes to life before the second, so at 25%the element flips halfway horizontally before the vertical flip, and the animation is so smooth you hardly notice it.Example: 3D accordion
rotateX() rotation when items expand or collapse, creating a more staggered fall effect that further engages the user and improves the experience, rather than the simple slide-down-and-back-up animation..accordion-item { perspective: 1000px;}transform and transform-origin. Since we want the .accordion-content to fall toward the user, we use a negative 90° angle to shift the element out of the user’s view.transfom-origin: top;.accordion-content { transform-origin: top; transform: rotateX(-90deg); overflow: hidden; transition: transform 0.4s ease, opacity 0.3s ease, max-height 0.4s ease;}transform-origin:top ensures the rotation occurs from the top edge, making it look like a door opening downward, while rotateX(-90deg) makes the content appear to unfold into view..accordion-content element falls in a staggered manner to 0 degrees, which is the default position..accordion-item.open .accordion-content { transform: rotateX(0deg); opacity: 1; max-height: 500px;}A note about
transform-originand rotateX()rotateX() function rotates an element around its center. However, you can change this rotation axis using the CSS transform-origin property. transform-origin lets you change the point of origin of any transform function, so rather than being restricted to center, you can use top center, top right, bottom left, or even percentages and lengths..child { transform: rotateX(120deg); transform-origin: top center;}Specification
rotateX() function is defined in the CSS Transforms Module Level 2 draft.Browser Support
rotateX() function has baseline support on all modern browsers.Related
transform rotate()
.element { transform: rotate(45deg); }
Gabriel Shoyombo transform rotateY()
.element { transform: rotateY(30deg); }
Gabriel Shoyombo transform rotateZ()
.element { transform: rotateZ(90deg); }
Gabriel Shoyombo perspective
.element { perspective: 1000px; }
Chris Coyier transform
.element { transform: scale(2); }
Sara Cope transform transform-origin transform-origin
.element { transform-origin: top left; }
Chris Coyier transform-style
.element { transform-style: preserve-3d; }
Chris Coyier
- 最近发表
-
- CSS Transform Handbook – Complete Guide to CSS Transform Functions and Properties
- Open Source Tools Every STEM Student Should Know About
- How to Scale Laravel Applications for High
- How to Start your Career in Tech with freeCodeCamp
- How to Ship a Production
- The REST API Handbook – How to Build, Test, Consume, and Document REST APIs
- Database Version Control with Liquibase and Spring Boot
- How to Start your Career in Tech with freeCodeCamp
- Command Line for Beginners – How to Use the Terminal Like a Pro [Full Handbook]
- How to Optimize Enterprise Knowledge Graphs for Scalable Digital Product Platforms
- 随机阅读
-
- How to Center Any Element in CSS: 7 Methods That Always Work
- How Attribute
- How to Optimize Enterprise Knowledge Graphs for Scalable Digital Product Platforms
- How to Build a PostgreSQL
- Payment Gateway Integration
- The GraphQL API Handbook – How to Build, Test, Consume and Document GraphQL APIs
- How to Scale Laravel Applications for High
- How Attribute
- Md Tarikul Islam
- Command Line for Beginners – How to Use the Terminal Like a Pro [Full Handbook]
- Database Version Control with Liquibase and Spring Boot
- How to Scale Laravel Applications for High
- Learn TypeScript – A Handbook for Developers
- How to Start your Career in Tech with freeCodeCamp
- Database Version Control with Liquibase and Spring Boot
- Learn JavaScript for Beginners – JS Basics Handbook
- How to Become a Full
- How Attribute
- Backend Challenges Teams Face When Processing Repeat Payments
- How Attribute
- 搜索
-