CSSUnitValue
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}
The **CSSUnitValue** interface of the CSS Typed Object Model API represents values that contain a single unit type.
For example, the value 42px (a {{cssxref("<dimension>")}}) would be represented by a CSSNumericValue.
{{InheritanceDiagram}}
Constructor
- {{domxref("CSSUnitValue.CSSUnitValue", "CSSUnitValue()")}}
- : Creates a new
CSSUnitValueobject.
Instance properties
- {{domxref('CSSUnitValue.value')}}
- : A number representing the number of units.
For a CSSNumericValue representing 42px, this would be 42.
- {{domxref('CSSUnitValue.unit')}} {{ReadOnlyInline}}
- : Returns a string indicating the type of unit. For a
CSSNumericValuerepresenting42px, this would be"px".
Static methods
_Also inherits methods from its parent interface, {{DOMxRef("CSSNumericValue")}}._
Instance methods
_Also inherits methods from its parent interface, {{DOMxRef("CSSNumericValue")}}._
Examples
Basic usage
The following shows a method of creating a {{domxref('CSSPositionValue')}} from individual CSSUnitValue constructors.
let pos = new CSSPositionValue(
new CSSUnitValue(5, "px"),
new CSSUnitValue(10, "px"),
);Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- CSS numeric data types
- CSS values and units, a listing of all possible units and data types