如何使用 MVC 创建(图片)标题徽标(4)
-
12-12-2019 - |
题
我正在努力使用 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
其他提示
我得到了问题原因!
我们的编码没有错,事情是一个覆盖我们的图像集的类?
在site.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
- 用于优先显示网页中的样式。
在您的 custom.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*/
}
无需更改 site.css 中的任何内容
不隶属于 StackOverflow