Home  >  Article  >  Web Front-end  >  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
Barbara StreisandOriginal
2024-11-10 19:13:02536browse

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%);
}

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%);
}

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!

Statement:
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