Home

# Library goog.style

Function Summary
| `clearTransparentBackgroundImage(?Element el)` Clears the background image of an element in a browser independent manner.

`getBackgroundColor(?Element element) ⇒ string`

Retrieves the computed background color string for a given element. The string returned is suitable for assigning to another element's background-color, but is not guaranteed to be in any particular string format. Accessing the color in a numeric form may not be possible in all browsers or with all input. If the background color for the element is defined as a hexadecimal value, the resulting string can be parsed by goog.color.parse in all supported browsers. Whether named colors like "red" or "lightblue" get translated into a format which can be parsed is browser dependent. Calling this function on transparent elements will return "transparent" in most browsers or "rgba(0, 0, 0, 0)" in WebKit.

| `getBorderBox(?Element element) ⇒ !goog.math.Box` Gets the computed border widths (on all sides) in pixels
| `getBorderBoxSize(?Element element) ⇒ !goog.math.Size` Gets the border box size for an element.

`getBoundingClientRect_(?Element el) ⇒ ?Object`

Gets the client rectangle of the DOM element. getBoundingClientRect is part of a new CSS object model draft (with a long-time presence in IE), replacing the error-prone parent offset computation and the now-deprecated Gecko getBoxObjectFor. This utility patches common browser bugs in getClientBoundingRect. It will fail if getClientBoundingRect is unsupported. If the element is not in the DOM, the result is undefined, and an error may be thrown depending on user agent.

| `getBounds(?Element element) ⇒ !goog.math.Rect` Returns a bounding rectangle for a given element in page space.
| `getBox_(?Element element, string stylePrefix) ⇒ !goog.math.Box` Gets the computed paddings or margins (on all sides) in pixels.
| `getCascadedStyle(?Element element, string style) ⇒ string` Gets the cascaded style value of a node, or null if the value cannot be computed (only Internet Explorer can do this).
| `getClientLeftTop(?Element el) ⇒ !goog.math.Coordinate` Returns clientLeft (width of the left border and, if the directionality is right to left, the vertical scrollbar) and clientTop as a coordinate object.
| `getClientPosition((Element|Event|goog.events.Event|null) el) ⇒ !goog.math.Coordinate` Returns the position of the event or the element's border box relative to the client viewport.
| `getClientViewportElement(?Node= opt_node) ⇒ ?Element` Returns the viewport element for a particular document
| `getComputedCursor(?Element element) ⇒ string` Retrieves the computed value of the cursor CSS attribute.
| `getComputedOverflowX(?Element element) ⇒ string` Retrieves the computed value of the overflow-x CSS attribute.
| `getComputedOverflowY(?Element element) ⇒ string` Retrieves the computed value of the overflow-y CSS attribute.
| `getComputedPosition(?Element element) ⇒ string` Retrieves the computed value of the position CSS attribute.
| `getComputedStyle(?Element element, string property) ⇒ string` Retrieves a computed style value of a node. It returns empty string if the value cannot be computed (which will be the case in Internet Explorer) or "none" if the property requested is an SVG one and it has not been explicitly set (firefox and webkit).
| `getComputedTextAlign(?Element element) ⇒ string` Retrieves the computed value of the text-align CSS attribute.
| `getComputedZIndex(?Element element) ⇒ (number|string)` Retrieves the computed value of the z-index CSS attribute.
| `getContentBoxSize(?Element element) ⇒ !goog.math.Size` Gets the content box size for an element. This is potentially expensive in all browsers.
| `getFloat(?Element el) ⇒ string` Gets value of explicitly-set float CSS property on an element.
| `getFontFamily(?Element el) ⇒ string` Returns the font face applied to a given node. Opera and IE should return the font actually displayed. Firefox returns the author's most-preferred font (whether the browser is capable of displaying it or not.)
| `getFontSize(?Element el) ⇒ number` Returns the font size, in pixels, of text in an element.
| `getFramedPageOffset(?Element el, ?Window relativeWin) ⇒ !goog.math.Coordinate` Returns a Coordinate object relative to the top-left of an HTML document in an ancestor frame of this element. Used for measuring the position of an element inside a frame relative to a containing frame.
| `getIePixelBorder_(?Element element, string prop) ⇒ number` Helper function for IE to get the pixel border.
| `getIePixelDistance_(?Element element, string propName) ⇒ number` Helper function for getting the pixel padding or margin for IE.
| `getIePixelValue_(?Element element, string value, string name, string pixelName) ⇒ number` IE specific function that converts a non pixel unit to pixels.
| `getLengthUnits(string value) ⇒ ?string` Returns the units used for a CSS length measurement.
| `getMarginBox(?Element element) ⇒ !goog.math.Box` Gets the computed margins (on all sides) in pixels.
| `getOffsetParent(?Element element) ⇒ ?Element` Returns the first parent that could affect the position of a given element.
| `getOpacity(?Element el) ⇒ (number|string)` Gets the opacity of a node (x-browser). This gets the inline style opacity of the node, and does not take into account the cascaded or the computed style for this node.
| `getPaddingBox(?Element element) ⇒ !goog.math.Box` Gets the computed paddings (on all sides) in pixels.

`getPageOffset(?Element el) ⇒ !goog.math.Coordinate`

Returns a Coordinate object relative to the top-left of the HTML document. Implemented as a single function to save having to do two recursive loops in opera and safari just to get both coordinates. If you just want one value do use goog.style.getPageOffsetLeft() and goog.style.getPageOffsetTop(), but note if you call both those methods the tree will be analysed twice.

| `getPageOffsetLeft(?Element el) ⇒ number` Returns the left coordinate of an element relative to the HTML document
| `getPageOffsetTop(?Element el) ⇒ number` Returns the top coordinate of an element relative to the HTML document
| `getPixelStyleValue_((number|string) value, boolean round) ⇒ string` Helper function to create a string to be set into a pixel-value style property of an element. Can round to the nearest integer value.
| `getPosition(?Element element) ⇒ !goog.math.Coordinate` Gets the offsetLeft and offsetTop properties of an element and returns them in a Coordinate object
| `getRelativePosition((Element|Event|goog.events.Event|null) a, (Element|Event|goog.events.Event|null) b) ⇒ !goog.math.Coordinate` Returns the position of an element relative to another element in the document. A relative to B
| `getScrollbarWidth(string= opt_className) ⇒ number` Returns the scroll bar width (represents the width of both horizontal and vertical scroll).
| `getSize(?Element element) ⇒ !goog.math.Size` Gets the height and width of an element, even if its display is none. Specifically, this returns the height and width of the border box, irrespective of the box model in effect.
| `getSizeWithDisplay_(?Element element) ⇒ !goog.math.Size` Gets the height and with of an element when the display is not none.
| `getStyle(?Element element, string property) ⇒ string` Retrieves an explicitly-set style value of a node. This returns '' if there isn't a style attribute on the element or if this style property has not been explicitly set in script.
| `getStyle_(?Element element, string style) ⇒ string` Cross-browser pseudo get computed style. It returns the computed style where available. If not available it tries the cascaded style value (IE currentStyle) and in worst case the inline style value. It shouldn't be called directly, see http://wiki/Main/ComputedStyleVsCascadedStyle for discussion.
| `getVisibleRectForElement(?Element element) ⇒ ?goog.math.Box` Calculates and returns the visible rectangle for a given element. Returns a box describing the visible portion of the nearest scrollable offset ancestor. Coordinates are given relative to the document.
| `installStyles(string stylesString, ?Node= opt_node) ⇒ (Element|StyleSheet|null)` Installs the styles string into the window that contains opt_element. If opt_element is null, the main window is used.
| `isElementShown(?Element el) ⇒ boolean` Test whether the given element has been shown or hidden via a call to {@link #showElement}. Note this is strictly a companion method for a call to {@link #showElement} and the same caveats apply; in particular, this method does not guarantee that the return value will be consistent with whether or not the element is actually visible.
| `isRightToLeft(?Element el) ⇒ boolean` Returns true if the element is using right to left (rtl) direction.
| `isUnselectable(?Element el) ⇒ boolean` Returns true if the element is set to be unselectable, false otherwise. Note that on some platforms (e.g. Mozilla), even if an element isn't set to be unselectable, it will behave as such if any of its ancestors is unselectable.
| `parseStyleAttribute(string value) ⇒ !Object` Parses a style attribute value. Converts CSS property names to camel case.
| `scrollIntoContainerView(?Element element, ?Element container, boolean= opt_center)` Changes the scroll position of {@code container} with the minimum amount so that the content and the borders of the given {@code element} become visible. If the element is bigger than the container, its top left corner will be aligned as close to the container's top left corner as possible.
| `setBorderBoxSize(?Element element, ?goog.math.Size size)` Sets the border box size of an element. This is potentially expensive in IE if the document is CSS1Compat mode
| `setBoxSizingSize_(?Element element, ?goog.math.Size size, string boxSizing)` Helper function that sets the box sizing as well as the width and height
| `setContentBoxSize(?Element element, ?goog.math.Size size)` Sets the content box size of an element. This is potentially expensive in IE if the document is BackCompat mode.
| `setFloat(?Element el, string value)` Sets CSS float property on an element.
| `setHeight(?Element element, (number|string) height)` Set the height of an element. Sets the element's style property.
| `setInlineBlock(?Element el)` Sets 'display: inline-block' for an element (cross-browser).
| `setOpacity(?Element el, (number|string) alpha)` Sets the opacity of a node (x-browser).
| `setPageOffset(?Element el, (goog.math.Coordinate|null|number) x, number= opt_y)` Moves an element to the given coordinates relative to the client viewport.
| `setPosition(?Element el, (goog.math.Coordinate|null|number|string) arg1, (number|string=) opt_arg2)` Sets the top/left values of an element. If no unit is specified in the argument then it will add px.
| `setPreWrap(?Element el)` Sets 'white-space: pre-wrap' for a node (x-browser). There are as many ways of specifying pre-wrap as there are browsers. CSS3/IE8: white-space: pre-wrap; Mozilla: white-space: -moz-pre-wrap; Opera: white-space: -o-pre-wrap; IE6/7: white-space: pre; word-wrap: break-word;

`setSize(?Element element, (goog.math.Size|null|number|string) w, (number|string=) opt_h)`

Sets the width/height values of an element. If an argument is numeric, or a goog.math.Size is passed, it is assumed to be pixels and will add 'px' after converting it to an integer in string form. (This just sets the CSS width and height properties so it might set content-box or border-box size depending on the box model the browser is using.)

`setStyle(?Element element, (Object|null|string) style, (boolean|number|string=) opt_value)`

Sets a style value on an element. This function is not indended to patch issues in the browser's style handling, but to allow easy programmatic access to setting dash-separated style properties. An example is setting a batch of properties from a data object without overwriting old styles. When possible, use native APIs: elem.style.propertyKey = 'value' or (if obliterating old styles is fine) elem.style.cssText = 'property1: value1; property2: value2'.

| `setStyle_(?Element element, (boolean|number|string|undefined) value, string style)` Sets a style value on an element, with parameters swapped to work with {@code goog.object.forEach()}.
| `setStyles((Element|StyleSheet|null) element, string stylesString)` Sets the content of a style element. The style element can be any valid style element. This element will have its content completely replaced by the new stylesString.

`setTransparentBackgroundImage(?Element el, string src)`

Sets the background of an element to a transparent image in a browser- independent manner. This function does not support repeating backgrounds or alternate background positions to match the behavior of Internet Explorer. It also does not support sizingMethods other than crop since they cannot be replicated in browsers other than Internet Explorer.

| `setUnselectable(?Element el, boolean unselectable, boolean= opt_noRecurse)` Makes the element and its descendants selectable or unselectable. Note that on some platforms (e.g. Mozilla), even if an element isn't set to be unselectable, it will behave as such if any of its ancestors is unselectable.
| `setWidth(?Element element, (number|string) width)` Set the width of an element. Sets the element's style property.

`showElement(?Element el, <Any Type> display)`

Shows or hides an element from the page. Hiding the element is done by setting the display property to "none", removing the element from the rendering hierarchy so it takes up no space. To show the element, the default inherited display property is restored (defined either in stylesheets or by the browser's default style rules.) Caveat 1: if the inherited display property for the element is set to "none" by the stylesheets, that is the property that will be restored by a call to showElement(), effectively toggling the display between "none" and "none". Caveat 2: if the element display style is set inline (by setting either element.style.display or a style attribute in the HTML), a call to showElement will clear that setting and defer to the inherited style in the stylesheet.

| `toCamelCase(<Any Type> selector) ⇒ string` Converts a CSS selector in the form style-property to styleProperty.
| `toSelectorCase(string selector) ⇒ string` Converts a CSS selector in the form styleProperty to style-property.
| `toStyleAttribute(?Object obj) ⇒ string` Reverse of parseStyleAttribute; that is, takes a style object and returns the corresponding attribute value. Converts camel case property names to proper CSS selector names.
| `translateRectForAnotherFrame(?goog.math.Rect rect, ?goog.dom.DomHelper origBase, ?goog.dom.DomHelper newBase)` Translates the specified rect relative to origBase page, for newBase page. If origBase and newBase are the same, this function does nothing.
| `uninstallStyles((Element|StyleSheet|null) styleSheet)` Removes the styles added by {@link #installStyles}.