Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotated elements overlap each other

Tags:

html

css

Is there a way to fix this, when I rotate 2 elements, they overlap each other because the width and height don't swap.

Thank you

https://jsfiddle.net/aez4uc3u/

a {
  display: block;
  transform: rotate(-90deg);
}
<div>
  <a href="#">This is the first link</a>
  <a href="#">This is the second link</a>
</div>
like image 210
MIkeMo Avatar asked Oct 29 '25 15:10

MIkeMo


2 Answers

Rotate the container and display the childs as inline-block seems to do the trick.

.container {
  transform: rotate(-90deg);
}

.container a {
  display:inline-block;
  margin: 0 5px;
}
<div class="container">
    <a href="#">This is the first link</a>
    <a href="#">This is the second link</a>
</div>
like image 162
Dexter0015 Avatar answered Oct 31 '25 05:10

Dexter0015


Rotate the parent.

a {
  display: block
}

div {
  transform: rotate(-90deg);
}
<div>
  <a href="#">This is the first link</a>
  <a href="#">This is the second link</a>
</div>

Positioning the div as you might like will take additional transforms and, perhaps, adjusting the transform-origin property.

You shoud also be aware that transform is purely visual. It does not actually affect the positioning or margins of elements.

like image 35
Paulie_D Avatar answered Oct 31 '25 04:10

Paulie_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!