CSS rotate and postion on left top Corner

倾然丶 夕夏残阳落幕 提交于 2020-01-10 05:43:10

问题


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:


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>


来源:https://stackoverflow.com/questions/49096139/css-rotate-and-postion-on-left-top-corner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!