Conditional stylesheets for IE

310 views
Skip to first unread message

Andrew Davey

unread,
Nov 27, 2011, 11:47:28 AM11/27/11
to Cassette
Here's a quick treat I had to sneak in before 1.0 ;) ...

v0.9.5 supports conditional stylesheets - for including IE specific stylesheets in a page.

In CassetteConfiguration:

bundles.Add<StylesheetBundle>("styles/ie-hacks", b => b.Condition = "lt IE 9");

When rendered in the page, you'll get:

<!--[if lt IE 9]>
<link href="the-cassette-url" type="text/css" rel="stylesheet"/>
<[endif]-->

Chris Marisic

unread,
Nov 28, 2011, 8:56:35 AM11/28/11
to cass...@googlegroups.com
Upvote

Nick

unread,
Oct 2, 2012, 9:28:26 AM10/2/12
to cass...@googlegroups.com
Is it still the way to go to include a conditional stylesheet? Or is there a better way now?

Nick

unread,
Oct 2, 2012, 9:34:35 AM10/2/12
to cass...@googlegroups.com
and how can I have in the same bundle a file named site.css (always included) and a conditional file named site.ie.css used only for IE?

Andrew Davey

unread,
Oct 2, 2012, 12:57:36 PM10/2/12
to cass...@googlegroups.com
The StylesheetBundle Condition property is still the thing to use.

However, it does need to be a distinct bundle from your other styles.
Message has been deleted

Daniel Lo Nigro

unread,
May 13, 2013, 7:11:03 PM5/13/13
to cass...@googlegroups.com
This is great for loading jQuery 1.9 for legacy IE and jQuery 2.0 for modern browsers:

// Load either jQuery 1.9 or 2.0 depending on whether the browser is IE
bundles.Add<ScriptBundle>("_js/jquery-1.9", new[] { "~/_js/jquery-1.9.1.js" }, bundle => bundle.Condition = "lt IE 9");
bundles.Add<ScriptBundle>("_js/jquery-2.0", new[] { "~/_js/jquery-2.0.0.js" }, bundle => bundle.Condition = "(gte IE 9)|!(IE)");

Then just reference both bundles.
Reply all
Reply to author
Forward
0 new messages