Is it possible to create, for instance, a box model hack while using in-line CSS?
For example:
I'd go outside - slap a class on that element, or use the ID you have, and handle the styling externally.
I'd also concur with the conditional comments answers preceding mine.
That said: As an absolute last resort, you can use the following style hacks to target <= IE6, and even IE7. The trouble comes when/if they fix IE8 to defeat your hack.
.foo {
padding: 5px;
^padding: 4px; /* this targets all IE, including 7. It must go first, or it overrides the following hack */
_padding: 3px; /* this targets >= IE6 */
width: 30px;
}
Good luck.
Without arguing for or against CSS hacks, personally if I needed to do something like that, I would prefer to use a conditional comment:
<!--[if lt IE 7]>
<style>
#blah {
padding: 5px;
margin: 5px;
width: 30px;
}
</style>
<![endif]-->
You can use the "prefixing" hack in inline styles as well:
<div style="*background:red"></div>
Just make sure you put the IE hacks at the end of the style attribute. However I second the opinion that inline styles should be avoided when possible. Conditional comments and a separate CSS file for Internet Explorer seem to be the best way to handle such issues.
The best solution is to work in Standards Mode rather than Quirks Mode.... that'll eliminate the need for the majority of your box model hacks right away.
Beyond that, conditional comments with an IE-specific stylesheet are far cleaner and more maintainable. That method has been good enough for most every top-notch designer for the last several years... unless there's something specific about your site that requires it all to be inline I suggest taking a step back and looking at the root problems instead of how you can patch these little symptoms as they appear.alt text http://sonicloft.net/im/52
The most appropriate answer is don't. (Edit: to be clear, I mean don't do it inline, I don't mean don't use CSS hacks.)
Edit: This doesn't work, IE ignores the conditional comment. Leaving the answer here to not be a bastard.
The next most appropriate answer is conditional comments:
<div id="blah" style="padding: 5px; margin: 5px; width: 30px; <!--[if lte IE 6]> ... <![endif]-->">
Yeah like everyone above, if you can avoid doing it inline do!! But if you really need to go inline then parser filters are probably your best bet, these are certain characters you can use on properties such as the underscore hack in ie6
print("code sample");
style="position:relative;padding:5px; _position:absolute; _padding:10px;"
ie6 will still get the underscored styles, everyone else will just ignore them!
There is also using !important instead of underscore.
have a play around and see what happens, but again like above, try and avoid like the plague :)