Javascript DOM CSS Style transformStyle Property

Introduction

Let the transformed child elements preserve the 3D transformations:

document.getElementById("myDIV").style.transformStyle = "preserve-3d";

Click the button to preserve the 3D position of the child elements of the DIV2 element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#DIV1 {/*ww  w . ja  va2 s . c o  m*/
  position: relative;
  height: 200px;
  width: 200px;
  margin: 100px;
  padding: 10px;
  border: 1px solid black;
}

#DIV2 {
  padding: 50px;
  position: absolute;
  border: 1px solid black;
  background-color: coral;
  transform: rotateY(50deg);
}

#DIV3 {
  padding: 40px;
  position: absolute;
  border: 1px solid black;
  background-color: red;
  transform: rotateY(70deg);
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="DIV1">DIV1
  <div id="DIV2">HELLO DIV2
  <div id="DIV3">HELLO DIV3</div>
  </div>
</div>

<script>
function myFunction() {
  document.getElementById("DIV2").style.transformStyle = "preserve-3d";
}
</script>
</body>
</html>

The transformStyle property sets or get how nested elements are rendered in 3D space.

This property must be used together with the transform property.

Property Values

Value Description
flatDefault. The child elements will NOT preserve its 3D position
preserve-3d The child elements will preserve its 3D position
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The transformStyle property returns a String representing the transform-style property of an element.




PreviousNext

Related