CSS Property: background-origin
[this page | pdf | back links]
The CSS (CSS3) background-origin property specifies
where the background image for an element is positioned. If the background-attachment
property is set to "fixed" then the background-origin property has no
effect.
Valid property values
(other than inherit
and initial) are:
Value
|
Description
|
border-box
|
Background image starts
from the upper-left corner of the border
|
content-box
|
Background image starts
from the upper-left corner of the content
|
padding-box
|
(default value).
Background image starts from the upper-left corner of the padding edge
|
Default Value:
|
padding-box
|
JavaScript syntax:
|
e.g. object.style.backgroundOrigin="content-box"
|
Inherited:
|
No
|
Animatable:
|
No
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 200px; background-image: url(NematrianLogo.png); padding: 20px;}
p.x1 {background-origin: content-box;}
</style>
</head>
<body>
1. Element with default property<br>
<p>1</p><br>
2. Element set using in-file HTML style
<p class="x1">2</p><br>
3. Element set using JavaScript
<p id="x2">3</p>
<script>
document.getElementById("x2").style.backgroundOrigin =
"content-box";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBackgroundOrigin() {
var x = document.createElement("DIV"); x.style.backgroundOrigin = "content-box"; return (window.getComputedStyle(x, null).backgroundOrigin == "content-box");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties