The emergence of CSS makes it much easier for web page creators to control web page elements. Of course, CSS can only be effective for color, size, distance, and other static styles, the dynamic style of Some html elements cannot be implemented.
With the CSS custom attribute Expression, you can define the attributes and write the required code in the attributes. In this way, you can combine the CSS features and JS effects, controls the same elements on the entire page. Isn't that incredible? Let's take the example of how to eliminate the link dashed box on the page that the new users often ask.
The common practice is:
Link1link2link3
Although the advantage of using expression may not be apparent, if your page contains dozens or even hundreds of links, will you still perform mechanical Ctrl + C, ctrl + V. What's more, which of the two produces more redundant code?
Use expression as follows:
& Amp; lt; style type = & amp; quot; text/css & amp; quot; & amp; gt; a {star: expression (onfocus = this. blur)} & amp; lt;/style & amp; gt; link1link2link3
Note: star is an attribute defined by yourself. You can define it as you like, and the statements contained in expression () are JS scripts, do not forget to keep a quotation mark between the custom attribute and expression. Because it is actually CSS, it is placed in the style label rather than in the script. OK, so that it is easy to use one sentence to eliminate the link dashed line boxes in the page. But don't be proud of it. If the special effect triggered is a CSS attribute change, the output will be different from your intention. For example, if you want to change the color of the text box on the page as the mouse moves in and out, you may assume that
& Amp; lt; style type = & amp; quot; text/css & amp; quot; & amp; gt; input {star: expression (onmouseover = this. style. backgroundColor = & amp; quot; # FF0000 & amp; quot; onmouseout = this. style. backgroundColor = & amp; quot; # FFFFFF & amp; quot;)} & amp; lt;/style & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt;
The result is a script error. The correct syntax should write the CSS style definition into the function, as shown below:
& Amp; lt; style type = & amp; quot; text/css & amp; quot; & amp; gt; input {star: expression (onmouseover = function () {this. style. backgroundColor = & amp; quot; # FF0000 & amp; quot;}, onmouseout = function () {this. style. backgroundColor = & amp; quot; # FFFFFF & amp; quot ;})} & amp; lt;/style & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt; & amp; lt; input type = & amp; quot; text & amp; quot; & amp; gt;
After reading so much, how does it feel? Is it a concept. The Custom Attributes of CSS are very concise and can achieve the same effect produced by JS with less code. It really plays a multiplier role. You don't have to try it now?