Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

translateX overrides translateY

Tags:

html

css

flexbox

I'm trying to make different classes for alignment.

I want to be able to combine it like class="left bottom" using the transform:translate property.

The problem is that the property is being overridden by each other.

If you have a look at my fiddle and open up the debugger you will notice that translateX(50%) has been overridden by translateY(25%). Shouldn't they be combined like translate(50%,25%)?

.container {
  background: gray;
  height: 100px;
  width: 100%;
}
.left {
  transform: translateX(50%);
}
.bottom {
  transform: translateY(25%);
}
<div class="container">
  <div class="left bottom">
    I should be aligned
  </div>
</div>

https://jsfiddle.net/r2LmfqLs

like image 459
Sandro Avatar asked Sep 17 '25 14:09

Sandro


1 Answers

This is perfectly correct, because you are changing the transform parameter.

You have to nest them:

.left.bottom {
    transform: translateX(50%) translateY(25%);
}

Or combine them to one class:

.left-bottom {
    transform: translateX(50%) translateY(25%);
}
like image 117
Michael Czechowski Avatar answered Sep 19 '25 04:09

Michael Czechowski