if IE Conditional CSS using ASP.NET Themes
Yesterday when I introduced Artisteer I mentioned that they use conditional link comments to include IE6 and IE7 specific CSS in the master page.
In my world, I like to use ASP.NET themes for my CSS, which means the CSS will get included automatically. So the question is, how can we use Artister with ASP.NET themes? Or for that matter, how can we include IE-specific CSS as part of our themes?
Once you’ve moved the IE-specific CSS into your themes directory, you’ll want to change the extension to something other than CSS so that ASP.NET will pick it up. I just reversed mine so that the CSS is style.css.ie6 and style.css.ie7.
Next we need to write code that will include these two files with the conditional comment code around them. The best place to do this is in the page_load event of the master page, or if you are using international themes you’ll want to set it right after you’ve set the theme in the PreInit code.
Here’s the code you should add:
string appPath = Request.ApplicationPath; if (appPath.Length == 0) appPath = "/"; else if (!appPath.EndsWith("/")) appPath += "/"; String themeDir = Page.Theme; if (themeDir == null || themeDir.Length == 0) themeDir = Page.StyleSheetTheme; String conditionalCode = @"<!--[if IE 6]><link rel='stylesheet' href='" + appPath + @"app_themes/" + themeDir + @"/style.css.ie6' type='text/css' /><![endif]--> <!--[if IE 7]><link rel='stylesheet' href='" + appPath + @"app_themes/" + themeDir + @"/style.css.ie7' type='text/css' /><![endif]--> "; Page.ClientScript.RegisterClientScriptBlock ("".GetType(), "iespecific", conditionalCode);
Other Related Items:
Dreamweaver CS4: The Missing ManualWhen it comes to building professional websites, Dreamweaver CS4 is capable of doing more than any other web design program -- including previous v... Read More >
Candy Stripe - SmallThis imported red and white basket brings lots of cheer to your recipients! It is packed full of treats that include imported chocolate truffles, Walk... Read More >
Bose® In-Ear HeadphonesPresenting high quality in-ear headphones engineered and developed by Bose, the most respected name in sound. Enjoy rich audio and a comfortable fit n... Read More >
If you're new here, you may want to subscribe to the mailing list to get notifications of new post and a virtual tour of past topics. Thanks for visiting!










[...] if IE Conditional CSS using ASP.NET Themes and Programming SEO – Tags and Keywords (Dave M. Bush) [...]