CSS transform-style Property
CSS transform-style Property
CSS transform-style
property specifies whether children of an element are positioned in the 3D space or are flattened in the plane of the element.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
div{
width: 100px;
height: 100px;
border: 1px solid #000;
}
#outer{
background: #f69d3c;
transform: perspective(200px) rotateY(30deg);
-webkit-transform: perspective(200px) rotateY(30deg);
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
}
#inner{
background: #0066ff;
-webkit-transform: rotate(70deg);
transform: rotate3d(1, 1, 1, 45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<div id="outer">OuterDiv
<div id="inner">InnerDiv</div>
</div>
</body>
</html>
Syntax
Using CSS
element{
transform-style: preserve-3d;
}
Using Javascript
object.style.transformStyle="preserve-3d";
Animatable
No, transform-style property is not animatable. CSS Animatable Properties Reference.
Default Value
Default value for CSS transform-style property is flat.
Property Value
The following table provides a list of values for CSS transform-style
property.
Value | Explanation |
---|
flat | Specifies that the children of the element are lying in the plane of the element itself. |
preserve-3d | Specifies that the children of the element should be positioned in the 3D-space. |
Using JavaScript
In the following example, we will demonstrate how to change the CSS transform-style
property of an element using JavaScript.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
div{
width: 100px;
height: 100px;
border: 1px solid #000;
}
#outer{
background: #f69d3c;
margin-bottom:50px;
transform: perspective(200px) rotateY(30deg);
-webkit-transform: perspective(200px) rotateY(30deg);
}
#inner{
background:#0066ff;
-webkit-transform: rotate(70deg);
transform: rotate3d(1, 1, 1, 45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<div id="outer">OuterDiv
<div id="inner">InnerDiv</div>
</div>
<button onclick="myFunction()">Click Me</button>
<script>
var x = document.getElementsByTagName("div")[0];
function myFunction(){
x.style.transformStyle = "preserve-3d";
x.style.WebkitTransformStyle = "preserve-3d";
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in CSS.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Share this Page
Meet the Author