I have noticed, that right:0px
is positioning element incorrectly. transform:scale
doesn't recalculate element width.
Is there a way to properly stick this element to the right side?
HTML:
<div id="stick_me">
blah blah blah<br />
blah blah blah<br />
blah blah blah<br />
</div>
CSS:
#stick_me {
border:1px solid red;
display:inline-block;
transform:scale(3);
position:absolute;
right:0px;
top:0px;
}
Thank you.
Absolute Positioning You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
We can use CSS absolute positioning to overlap elements, but there's some advantages to using CSS grid instead.
You want to use the transform-origin
(https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin) property set to top right
. As you are positioning the element to the top and right, you need it to scale from there, i.e. down and to the left.
#stick_me {
border:1px solid red;
display:inline-block;
transform:scale(3);
position:absolute;
right:0px;
top:0px;
transform-origin:top right;
}
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With