relative path in stylesheets within asp.net mvc areas

[亡魂溺海] 提交于 2021-01-27 05:06:24

问题


I have a project with the current structure

My Project
  /Content
  /Controller
  /View
  /Model
  /Areas
     /Area1
        /View
        /Controller
        /Model
     /Area2
        /View
        /Controller
        /Model

All of the area views are using a root shared _Layout view which is referencing a css file under the root content directory. The css file under the content folder is referencing images or other content with the same directory like below:

.box-shadow
{
    -webkit-box-shadow: 0px 5px 80px #505050;
    -moz-box-shadow: 0px 5px 80px #505050;
    box-shadow: 0px 5px 80px #505050;
    behavior: url('../Content/PIE.htc');
}

All of this works fine when i access 'http://MyProject/controller/action', but when i go into an area 'http://root/area/controller/action' my css file is not able to find the path '../Content/PIE.htc'.

I don't know how to go about fixing this so i was wondering if anyone knew of a way to fix this.

Thanks!


回答1:


If all the views in all the areas are using root shared _Layout (~/Views/Shared/_Layout.cshtml), make sure that _Layout.cshtml calls css file like the following code:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

I tested it with MVC 3 and it works.




回答2:


There are two useful SO posts on this: css3pie in MVC, where to place the pie.htc file? and where do I put the PIE.htc file (for making IE work with CSS3) when I'm using cakephp, and the PIE site has a discussion about it too:

IE interprets the URL for the behavior property relative to the source HTML document, rather than relative to the CSS file like every other CSS property. This makes invoking the PIE behavior inconvenient, because the URL has to either be:

Absolute from the domain root — this makes the CSS not easily moveable between directories

Relative to the HTML document — this makes the CSS not easily reusable between different HTML files.

My best idea so far is to have one css directory sitewide where you put the PIE.htc file, and use absolute pathing to it. Not great, but not terrible.



来源:https://stackoverflow.com/questions/7653538/relative-path-in-stylesheets-within-asp-net-mvc-areas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!