CSS Property: transform-origin
[this page | pdf | back links]
The CSS (CSS3) transform-origin property defines the
origin used by the transform
property.
Valid property values
(other than inherit
and initial) are:
Value
|
Description
|
x-axis y-axis z-axis
|
Origin defined by three
values, where:
x-axis can be:
-
length (a CSS
length)
-
% (of overall element size)
-
left (origin x-coordinate
at left end of element)
-
centre (origin x-coordinate
at centre of element)
-
right (origin x-coordinate
at right end of element)
y-axis can be:
-
length (a CSS
length)
-
% (of overall element size)
-
bottom (origin y-coordinate
at bottom end of element)
-
centre (origin y-coordinate
at centre of element)
-
top (origin y-coordinate
at right end of element)
z-axis can be:
-
length (a CSS
length)
|
Default Value:
|
50% 50% 0
|
JavaScript syntax:
|
e.g. object.style.transformOrigin="0 0"
|
Inherited:
|
No
|
Animatable:
|
Yes
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div.x {width: 180px; height: 50px; border: thin solid green; margin: 30px; position: relative;}
div.y {background-color: orange; border: 3px solid blue; position: absolute; height: 50px;
transform: rotate(5deg)}
div.y1 {background-color: orange; border: 3px solid blue; position: absolute; height: 50px;
transform: rotate(5deg);
transform-origin: 0% 0%;}
</style>
</head>
<body>
<div class="x">
<div class="y">Element with default property</div>
</div>
<div class="x">
<div class="y1">Element with property set by HTML</div>
</div>
<div class="x">
<div id="y2">Element with property set by JavaScript</div>
</div>
<script>
var x = document.getElementById("y2");
x.style = "background-color: orange; border: 3px solid blue; position: absolute; height: 50px; transform: rotate(5deg);";
x.style.transformOrigin = "0% 0%";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyTransformOrigin() {
var x = document.createElement("DIV"); x.style.transformOrigin = "0% 0%"; return (window.getComputedStyle(x, null).transformOrigin == "0% 0%");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties