How to use expression in CSS? CSS expression details

Source: Internet
Author: User
Tags dashed line

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.