What is CSS expression?
IE5 and later versions support the use of expression in CSS to associate CSS attributes with Javascript scripts. The CSS attributes here can be inherent attributes of elements or custom attributes. That is to say, the CSS attribute can be followed by a Javascript expression. The value of the CSS attribute is equal to the result calculated by the Javascript expression.
You can directly reference attributes and methods of an element in an expression, or use other browser objects. This expression is like a member function in this element.
Do you think the text above is a bit obscure? It doesn't matter. You just need to know: we can write Javascript scripts into css files through expression to implement some convenient functions and effects.
What role does CSS expression play?
1. Assign values to the inherent attributes of an element
2. Assign values to custom attributes of elements
We want to remove the dotted line generated when clicking the link on the page.
In general, we do this:
The code is as follows: |
Copy code |
<A href = "link1.htm" onfocus = "this. blur ()"> 111cn.net </a> <br/> <A href = "link2.htm" onfocus = "this. blur ()"> 111cn.net </a> <br/> <A href = "link3.htm" onfocus = "this. blur ()"> 111cn.net </a>
|
You may not feel it. But if there are dozens or even hundreds of links on your page, will you still mechanically Ctrl + C, Ctrl + V, the advantage of using expression is now apparent. Which of the two produces more redundant code?
Use expression as follows:
The code is as follows: |
Copy code |
A {star: expression (this. onFocus = this. blur ())}
|
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. In this way, it is easy to use one sentence to eliminate the link dashed line boxes on the page.
Special attention should be paid to: If expression is not very special, it is generally not recommended to use expression because expression has high requirements on browser resources.
We will write some notes about expression application examples and usage in future articles. Please follow our website: I love CSS-111cn.net.