Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a series of 3 SVG elements inside a wrapper element and I have rotated this wrapper by -90 deg with a CSS transform.

I'm trying to get it so the yellow containing block is pinned to the left of the screen, so I can then alter how far from the left (% or vw) this yellow wrapper sits.

I can't for the life of me get it stick to the left - the transform seems to be making everything a lot harder. I need it so that even if the window is resized it stays a set % (or vw) from the far left - for arguments sake say 5% / 5vw.

P.S I'm using SVG text because it's part of a clip-path animation, but I have removed this code to make things easier to read.

codepen[^]

What I have tried:

CSS

body {
  margin: 0; 
  width: 100%; 
  height: 100vh;
  position: relative;
}

#wrapper {
  display: flex;
  justify-content: center;
  background: yellow;
  transform: rotate(-90deg);
  position: absolute;
  left: 0;
}

#wrapper svg {margin: 1rem}
text {font-size: 1rem}


HTML

<!-- THIS IS THE YELLOW BLOCK CONTAINING THE SVG ELEMENTS -->
<div id="wrapper">

  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="40" viewBox="0 0 120 40">
    <rect class="masker" x="0" y="0" width="120" height="40" fill="red" />
    <text x="16" y="25" fill="white">Some Text 1</text>
  </svg>

  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="40" viewBox="0 0 120 40">
    <rect class="masker" x="0" y="0" width="120" height="40" fill="red" />
    <text x="16" y="25" fill="white">Some Text 2</text>
  </svg>

  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="40" viewBox="0 0 120 40">
    <rect class="masker" x="0" y="0" width="120" height="40" fill="red" />
    <text x="16" y="25" fill="white">Some Text 3</text>
  </svg>
  
</div>
Posted
Updated 23-Mar-18 7:58am
v2

1 solution

Fairly simple - you just need to set the transform-origin[^] to "top left", and translate[^] the result:
CSS
#wrapper {
  ...
  transform: rotate(-90deg) translate(-100%, 0);
  transform-origin: top left;
  ...
}

Pin Rotated Container to the Left of Parent - forked[^]

An attempt to explain what's going on:
CSS rotation + alignment[^]
Click on the blocks under "Rotated" and "Translated" to see a simple animation of the CSS transformations.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900