IHTMLStyleSheet

IHTMLStyleSheet


This interface provides access to an object representing a single style sheet in the document.

The styleSheet object represents an instance of the STYLE or LINK tag with a relationship (rel attribute) of the STYLESHEET object.

You use the object to retrieve information about the style sheet, such as the URL of the source file for the style sheet and the element in the document that owns (defines) the style sheet. You also use the object to modify the style sheet.

You retrieve a pointer to the style sheet object by using the IHTMLDocument2::get_styleSheets method. You can retrieve a collection of all styleSheets in the document by using the IHTMLStyleSheet::get_imports method. Each item in the collection is a style sheet. A style sheet object is available for a style sheet only if it is included in a document with a STYLE or LINK element, or with an @import statement in the STYLE element.

IHTMLStyleSheet Methods
put_title   get_title   get_parentStyleSheet  
get_owningElement   put_disabled   get_disabled  
get_readOnly   get_imports   put_href  
get_href   get_type   get_id  
addImport   addRule   removeImport  
removeRule   put_media   get_media  
get_cssText   get_rules  

IHTMLStyleSheet::addImport

HRESULT addImport(
    BSTR bstrURL,
    long lIndex,
long *plIndex 
);

Adds a style sheet to the imports collection for the given style sheet.

bstrURL
String specifying the location of the source file for the style sheet.
lIndex
Integer specifying the requested position of the style sheet in the collection. The position is zero-based.
plIndex
Address of a variable that receives an integer index value specifying the position of the imported style sheet in the imports collection.

IHTMLStyleSheet::addRule

HRESULT addRule( 
    BSTR bstrSelector,
    BSTR bstrStyle,
    long lIndex, 
    long *plNewIndex 
);

Creates a new style rule using the given selector and style assignment.

bstrSelector
String specifying the selector for the new rule.
bstrStyle
String specifying the style assignments for this style rule.
lIndex
Zero-based position in the style sheet where the style rule is to be placed.
plNewIndex
Address of a variable that receives the new zero-based index of the style rule.

IHTMLStyleSheet::get_cssText

HRESULT get_cssText(
    BSTR *p 
);

Retrieves a string of the rules set in the style sheet defined in the CSS format as it would look, if the style sheet were saved.

p
Address of a string variable that receives the rules set.

IHTMLStyleSheet::get_disabled

HRESULT get_disabled( 
    VARIANT_BOOL *p 
);

Determines whether the style sheet is enabled or disabled. "False" for style sheets that do not specify a title and that are not currently selected.

p
Address of a variable that receives TRUE if the style sheet is enabled, or FALSE otherwise. This parameter receives FALSE if the style sheet does not specify a title or is not currently selected.

The value of this property can change per media-dependent style sheets. The application of individual style sheets can be turned on and off dynamically. Note that the value of this property is also controlled by whether titled style sheets are applied.

See also put_disabled

IHTMLStyleSheet::get_href

HRESULT get_href(
    BSTR *p 
);

Retrieves the URL of a linked style sheet.

p
Address of a string that receives the URL. If the style sheet is a STYLE element, this parameter receives NULL.

See also put_href

IHTMLStyleSheet::get_id

HRESULT get_id(
    BSTR *p 
);

Retrieves the identifier of the style sheet.

p
Address of a variable that receives the identifier.

IHTMLStyleSheet::get_imports

HRESULT get_imports(
    IHTMLStyleSheetsCollection **p 
);

Retrieves a zero-based collection of all the imported style sheets defined for the given styleSheet object. An imported style sheet is one that is brought into the document using the CSS @import attribute.

p
Address of a variable that receives a pointer to the collection. See IHTMLStyleSheetsCollection for details.

IHTMLStyleSheet::get_media

HRESULT get_media( 
    BSTR *p 
);

Receives the string that indicates which media this style applies to.

p
Address of a sting variable that receives the media type.

See also put_media

IHTMLStyleSheet::get_owningElement

HRESULT get_owningElement(
    IHTMLElement **p 
);

Retrieves the element that is next in the HTML hierarchy. This usually contains the STYLE or LINK that defined the style sheet.

p
Address of a variable that receives an interface pointer to the element.

See also IHTMLElement

IHTMLStyleSheet::get_parentStyleSheet

HRESULT get_parentStyleSheet(
    IHTMLStyleSheet **p 
);

Retrieves an interface pointer to the styleSheet object that imported the current style sheet. This property is intended for imported styleSheets.

p
Address of a variable that receives an interface pointer to the parent style sheet. This parameter receives NULL if the style sheet is part of a LINK or STYLE element.

IHTMLStyleSheet::get_readOnly

HRESULT get_readOnly( 
    VARIANT_BOOL *p 
);

Indicates whether the rule object can be edited.

p
Address of a variable that receives TRUE if the rule object can be edited, or FALSE if not.

IHTMLStyleSheet::get_rules

HRESULT get_rules(
    IHTMLStyleSheetRulesCollection **p 
);

Retrieves an IHTMLStyleSheetRulesCollection pointer to the collection of the rules in this styleSheet. If there are no rules, the length of the collection returned is zero.

p
Address of a variable that receives an interface pointer to IHTMLStyleSheetRulesCollection.

IHTMLStyleSheet::get_title

HRESULT get_title(
    BSTR *p 
);

Retrieves the title of the styleSheet.

p
Address of a variable that receives the title. This parameter receives FALSE if the style sheet has no title or the title is not currently selected.

The application of individual style sheets can be turned on and off dynamically. Note that the value of this property is also controlled by whether titled style sheets are applied.

See also put_title

IHTMLStyleSheet::get_type

HRESULT get_type(
    BSTR *p 
);

Retrieves the CSS language the style sheet is written in.

p
Address of a variable that receives the type. It can be any string, including an empty string. Currently, style sheets having any type other than "text/css" are not supported.

IHTMLStyleSheet::put_disabled

HRESULT put_disabled( 
    VARIANT_BOOL v 
);

Enables or disables the style sheet.

v
TRUE to enable the style sheet, or FALSE to disable it.

See also get_disabled

IHTMLStyleSheet::put_href

HRESULT put_href(
    BSTR v 
);

Sets the URL of a linked styleSheet; that is, it is part of a LINK element.

v
String specifying the URL.

See also get_href

IHTMLStyleSheet::put_media

HRESULT put_media(
    BSTR v 
);

Sets the string that indicates which media this style element applies to. See IHTMLLinkElement::put_media for values.

v
String specifying the media type for the styleSheet element.

See also get_media

IHTMLStyleSheet::put_title

HRESULT put_title(
    BSTR v 
);

Sets the title of the styleSheet element.

v
String specifying the title.

See also get_title

IHTMLStyleSheet::removeImport

HRESULT removeImport(
    long lIndex 
);

Removes the imported style sheet by ordinal position in the imports collection based on the value of the index passed in.

lIndex
Long integer value indicating which imported style sheet to remove.

IHTMLStyleSheet::removeRule

HRESULT removeRule( 
    long lIndex 
);

Removes the rule by ordinal position based on the value of the index passed in. The rule is deleted from the style sheet, and the document is updated to reflect any changes.

lIndex
Long integer value indicating which style rule to remove.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.