Home > Web Front-end > CSS Tutorial > How to Rotate and Position an Element on the Top Left or Top Right Corner?

How to Rotate and Position an Element on the Top Left or Top Right Corner?

Barbara Streisand
Release: 2024-11-10 19:13:02
Original
562 people have browsed it

How to Rotate and Position an Element on the Top Left or Top Right Corner?

Rotating and Positioning an Element on the Top Left or Top Right Corner

To rotate a div with text and place it on the top left corner, the following code can be used:

.credit {
  transform-origin: top left;
  position: absolute;
  background-color: pink;
  transform: rotate(-90deg) translateX(-100%);
}
Copy after login

Here, the transform-origin property is set as top left which makes the rotation occur with respect to the top left corner. The translateX(-100%) translation moves the rotated element to the left by 100% of its width.

To align the element with the right edge, you can modify the translateX value to be positive, such as translateX(100%). This will move the rotated element to the right by 100% of its width.

.credit {
  transform-origin: top right;
  position: absolute;
  background-color: pink;
  transform: rotate(-90deg) translateX(100%);
}
Copy after login

The above is the detailed content of How to Rotate and Position an Element on the Top Left or Top Right Corner?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template