我有一些css文件在default.aspx模板的头部像魅力一样工作。我们正在尝试从网站构建器的仪表板添加自定义CSS输入字段。它是.net,并且获取服务器端的头部代码是:
<asp:Literal runat="server" ID="litCustomCSS"></asp:Literal>
该位的代码隐藏是:
if (s.ToLower().Equals("websiteid"))
{
// check if the customCSS file exists in the proper directory
if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["WebsiteImagePath"] + "/" + pageInfo.ReturnValues[s] + "/CustomCSS.css")))
{
litCustomCSS.Text = "<link rel='stylesheet' type='text/css' id='customCSS' src='" + ConfigurationManager.AppSettings["WebsiteImagePath"] + "/" + pageInfo.ReturnValues[s] + "/CustomCSS.css' />";
}
}
奇怪的部分是它有效......就像文件显示在渲染页面的头部(客户端),但似乎不起作用。就像我为body添加一个自定义CSS类或者它没有将样式附加到该元素一样。它在inspect元素中不可见,但我可以通过单击头部中的链接自行查看css文件。
例如,在此网站(http://tworockguns.com/home.html)上,css行为
<link rel="stylesheet" type="text/css" id="customCSS" src="/site_data/2830/CustomCSS.css">
指向css文件http://www.tworockguns.com/site_data/2830/CustomCSS.css
的链接我通过后端添加了CSS:
.footer-bottom {
background: #111111;
color: #555;
}
您将看到它已成功转移到css doc。
我尝试更改charset ...更改css文件的顺序......但仍然没有。
有什么想法吗?
答案 0 :(得分:1)
您应该将src更改为href,它将起作用。至少在你的网站上它对我有用。