ObsoleteThis feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
The CSSPositionValue
interface of the the CSS Typed Object Model API represents values for properties that take a position, for example object-position
.
Constructor
CSSPositionValue.CSSPositionValue()
- Creates a new
CSSPositionValue
object.
Properties
CSSPositionValue.x
- Returns the item's position along the web page's horizontal axis.
CSSPositionValue.y
- Returns the item's position along the vertical axis.
Methods
None.
Examples
The following example positions a container <div>
5 pixels from the top and 10 pixels from the left of the page.
let replacedEl = document.getElementById( 'image' );
let position = new CSSPositionValue( CSS.px(35), CSS.px(40) );
replacedEl.attributeStyleMap.set( 'object-position', position );
console.log( position.x.value, position.y.value );
console.log( replacedEl.computedStyleMap().get('object-position') );
We set the object-position
property, then check the values returned.
#image {
width: 300px;
height: 300px;
border: 1px solid black;
background-color: #dededf;
object-fit: none;
}
<p>Check the developer tools to see the log in the console and to inspect the style attribute on the image.</p>
<img id="image" src="https://mdn.mozillademos.org/files/12668/MDN.svg" alt="MDN Logo"/>
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 53 |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
No support No |
Opera Android
Full support 47 |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 53 |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
No support No |
Opera Android
Full support 47 |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 | |
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 53 |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
No support No |
Opera Android
Full support 47 |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 | |
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 53 |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
No support No |
Opera Android
Full support 47 |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
See Also
CSSImageValue
CSSKeywordValue
CSSNumericValue
CSSTransformValue
CSSUnparsedValue
- Using the CSS Typed OM
- CSS Typed Object Model API
CSSPositionValue by Mozilla Contributors is licensed under CC-BY-SA 2.5.