The translateX function

The translateX function sets an element reposition along the X-axis. It is used together with the transform property. The property value is any size units. A positive value shifts to the right, a negative value shifts to the left.

Syntax

cssselector {
  transform: translateX(reposition);
}

Example

If you hover over the block, it will move 30px to the right:

html<div id="elem"></div>
css#elem {
  border: 1px solid black;
  width: 100px;
  height: 50px;
}
#elem:hover {
  transform: translateX(30px);
}

Результат:

Example

If you hover over the block, it will move 30px to the left:

html<div id="elem"></div>
css#elem {
  border: 1px solid black;
  width: 100px;
  height: 50px;
}
#elem:hover {
  transform: translateX(-30px);
}

Результат:

See also

  • the translate function
    that specifies a reposition along the X- and Y-axes
  • the translateY function
    that specifies a reposition along the Y-axis