我正在努力使用 MVC (4) 使用 Razor 语法,希望找到可以帮助我找到一个很好的有效解决方案的人。
我想要一个可点击的徽标(图像)并创建了以下代码。除了两件事外,这有效。我没有看到图像显示,其次,当在其他控制器中时,路由出错(http4错误)。
这就是我现在的做法:
剃刀:
<h1>@Html.ActionLink("siteHeader", "Index", null, new { @class = "site-logo"})</h1>
或
<h1>@Html.ActionLink("siteHeader", "Index", "Home", new { @class = "site-logo"})</h1>
例如,当在不同的控制器(帐户/购物车/等)中并单击徽标时,会产生 404。
.CSS:
/网站标题徽标/
a.site-logo {
background: url(images/Solosoft.png) no-repeat top left;
display: block;
width: 100px;
height: 100px;
text-indent: -9999px; /*hides the link text*/
}
提前谢谢。
试试这个:
@Html.ActionLink("siteHeader", "Index", "Home", null, new { @class = "site-logo"})
这是:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
Object routeValues,
Object htmlAttributes
)
链接: msdn
我得到了问题的原因!
我们的编码没有错,问题是有一个类覆盖了我们的图像集
网站中有这行.css
.site-title a, .site-title a:hover, .site-title a:active {
*background: none;* <=comment this out and the bg will show or remove the .site-title a
color: #c8c8c8;
outline: none;
text-decoration: none;
}
希望对您有所帮助
wizzardz 说的是正确的。自定义 css 文件中的背景样式被 site.css 中的样式覆盖。
试试这个,!important
- 用于优先考虑样式出现在网页中。
在您的自定义.css页面中,
a.site-logo {
background: url(images/Solosoft.png) no-repeat top left **!important**;
display: block;
width: 100px;
height: 100px;
text-indent: -9999px; /*hides the link text*/
}
无需更改网站中的任何内容.css