Home  >  Article  >  Web Front-end  >  expression_html/css_WEB-ITnose in css

expression_html/css_WEB-ITnose in css

WBOY
WBOYOriginal
2016-06-24 11:40:351272browse

Recently, I am more interested in the behavior in CSS. Although it does not meet the standards and can only be recognized by IE, it does expand the functions of CSS a lot. The following are text and examples taken from the Internet. Because they have been corrupted, the source cannot be indicated.

IE5 and later versions support the use of expression in CSS to associate CSS attributes with Javascript expressions. The CSS attributes here can be inherent attributes of the element or custom attributes. That is to say, the CSS attribute can be followed by a Javascript expression, and the value of the CSS attribute is equal to the result of the Javascript expression calculation. You can directly reference the properties and methods of the element itself in the expression, or use other browser objects. The expression is as if it were within a member function of this element.

Assign values ​​to the inherent attributes of the element

The following is to define the width of the container container. If <725, it is its own width, otherwise it is equal to 725, which is equivalent to max- width:725px;.

Assign a value to the element's custom attribute

For example, eliminate the link dotted box on the page. The usual approach is:

link1
link2
link3

At a glance, the advantages of using expression may not be apparent, but if there are dozens or even hundreds of links on your page, would you still use Ctrl C and Ctrl V mechanically at this time, let alone compare the two? , which one generates more redundant code?

The way to use expression is as follows:


link1
link2
< a href="link3.htm">link3

Explanation: The star in is an attribute defined arbitrarily by you. You can define it as you like, and then include it in The statement in expression() is a JS script. Don’t forget there is a quotation mark between the custom attribute and expression. Because the essence is still CSS, it is placed in the style tag instead of the script. OK, so it is easy to eliminate the link dotted box in the page in one sentence. But don’t be complacent. If the special effect triggered is a CSS attribute change, the result will be different from your original 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 naturally think that it should be written as




But the result is a script error. The correct way to write it is Write the definition of CSS style into the function, as follows:




Note: is not very necessary, generally It is not recommended to use expression because expression requires relatively high browser resources.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn