CSS BEHAVIOR
The Behavior property specifies one or more space separated URLs indicating script(s) to attach to a CSS selector. Behaviors allow the default functionality of a given element to be extended. Using simple CSS syntax that allows script to be separated from style and content, CSS behaviors offer a fairly elegant and efficient way to re-use script code. This is an IE propietary property
Example
blockquote { behavior: url(hilight.htc) url(#behaveBinObject) }
Some text
Possible Values
[Script URL]: Provides an absolute or relative URL reference to the Behavior.
[#Object ID]: The Behavior is a binary implementation. This syntax consists of a pound sign (“#”) followed by an OBJECT element ID within the document that instantiates the binary implementation.
[Default Behavior]: Quite a few default behaviors ship with Internet Explorer 5.0. This syntax allows each default behavior to be easily referenced.
25 Responses
Hey,
I found this page. I’d like to get the best book on CSS on the market. Something that covers it all. I have yet to find a book that does. Can you help me?
Jim.
nice post. i like that…
How can i use it. and when should i use it?
Hello,
Are there any working example of this property so that we can actually see it implementation in realtime.
hi
How can i use it. and when should i use it?
where is hilight.htc file
The most commonly used scripts that I’ve seen deal with hacking IE. Either making transparent PNGs display correctly or tricking IE into maintaining a :hover on elements it doesn’t like to.
This would be a difficult property to provide specific examples of that would be relevant to it’s usage.
This is an IE specific CSS property. Use it only when you want to fix something in IE, Otherwise i think you shouldn’t. An excellent example of this is IEPngFix.
The CSS behavior property only works in Microsoft. It doesn’t separate style from content any more than any other CSS property, but it sure does introduce the rather abusive idea of connecting style to script.
The CSS behavior property is basically, you want a certain element to do something script-related, like bounce around the screen or something. Instead of linking to an external Javascript (js) file or having an internal script within a script element in HTML, this just uses htc files, which I’ve never used and never intend to use because it’s all Microsoft-specific (though other browsers do use it, most don’t).
Do yourself a favor, download, learn, and use jQuery if you want to use CSS selectors to define behavior in a WAY easier way that takes up less space and isn’t so abusive.
Stay away from the CSS behavior property. I mean if you wanna try it, go ahead. Just saying, it’ll most likely be a waste of your time.
Check out this page: http://www.w3schools.com/Css/css_dont.asp (hopefully the preceding link has shown up). The code shown there gives you the ability to make a working demonstration if you’re curious. Other than plain curiosity, I don’t see any use for such a property that cuts off what’s turning into half of browser users. And if you’re making an IE-specific site, like one of those university deals, don’t use it then either. jQuery works on just about every browser made in this decade.
Javascript within CSS is not CSS, just like copying random text into an HTML file is not HTML.
Hi,
how to implement this?
This is an IE propietary property not a CSS one
http://msdn.microsoft.com/en-us/library/ms530723%28VS.85%29.aspx
and here the w3 alternative option:
http://www.w3.org/TR/xbl/
img,
div {
behavior: url(templates/iepngfix.htc)
}
there are some *.htc files in the web, they normally do a “fix” to the behavior in IE for some image properties (e.g. transparency)
I remember a few years back when everyone complained that Microsoft were causing problems by using their proprietary attributes etc. and here we are using it again. :)
Only to fix errors and problems Microsoft could not have fixed on its own :)
We used HTC for Date and Number input text fields for auto-formatting. Additionally, some input fields needs to have AJAX behaviours and HTC is best for this. For button push effect, we used it. You simply declare CSS behaviour in your style definion and use it: class=”myRichNumberInputText”
hi
How can i use it. and when should i use it?
where is hilight.htc file
[…] CSS3 PIE is a behavior plug-in, proprietary to IE, that sits beside your stylesheet adding support for the following […]
Hello,
Are there any working example of this property so that we can actually see it implementation in realtime.
its good but..
How can i use it. and when should i use it?
how to use css behavior
[…] As a final note, the behaviour property allows us to attach a script to a CSS selector. You can read more about it at http://www.css3.com. […]
So this mean we can use to separate style-sheets?
Excellent..Any one can help me to give me all information about htc files..
I have used this a lot but cant understand how to implement this?
HTML Components (HTCs) provide a mechanism to implement components in script as Dynamic HTML (DHTML) behaviors. An HTC is an HTML file that contains script and a set of HTC-specific elements that define the component. The component is saved with an .htc extension.
I agree with Josh, do NOT use this property. It’s Explorer only, and does not separate design from function – you are injecting script into CSS! That is what JavaScript is for.
http://css3pie.com/
you can use this site for how to implement border-radius, shadow and gradient features of css3 in IE6-8 browsers.
Its simply awesome..
pie and similar htc css additions can work well but if you have dynamically loaded elements on your pages (like ajax loaded) avoid css behaviour attribute like plague. It WILL break your styling in IE7,8.
we are using htc files too with behaviour attribute. It makes is possible to do rounded corners, gradient and other css3 goodies in IE as well.
not the most ideal to use scripts in css but it works very well.