CSS rotate and postion on left top Corner

2019-01-29 05:19发布

I rotated a div with Text & wanted to Place it on the left top. I managed to place it at the top, but I can't get it working to align with the left edge. How do I do this?

.credit {
  position: absolute;
  background-color: pink;
  transform: rotate(-90deg) translateX(-50%);
}
<div class="credit">
  Picture by Name
</div>

1条回答
冷血范
2楼-- · 2019-01-29 05:55

Change the transform-origin to top left and make the translation -100%

body {
 margin:0;
}

.credit {
  transform-origin: top left;
  position: absolute;
  background-color: pink;
  transform: rotate(-90deg) translateX(-100%);
}
<div class="credit">
  Picture by Name
</div>

查看更多
登录 后发表回答