エクスポート (0) 印刷
すべて展開
EN
このコンテンツは設定された言語で表示できません。英語版のページが表示されます。

style Object

Represents the current settings of all possible inline styles for a given element.

Members Table

The following table lists the members exposed by the style object.

Attributes/Properties
Attribute Property Description
aria-activedescendant ariaActivedescendant Gets or sets the currently active child element.
aria-busy ariaBusy Gets or sets a value indicating whether a live region is finished updating.
aria-checked ariaChecked Sets or retrieves the checked state of this element.
aria-controls ariaControls Gets or sets the list of elements that are controlled by the current element.
aria-describedby ariaDescribedby Gets or sets a list of elements that describe the current object.
aria-disabled ariaDisabled Sets or retrieves the disabled state of this element.
aria-expanded ariaExpanded Sets or retrieves the expanded state of this element.
aria-flowto ariaFlowto Gets or sets the recommended reading order of content.
aria-haspopup ariaHaspopup Sets or retrieves a value indicating whether this element may display a pop-up window.
aria-hidden ariaHidden Sets or retrieves the hidden state of this element.
aria-invalid ariaInvalid Sets or retrieves the error state of this element.
aria-labelledby ariaLabelledby Gets or sets a list of elements that provide a label for the current object.
aria-level ariaLevel Sets or retrieves the level of this element.
aria-live ariaLive Gets or sets how assistive technology should announce updates to live regions.
aria-multiselect ariaMultiselect Sets or retrieves the multiple-selection state of this element.
aria-owns ariaOwns Gets or sets a list of child objects, including elements that are not direct descendants of the current object.
aria-posinset ariaPosinset Sets or retrieves the current position of an item within a set.
aria-pressed ariaPressed Sets or retrieves the pressed state of a button that can be toggled.
aria-readonly ariaReadonly Sets or retrieves the read-only state of this element.
aria-relevant ariaRelevant Gets or sets which changes to a live region are relevant.
aria-required ariaRequired Sets or retrieves the form-completion requirement of this element.
aria-secret ariaSecret Sets or retrieves the secret state of this element.
aria-selected ariaSelected Sets or retrieves the selection state of this element.
aria-setsize ariaSetsize Sets or retrieves the set size of this element.
aria-valuemax ariaValuemax Gets or sets the maximum value that a user can provide.
aria-valuemin ariaValuemin Gets or sets the minimum value that a user can provide.
aria-valuenow ariaValuenow Gets or sets the current value of the element.
attributes Retrieves a collection of attributes of the object.
background-size New for Internet Explorer 9  backgroundSize Gets or sets the size of the background images.
background-size New for Internet Explorer 9  backgroundSize Gets or sets the size of the background images.
clipBottom New for Internet Explorer 9  Gets the bottom coordinate of the object clipping region.
clip-path New for Internet Explorer 9  clipPath Gets or sets a reference to the Scalable Vector Graphics (SVG) graphical object that will be used as the clipping path.
clip-rule New for Internet Explorer 9  clipRule Gets or sets a value that indicates a clipping rule.
constructor Returns a reference to the constructor of an object.
cssFloat New for Internet Explorer 9  Gets or sets a value that specifies whether a box should float to the left, right, or not at all.
length New for Internet Explorer 9  Gets the number of properties that are explicitly set on the parent object.
onOffBehavior Gets an object that indicates whether the specified Microsoft DirectAnimation behavior is running.
parentRule New for Internet Explorer 9  Gets the containing rule, if the current rule is contained inside another rule.
role role Sets or retrieves the role for this element.
text-anchor New for Internet Explorer 9  textAnchor Gets or sets a value that aligns a string of text relative to a given point.
Filters
Filter property Description
Alpha Adjusts the opacity of the content of the object.
BlendTrans Reveals new content of the object by fading the original content.
Chroma Displays a specific color of the content of the object as transparent.
DropShadow Creates a solid silhouette of the content of the object, offset in the specified direction. This creates the illusion that the content is floating and casting a shadow.
FlipH Displays the content of the object flipped across the horizontal axis.
FlipV Displays the content of the object flipped across the vertical axis.
Glow Adds radiance around the outside edges of the content of the object so that it appears to glow.
Gray Displays the content of the object in grayscale.
Invert Reverses the hue, saturation, and brightness values of the content of the object.
Light Creates the effect of a light shining on the content of the object.
MaskFilter Displays transparent pixels of the object content as a color mask, and makes the nontransparent pixels transparent.
MotionBlur Causes the content of the object to appear to be in motion.
Redirect Not supported.
RevealTrans Reveals new content of the object using one of 24 predefined Transition effects.
Shadow Creates a solid silhouette of the content of the object, offset in the specified direction. This creates the illusion of a shadow.
Wave Performs a sine wave distortion of the content of the object along the vertical axis.
Xray Changes the color depth of the content of the object and displays it in black and white.
Methods
Method Description
getAttribute Retrieves the value of the specified attribute.
getAttributeNode Retrieves an attribute object referenced by the attribute.name property.
getExpression Retrieves the expression for the given property.
getPropertyPriority New for Internet Explorer 9  Gets the priority of a Cascading Style Sheets (CSS) property if the priority is explicitly set in the current declaration block.
getPropertyValue New for Internet Explorer 9  Gets the value of a CSS property if it is explicitly set within the current declaration block.
hasAttribute Determines whether an attribute with the specified name exists.
item New for Internet Explorer 9  Gets a property that has been explicitly set in the current declaration block.
normalize Merges adjacent Document Object Model (DOM) objects to produce a normalized document object model.
removeAttribute Removes an attribute from an object.
removeAttributeNode Removes an attribute object from the object.
removeExpression Removes the expression from the specified property.
removeProperty New for Internet Explorer 9  Removes a CSS property if it is explicitly set within the current declaration block.
setAttribute Sets the value of the specified attribute.
setAttributeNode Sets an attribute object node as part of the object.
setExpression Sets an expression for the specified object.
setProperty New for Internet Explorer 9  Sets a property value and priority within the current declaration block.
Prototypes
Object Description
CSSStyleSheet Constructor Defines the properties and methods inherited by objects in the CSSStyleSheet Constructor prototype chain.
Styles
Style attribute Style property Description
-ms-accelerator accelerator Gets or sets a string that indicates whether the object represents a keyboard shortcut.
alignment-baseline New for Internet Explorer 9  alignmentBaseline Gets or sets how an inline-level element is aligned with respect to its parent.
background background Gets or sets up to five separate background properties of the object.
background-attachment backgroundAttachment Gets or sets how the background image is attached to the object within the document.
background-clip New for Internet Explorer 9  backgroundClip Gets or sets the background painting area.
background-clip New for Internet Explorer 9  backgroundClip Gets or sets the background painting area.
background-clip New for Internet Explorer 9  backgroundClip Gets or sets the background painting area.
background-color backgroundColor Gets or sets the color behind the content of the object.
background-image backgroundImage Gets or sets the background image of the object.
background-origin New for Internet Explorer 9  backgroundOrigin Gets or sets the background positioning area of a box or multiple boxes.
background-origin New for Internet Explorer 9  backgroundOrigin Gets or sets the background positioning area of a box or multiple boxes.
background-position backgroundPosition Sets or retrieves the position of the background of the object.
-ms-background-position-x backgroundPositionX Gets or sets the x-coordinate of the backgroundPosition property.
-ms-background-position-y backgroundPositionY Gets or sets the y-coordinate of the backgroundPosition property.
background-repeat backgroundRepeat Gets or sets how the backgroundImage property of the object is tiled.
baseline-shift New for Internet Explorer 9  baselineShift Gets or sets a value that indicates how the dominant baseline should be repositioned relative to the dominant baseline of the parent text content element.
-ms-behavior behavior Gets or sets the location of the Dynamic HTML (DHTML) behavior.
border border Sets or retrieves the properties to draw around the object.
border-bottom borderBottom Sets or retrieves the properties of the bottom border of the object.
border-bottom-color borderBottomColor Gets or sets the color of the bottom border of the object.
border-bottom-left-radius New for Internet Explorer 9  borderBottomLeftRadius Gets or sets one or two values that define the radii of the quarter ellipse that defines the shape of the lower-left corner for the outer border edge of the current box.
border-bottom-right-radius New for Internet Explorer 9  borderBottomRightRadius Gets or sets one or two values that define the radii of the quarter ellipse that defines the shape of the lower-right corner for the outer border edge of the current box.
border-bottom-style borderBottomStyle Gets or sets the style of the bottom border of the object.
border-bottom-width borderBottomWidth Gets or sets the width of the bottom border of the object.
border-collapse borderCollapse Gets or sets a value that indicates whether the row and cell borders of a table are joined in a single border or detached as in standard HTML.
border-color borderColor Gets or sets the border color of the object.
border-left borderLeft Sets or retrieves the properties of the left border of the object.
border-left-color borderLeftColor Gets or sets the color of the left border of the object.
border-left-style borderLeftStyle Gets or sets the style of the left border of the object.
border-left-width borderLeftWidth Gets or sets the width of the left border of the object.
border-radius New for Internet Explorer 9  borderRadius Gets or sets one or more values that define the radii of a quarter ellipse that defines the shape of the corners for the outer border edge of the current box.
border-right borderRight Sets or retrieves the properties of the right border of the object.
border-right-color borderRightColor Gets or sets the color of the right border of the object.
border-right-style borderRightStyle Gets or sets the style of the right border of the object.
border-right-width borderRightWidth Gets or sets the width of the right border of the object.
border-spacing borderSpacing Gets or sets the distance between the borders of adjoining cells in a table.
border-style borderStyle Gets or sets the style of the left, right, top, and bottom borders of the object.
border-top borderTop Sets or retrieves the properties of the top border of the object.
border-top-color borderTopColor Gets or sets the color of the top border of the object.
border-top-left-radius New for Internet Explorer 9  borderTopLeftRadius Gets or sets one or two values that define the radii of the quarter ellipse that defines the shape of the upper-left corner for the outer border edge of the current box.
border-top-right-radius New for Internet Explorer 9  borderTopRightRadius Gets or sets one or two values that define the radii of the quarter ellipse that defines the shape of the upper-right corner for the outer border edge of the current box.
border-top-style borderTopStyle Gets or sets the style of the top border of the object.
border-top-width borderTopWidth Gets or sets the width of the top border of the object.
border-width borderWidth Gets or sets the width of the left, right, top, and bottom borders of the object.
bottom bottom Gets or sets the bottom position of the object in relation to the bottom of the next positioned object in the document hierarchy.
box-shadow New for Internet Explorer 9  boxShadow Gets or sets a comma-separated list of shadows that attaches one or more drop shadows to the current box.
box-sizing boxSizing Gets or sets the box model to use for object sizing.
caption-side captionSide Gets or sets where the caption of a table is located.
clear clear Gets or sets whether the object allows floating objects on its left side, right side, or both, so that the next text displays past the floating objects.
clip clip Sets or retrieves which part of a positioned object is visible.
clipLeft New for Internet Explorer 9  Gets the left coordinate of the object clipping region.
clipRight New for Internet Explorer 9  Gets the right coordinate of the object clipping region.
clipTop New for Internet Explorer 9  Gets the top coordinate of the object clipping region.
color color Gets or sets the color of the text of the object.
content content Gets or sets generated content to insert before or after an element.
counter-increment counterIncrement Gets or sets a list of counters to increment.
counter-reset counterReset Gets or sets a list of counters to create or reset to zero.
cssText Gets or sets the persisted representation of the style rule.
cursor cursor Gets or sets the type of cursor to display as the mouse pointer moves over the object.
direction direction Gets or sets the reading order of the object.
display display Gets or sets whether the object is rendered.
dominant-baseline New for Internet Explorer 9  dominantBaseline Gets or sets a value that determines or redetermines a scaled-baseline table.
empty-cells emptyCells Determines whether to show or hide a cell without content.
fill New for Internet Explorer 9  fill Gets or sets a value that indicates the color to paint the interior of the given graphical element.
fill-opacity New for Internet Explorer 9  fillOpacity Gets or sets a value that specifies the opacity of the painting operation that is used to paint the interior of the current object.
fill-rule New for Internet Explorer 9  fillRule Gets or sets a value that indicates the algorithm that is to be used to determine what parts of the canvas are included inside the shape.
-ms-filter New for Internet Explorer 9  filter Gets or sets the filter or collection of filters that are applied to the object.
font font Sets or retrieves a combination of separate font properties of the object. Alternatively, sets or retrieves one or more of six user-preference fonts.
font-family fontFamily Gets or sets the name of the font used for text in the object.
font-size fontSize Gets or sets a value that indicates the font size used for text in the object.
font-size-adjust New for Internet Explorer 9  fontSizeAdjust Gets or sets a value that specifies an aspect value for an element that will effectively preserve the x-height of the first choice font, whether it is substituted or not.
font-stretch New for Internet Explorer 9  fontStretch Gets or sets a value that indicates a normal, condensed, or expanded face of a font family.
font-stretch New for Internet Explorer 9  fontStretch Gets or sets a value that indicates a normal, condensed, or expanded face of a font family.
font-style fontStyle Gets or sets the font style of the object as italic, normal, or oblique.
font-variant fontVariant Gets or sets whether the text of the object is in small capital letters.
font-weight fontWeight Gets or sets the weight of the font of the object.
glyph-orientation-horizontal New for Internet Explorer 9  glyphOrientationHorizontal Gets or sets a value that alters the orientation of a sequence of characters relative to an inline-progression-direction of horizontal.
glyph-orientation-vertical New for Internet Explorer 9  glyphOrientationVertical Gets or sets a value that alters the orientation of a sequence of characters relative to an inline-progression-direction of vertical.
height height Gets or sets the height of the object.
-ms-ime-mode imeMode Gets or sets the state of an Input Method Editor (IME).
kerning New for Internet Explorer 9  kerning Gets or sets a value that indicates whether Internet Explorer should adjust inter-glyph spacing based on kerning tables that are included in the relevant font (that is, enable auto-kerning) or instead disable auto-kerning and set inter-character spacing to a specific length (typically zero).
-ms-layout-flow layoutFlow Gets or sets the direction and flow of the content in the object.
-ms-layout-grid layoutGrid Sets or retrieves the composite document grid properties that specify the layout of text characters.
-ms-layout-grid-char layoutGridChar Gets or sets the size of the character grid used for rendering the text content of an element.
-ms-layout-grid-line layoutGridLine Gets or sets the gridline value used for rendering the text content of an element.
-ms-layout-grid-mode layoutGridMode Gets or sets whether the text layout grid uses two dimensions.
-ms-layout-grid-type layoutGridType Gets or sets the type of grid used for rendering the text content of an element.
left left Gets or sets the position of the object relative to the left edge of the next positioned object in the document hierarchy.
letter-spacing letterSpacing Gets or sets the amount of additional space between letters in the object.
line-break lineBreak Gets or sets line-breaking rules for text in selected languages such as Japanese, Chinese, and Korean.
line-height lineHeight Gets or sets the distance between lines in the object.
list-style listStyle Sets or retrieves up to three separate listStyle properties of the object.
list-style-image listStyleImage Gets or sets a value that indicates which image to use as a list-item marker for the object.
list-style-position listStylePosition Gets or sets a variable that indicates how the list-item marker is drawn relative to the content of the object.
list-style-type listStyleType Gets or sets the predefined type of the line-item marker for the object.
margin margin Gets or sets the width of the top, right, bottom, and left margins of the object.
margin-bottom marginBottom Gets or sets the height of the bottom margin of the object.
margin-left marginLeft Gets or sets the width of the left margin of the object.
margin-right marginRight Gets or sets the width of the right margin of the object.
margin-top marginTop Gets or sets the height of the top margin of the object.
marker New for Internet Explorer 9  marker Gets or sets a value that specifies the marker symbol that is used for all vertices on the given path element or basic shape.
marker-end New for Internet Explorer 9  markerEnd Gets or sets a value that defines the arrowhead or polymarker that is drawn at the final vertex of a given path element or basic shape.
marker-mid New for Internet Explorer 9  markerMid Gets or sets a value that defines the arrowhead or polymarker that is drawn at every other vertex (that is, every vertex except the first and last) of a given path element or basic shape.
marker-start New for Internet Explorer 9  markerStart Gets or sets a value that defines the arrowhead or polymarker that is drawn at the first vertex of a given path element or basic shape.
mask New for Internet Explorer 9  mask Gets or sets a value that indicates a SVG mask.
max-height maxHeight Gets or sets the maximum height for an element.
max-width maxWidth Gets or sets the maximum width for an element.
min-height minHeight Gets or sets the minimum height for an element.
min-width minWidth Gets or sets the minimum width for an element.
-ms-block-progression msBlockProgression Gets or sets the block progression and layout orientation.
-ms-interpolation-mode msInterpolationMode Gets or sets the interpolation (resampling) method used to stretch images.
opacity New for Internet Explorer 9  opacity Gets or sets a value that specifies object or group opacity in CSS or SVG.
orphans orphans Gets or sets the minimum number of lines of a paragraph that must appear at the bottom of a page.
outline outline Gets or sets the color, style, and width of the outline frame.
outline-color outlineColor Gets or sets the color of the outline frame.
outline-style outlineStyle Gets or sets the style of the outline frame.
outline-width outlineWidth Gets or sets the width of the outline frame.
overflow overflow Gets or sets a value indicating how to manage the content of the object when the content exceeds the height or width of the object.
-ms-overflow-x overflowX Gets or sets how to manage the content of the object when the content exceeds the width of the object.
-ms-overflow-y overflowY Gets or sets how to manage the content of the object when the content exceeds the height of the object.
padding padding Gets or sets the amount of space to insert between the object and its margin or, if there is a border, between the object and its border.
padding-bottom paddingBottom Gets or sets the amount of space to insert between the bottom border of the object and the content.
padding-left paddingLeft Gets or sets the amount of space to insert between the left border of the object and the content.
padding-right paddingRight Gets or sets the amount of space to insert between the right border of the object and the content.
padding-top paddingTop Gets or sets the amount of space to insert between the top border of the object and the content.
page-break-after pageBreakAfter Gets or sets a value indicating whether a page break occurs after the object.
page-break-before pageBreakBefore Gets or sets a string indicating whether a page break occurs before the object.
page-break-inside pageBreakInside Gets or sets a string indicating whether a page break is allowed to occur inside the object.
pixelBottom Sets or retrieves the bottom position of the object.
pixelHeight Sets or retrieves the height of the object.
pixelLeft Sets or retrieves the left position of the object.
pixelRight Sets or retrieves the right position of the object.
pixelTop Sets or retrieves the top position of the object.
pixelWidth Sets or retrieves the width of the object.
pointer-events New for Internet Explorer 9  pointerEvents Gets or sets a value that specifies under what circumstances a given graphics element can be the target element for a pointer event in SVG.
posBottom Sets or retrieves the bottom position of the object in the units specified by the bottom attribute.
posHeight Sets or retrieves the height of the object in the units specified by the height attribute.
position position Gets or sets the type of positioning used for the object.
posLeft Sets or retrieves the left position of the object in the units specified by the left attribute.
posRight Sets or retrieves the right position of the object in the units specified by the right attribute.
posTop Sets or retrieves the top position of the object in the units specified by the top attribute.
posWidth Sets or retrieves the width of the object in the units specified by the width attribute.
quotes quotes Gets or sets the pairs of strings to be used as quotes in generated content.
right right Gets or sets the position of the object relative to the right edge of the next positioned object in the document hierarchy.
ruby-align rubyAlign Gets or sets the position of the ruby text specified by the rt object.
ruby-overhang rubyOverhang Gets or sets the position of the ruby text specified by the rt object.
ruby-position rubyPosition Gets or sets the position of the ruby text specified by the rt object.
-ms-scrollbar-3dlight-color scrollbar3dLightColor Gets or sets the color of the top and left edges of the scroll box and scroll arrows of a scroll bar.
-ms-scrollbar-arrow-color scrollbarArrowColor Gets or sets the color of the arrow elements of a scroll arrow.
-ms-scrollbar-base-color scrollbarBaseColor Gets or sets the color of the main elements of a scroll bar, which include the scroll box, track, and scroll arrows.
-ms-scrollbar-darkshadow-color scrollbarDarkShadowColor Gets or sets the color of the gutter of a scroll bar.
-ms-scrollbar-face-color scrollbarFaceColor Gets or sets the color of the scroll box and scroll arrows of a scroll bar.
-ms-scrollbar-highlight-color scrollbarHighlightColor Gets or sets the color of the top and left edges of the scroll box and scroll arrows of a scroll bar.
-ms-scrollbar-shadow-color scrollbarShadowColor Gets or sets the color of the bottom and right edges of the scroll box and scroll arrows of a scroll bar.
-ms-scrollbar-track-color scrollbarTrackColor Gets or sets the color of the track element of a scroll bar.
stop-color New for Internet Explorer 9  stopColor Gets or sets a value that indicates what color to use at the current gradient stop.
stop-opacity New for Internet Explorer 9  stopOpacity Gets or sets a value that defines the opacity of the current gradient stop.
stroke New for Internet Explorer 9  stroke Gets or sets a value that indicates the color to paint along the outline of a given graphical element.
stroke-dasharray New for Internet Explorer 9  strokeDasharray Gets or sets one or more values that indicate the pattern of dashes and gaps used to stroke paths.
stroke-dashoffset New for Internet Explorer 9  strokeDashoffset Gets or sets a value that specifies the distance into the dash pattern to start the dash.
stroke-linecap New for Internet Explorer 9  strokeLinecap Gets or sets a value that specifies the shape to be used at the end of open subpaths when they are stroked.
stroke-linejoin New for Internet Explorer 9  strokeLinejoin Gets or sets a value that specifies the shape to be used at the corners of paths or basic shapes when they are stroked.
stroke-miterlimit New for Internet Explorer 9  strokeMiterlimit Gets or sets a value that indicates the limit on the ratio of the length of miter joins (as specified in the strokeLinejoin property).
stroke-opacity New for Internet Explorer 9  strokeOpacity Gets or sets a value that specifies the opacity of the painting operation that is used to stroke the current object.
stroke-width New for Internet Explorer 9  strokeWidth Gets or sets a value that specifies the width of the stroke on the current object.
float styleFloat Gets or sets on which side of the object the text will flow.
table-layout tableLayout Gets or sets a string that indicates whether the table layout is fixed.
text-align textAlign Gets or sets whether the text in the object is left-aligned, right-aligned, centered, or justified.
-ms-text-align-last textAlignLast Gets or sets how to align the last line or only line of text in the object.
-ms-text-autospace textAutospace Gets or sets the autospacing and narrow space width adjustment of text.
text-decoration textDecoration Gets or sets a value that indicates whether the text in the object has blink, line-through, overline, or underline decorations.
textDecorationBlink Sets or retrieves a Boolean value that indicates whether the object's textDecoration property has a value of "blink."
textDecorationLineThrough Sets or retrieves a Boolean value indicating whether the text in the object has a line drawn through it.
textDecorationNone Sets or retrieves the Boolean value indicating whether the textDecoration property for the object has been set to none.
textDecorationOverline Sets or retrieves a Boolean value indicating whether the text in the object has a line drawn over it.
textDecorationUnderline Sets or retrieves whether the text in the object is underlined.
text-indent textIndent Gets or sets the indentation of the first line of text in the object.
-ms-text-justify textJustify Gets or sets the type of alignment used to justify text in the object.
-ms-text-kashida-space textKashidaSpace Gets or sets the ratio of kashida expansion to white space expansion when justifying lines of text in the object.
-ms-text-overflow textOverflow Gets or sets a value that indicates whether to render ellipses(...) to indicate text overflow.
text-transform textTransform Gets or sets the rendering of the text in the object.
-ms-text-underline-position textUnderlinePosition Gets or sets the position of the underline decoration that is set through the textDecoration property of the object.
top top Gets or sets the position of the object relative to the top of the next positioned object in the document hierarchy.
unicode-bidi unicodeBidi Gets or sets the level of embedding with respect to the bidirectional algorithm.
vertical-align verticalAlign Gets or sets the vertical alignment of the object.
visibility visibility Gets or sets whether the content of the object is displayed.
white-space whiteSpace Gets or sets a value that indicates whether lines are automatically broken inside the object.
widows widows Gets or sets the minimum number of lines of a paragraph that must appear at the top of a page.
width width Gets or sets the width of the object.
-ms-word-break wordBreak Gets or sets line-breaking behavior within words, particularly where multiple languages appear in the object.
word-spacing wordSpacing Gets or sets the amount of additional space between words in the object.
-ms-word-wrap wordWrap Gets or sets whether to break words when the content exceeds the boundaries of its container.
-ms-writing-mode writingMode Gets or sets the direction and flow of the content in the object.
z-index zIndex Gets or sets the stacking order of positioned objects.
-ms-zoom zoom Gets or sets the magnification scale of the object.

Remarks

Inline styles are CSS assignments that you apply directly to individual HTML elements using the STYLE attribute. Use the style object to examine these assignments and to make new assignments or change existing ones.

To retrieve the style object, apply the style keyword to an element object. To retrieve the current setting for an inline style, apply the corresponding style property to the style object.

The style object does not provide access to the style assignments in style sheets. To obtain information about styles in style sheets, use the styleSheets collection to access to the individual style sheets defined in the document.

The following properties are not available when the rule object accesses the style object: posHeight, posWidth, posTop, posLeft, pixelHeight, pixelWidth, pixelTop, and pixelLeft.

To change or clear multiple style properties simultaneously, use this object with the cssText property. For example, to change the font color and background color of a DIV element, you could use the following code:



<DIV onclick="this.style.cssText = 'color:red;background-color:blue;border:5px solid black;'">
Click this DIV to change style properties.</DIV>

Examples

This example uses the style object to set the document body text font to Verdana.


document.body.style.fontFamily = "Verdana"

This example positions all absolutely positioned images in the given document at the top of the document.


var oImages = document.all.tags("IMG");
if (oImages.length) {
    for (var iImg = 0; iImg < oImages.length; iImg++) {
        var oImg = oImages(iImg);
        if (oImg.style.position == "absolute") {
            oImg.style.top = 0;
        }
    }
}

This example copies the inline style of the second element (div2) to the first (div1) while preserving the styles of the second. The background color of div1 is overwritten during the assignment.


<DIV ID="div1" STYLE="background-color:blue;font-weight:bold">Item 1</DIV>
<DIV ID="div2" STYLE="background-color:red;font-size:18pt;
    font-family:Verdana;">Item 2</DIV>

<SCRIPT>
div1.style.cssText += (';' + div2.style.cssText);
</SCRIPT>

Applies To

A, ABBR, ACRONYM, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CUSTOM, cssText, DD, defaults, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, rule, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

コミュニティの追加

表示:
© 2014 Microsoft