css - working - absolute position rotated element to right corner




transform origin not working (2)

Ana's answer is excellent and pointed me in the right direction, but I realised you could achieve the same effect without having to explicitly set the height, line-height and position for the element you want to move - instead, just set translate(0, -100%):

body {
  margin: 0;
}

#box {
  position: relative;
}

.bg {
	right: 0;
	padding: 1em;
	transform: rotate(-90deg) translate(0, -100%);
	transform-origin: 100% 0;
	position: absolute;
	background: #FF1493;
}
<div id="box">
	<div class="bg">        
		<div class="txt">He's not the Messiah. He's a very naughty boy.</div>
	</div>
</div>

...and a jsFiddle for good measure.

Im trying to figure out how to make shopping cart tab that would be positioned on the right corner and also rotated 90 degrees. The rotation naturally mixes the position but maybe there's a workaround of wrapping to different wrappers etc....

Extra points if there wouldn't need to define width. I don't care about older browsers


How about using transform-origin? See DEMO.

Relevant CSS:

#box {
    position: relative;
}
.bg {
    right: 40px; /* same as height */
    height: 40px;
    transform: rotate(-90deg);
    transform-origin: 100% 0;
    position: absolute;
    line-height: 40px; /* same as height, for vertical centering */
}




css-transitions