Introduction to Behavior property syntax in CSS

Source: Internet
Author: User

This article and we will focus on the use of CSS in the behavior attribute syntax, in the CSS page layout, we encountered the refresh to retain the contents of the form when the habit of using cookies, but it is very troublesome to do so, The behavior in CSS is good for us to solve this problem.

CSS Property behavior Syntax

In the CSS page layout, we encountered the refresh to keep the contents of the form when the habit of using cookies, but that is very cumbersome to do, CSS behavior for us to solve the problem well. Today we will introduce the syntax of CSS property behavior.

Behavior property Syntax:

Examplesourcecode

    1. Behavior:url (URL) |url (#objID) |url (#default #behaviorname)

Value:

URL (URL): Specifies the DHTML behavior component (. htc) with an absolute or relative URL address

URL (#objID): The behavior of using a binary implementation (as a activex® control). The #objid here is the ID property value of the object.

URL (#default #behaviorname): The default behavior of IE. specified by the name Identification (#behaviorName) of the behavior

Description: Sets or retrieves the DHTML behavior of an object. Multiple behaviors are separated by a space.

When multiple behaviors that are attached to the same feature conflict, the result depends on the order in which the behavior is applied to the feature. The priority of the latter behavior is higher than the previous behavior. The same rules apply to the name conflicts that occur with properties, events, and methods that are provided by different behaviors.

You can use the Addbehavior method to dynamically attach a behavior to an object.

This property is read-only for Currentstyle objects. Readable and writable for other objects.

It is important to note that using the Behavior property of the style sheet (CSS) inline definition or the behavior attached using the Addbehavior method is not automatically detached when the object is removed from the document tree. The behavior defined by the style sheet rule in the document is automatically detached when the object is removed from the document tree.

The corresponding script attribute is behavior.

Example:

Examplesourcecode

    1. P{behavior:url (#default #download);}
    2. Div{behavior:url (FLY.HTC) URL (shy.htc);}
    3. Div{behavior:url (#myObject);}

App 1: Refresh also preserves text inside the input box

Examplesourcecode

    1. . Shistory{}{behavior:url (#default #savehistory);}

App 2: Invoke script

Examplesourcecode

  1. <html>
  2. <head>
  3. <style>
  4. H1{behavior:url (BEHAVE.HTC)}
  5. </style>
  6. </head>
  7. <body>
  8. <H1> put the mouse here 52css.com</H1>
  9. </body>
  10. </html>
  11. Behave.htc
  12. <component>
  13. <attachforattachfor= "element"event= "onmouseover"handler=" hig_lite"/>
  14. <attachforattachfor= "element"event= "onmouseout"handler=" low_lite"/>
  15. <scripttypescripttype="Text/javascript">
  16. Functionhig_lite ()
  17. {
  18. element.style.color=255
  19. }
  20. Functionlow_lite ()
  21. {
  22. element.style.color=0
  23. }
  24. </Script>
  25. </Component>

Note: Try to avoid using behaviors technology when CSS

Internetexplorerbehaviors
What is it? InternetExplorer5 introduced the behavior (behaviors). Behaviors is a way to add behavior to HTML elements by using CSS.
Why should you avoid it? Only InternetExplorer supports the Behavior property.
What's the substitute for? Please use JavaScript and htmldom instead. Source: Http://blog.sina.com.cn/hksqbi

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.