Export (0) Print
Expand All

cssText property

Sets or retrieves the persisted representation of the style rule.

This property is read/write.

Syntax

HRESULT put_cssText(
  BSTR v
);

HRESULT get_cssText(
  [out, retval]  BSTR *p
);

Property values

Type: BSTR

the text.

Remarks

This property reflects the current state of the rule and not its initial value.

The number of rules that can be applied at one time with IHTMLRuleStyle::cssText is 4095.

For newly created style sheet objects, you must first append the element to the document before you can set IHTMLRuleStyle::cssText.

Examples

This example uses the IHTMLRuleStyle::cssText property to set the background image and text and border color for a div element, and to display the current IHTMLRuleStyle::cssText value.

The example defines default CSS div element settings, then creates two buttons on the page that each run a JavaScript function. Clicking the Blue button sets the background to a blue-aqua gradient image and the text and border color to white. Clicking the Red button sets the background to a red-bisque gradient image and the text and border color to black.

Code example: http://samples.msdn.microsoft.com/workshop/samples/css/cssText/cssText.html


#myDiv {
  width: 150px;
  height: 150px;
  border: thin solid;
  float: left;
  margin-right: 10px;
  text-align: center;
}


<body>
  <div id="myDiv"></div>
  <input type="button" value="Blue" onclick="blueGradient();">
  <input type="button" value="Red" onclick="redGradient();">
</body>

Each button calls a function that uses the IHTMLRuleStyle::cssText property to set the background image and text and border color, and to display the property value. The following snippet shows the JavaScript code for each function:


function blueGradient() {
  myDiv.style.cssText = "background-image: radial-gradient(blue, aqua); color: white;"
  myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
}
function redGradient() {
  myDiv.style.cssText = "background-image: radial-gradient(red, bisque); color: black;";
  myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
}

 

 

Community Additions

ADD
Show:
© 2014 Microsoft