I’d like to use Bootstrap from Twitter in my ASP.Net MVC 3 application. I downloaded bootstrap.css and added it to my project in the Content folder. I opened _Layout.cshtml and added a link to the file:
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />
When I run the application no stylesheet is applied. How do I reference both Site.css and bootstrap.css from my _Layout.cshtml file?
I think the issue here is the inheritance, cascade and specificity CSS. Bear in mind that Twitter’s Bootstrap resets all styles.
Actually, this makes complete sense.
Site.cssis loaded with all it’s style declarations and immediately afterwardsBootstrap.cssis loaded which resets most(if not all styles) thus declarations withinBootstrap.csswill be applied. It only appears that both work probably becauseBootstrap.cssmight not have a defined style orSite.csshas very specific style defined using html ids or classes.Reverse the order (with
Bootstrap.cssfirst), you are now resetting all styles first and then other styles are being applied. SinceSite.cssis loaded second, the styles defined therein will be applied to your site.For your own interest, try to define an inline style within your html doc that has been defined within both ‘Site.css’ and ‘Bootstrap.css’, and see how the style gets applied by adding/removing the style definition.
I tried finding a good supporting explanation for CSS cascading, and the best graphic and simple explanation I found was this which notes