In my MVC 3 app, I have a style sheet that is in the Content folder of the site called site.css. (in fact I am using the one that was created by default when I created the project). I have made several changes to the style sheet (changed the background
color, added image buttons, etc.) but not of my changes are showing up leading me to think that the style sheet is not being loaded. In my _Layout.cshtml file I have the link coded like so
For sure there is an error in the Css file that prevent it from being executed. That is, the file is loaded like your images, but all Css rules that are after the error are not used. Look at the last changes you have done just a little before the Css finished
working.
Even when I strip out everything except changing the background color to red, I get no styles. However, if I paste all my styles into a <style> tag in _layout.cshtml they all work.
I don't belive in magiscs, so obviously there is an error in some hidden place.....so the issue can be solved only if you post the relevant code of the page and your css file.
Skydolphin2
Member
216 Points
62 Posts
style sheet not loading
Mar 08, 2011 08:12 PM|LINK
HI all,
In my MVC 3 app, I have a style sheet that is in the Content folder of the site called site.css. (in fact I am using the one that was created by default when I created the project). I have made several changes to the style sheet (changed the background color, added image buttons, etc.) but not of my changes are showing up leading me to think that the style sheet is not being loaded. In my _Layout.cshtml file I have the link coded like so
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />Does anyone have any ideas of what else I can try to get my styles to load properly?
BTW, all my images load just fine using the same Url.Content syntax.
Thanks,
Rhonda
ignatandrei
All-Star
135120 Points
21675 Posts
Moderator
MVP
Re: style sheet not loading
Mar 08, 2011 08:23 PM|LINK
@string.Format("<link href='{0}' type='text/css' rel='stylesheet' />", ResolveUrl("~/Content/Site.css"))
http://msprogrammer.serviciipeweb.ro/2010/10/09/five-common-mistakes-for-asp-net-mvc-accesing-resources-css-js-images-ajax/
RaviSM
Contributor
2622 Points
589 Posts
Re: style sheet not loading
Mar 08, 2011 08:23 PM|LINK
Try this
<link href="@Href("~/Content/StyleSheet.css")" rel="stylesheet" type="text/css" />
Custom watermark on PDF
Thanks and Regards
Ravi Mathpal
MadhuriM
Member
703 Points
151 Posts
Re: style sheet not loading
Mar 08, 2011 08:56 PM|LINK
This could just be a caching issue form the Browser - especially Google Chrome. Please clear your cache and retry, it might just work.
francesco ab...
All-Star
20912 Points
3279 Posts
Re: style sheet not loading
Mar 08, 2011 09:06 PM|LINK
For sure there is an error in the Css file that prevent it from being executed. That is, the file is loaded like your images, but all Css rules that are after the error are not used. Look at the last changes you have done just a little before the Css finished working.
Mvc Controls Toolkit | Data Moving Plug-in Videos
Skydolphin2
Member
216 Points
62 Posts
Re: style sheet not loading
Mar 08, 2011 09:23 PM|LINK
I tried all the suggestions and none worked.
body { background-color: #b22222; }Even when I strip out everything except changing the background color to red, I get no styles. However, if I paste all my styles into a <style> tag in _layout.cshtml they all work.
Very strange,
RaviSM
Contributor
2622 Points
589 Posts
Re: style sheet not loading
Mar 08, 2011 09:32 PM|LINK
What get rendered in you html?
Custom watermark on PDF
Thanks and Regards
Ravi Mathpal
Forest Cheng...
Star
8370 Points
819 Posts
Re: style sheet not loading
Mar 10, 2011 01:40 AM|LINK
Hi Skydolphin2,
Try this:
body { background-color: #b22222 ! important; }Hope this helpful,
Forest Cheng
If you have any feedback about my replies,please contact msdnmg@microsoft.com.
Microsoft One Code Framework
francesco ab...
All-Star
20912 Points
3279 Posts
Re: style sheet not loading
Mar 10, 2011 06:34 PM|LINK
I don't belive in magiscs, so obviously there is an error in some hidden place.....so the issue can be solved only if you post the relevant code of the page and your css file.
Mvc Controls Toolkit | Data Moving Plug-in Videos
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: style sheet not loading
Mar 11, 2011 12:57 AM|LINK
Create a new MVC 3 Razor application - run it. Modify the style sheet. Compare that project to your own.