我已经阅读了很多论坛并尝试了许多不同的方法来使导航菜单的当前页面保持突出显示,但我不知道为什么它不起作用。
我不想使用 Javascript 或 PHP - 只有 CSS。
这就是我的 HTML:
<body id="@ViewBag.IDTag">
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home", null, new Dictionary<string, object> { { "id", "homenav" } })</li>
<li>@Html.ActionLink("What Is EDI?", "WhatIsEDI", "Home", null, new Dictionary<string, object> { { "id", "whatisedinav" } })</li>
<li>@Html.ActionLink("Bills of Lading", "Index", "Bills_of_Lading", null, new Dictionary<string, object> { { "id", "billsofladingnav" } })</li>
<li>@Html.ActionLink("Issues & Solutions", "Index", "Issues_and_Solutions", null, new Dictionary<string, object> { { "id", "issuesandsolutionsnav" } })</li>
<li>@Html.ActionLink("Partners", "Index", "Partners", null, new Dictionary<string, object> { { "id", "partnersnav" } })</li>
<li>@Html.ActionLink("Locations", "Index", "Locations", null, new Dictionary<string, object> { { "id", "locationsnav" } })</li>
<li>@Html.ActionLink("Refineries", "Index", "Refineries", null, new Dictionary<string, object> { { "id", "refineriesnav" } })</li>
<li>@Html.ActionLink("Sources", "Index", "Sources", null, new Dictionary<string, object> { { "id", "sourcesnav" } })</li>
<li>@Html.ActionLink("Transfer Criteria", "Index", "Transfer_Criteria", null, new Dictionary<string, object> { { "id", "transfercriterianav" } })</li>
<li>@Html.ActionLink("Transportation Methods", "Index", "Transportation_Methods", null, new Dictionary<string, object> { { "id", "transportationmethodsnav" } })</li>
<li>@Html.ActionLink("Rack to Partner Mappings", "Index", "Rack_to_Partner_Mappings", null, new Dictionary<string, object> { { "id", "racktopartnermappingsnav" } })</li>
<li>@Html.ActionLink("Products", "Index", "Products", null, new Dictionary<string, object> { { "id", "productsnav" } })</li>
</ul>
</body>
在每个视图中,我在页面顶部都有 id。主页示例如下:
@{
ViewBag.IDTag = "home";
}
这就是我的 CSS 的样子:
ul#menu
{
font-size: .8em;
font-weight: 600;
color: #FFF;
float: left;
width: 130px;
list-style-type: none;
margin-top: 133px;
margin-left: auto;
margin-right: auto;
margin-bottom: auto;
padding: 0;
}
ul#menu a:link, ul#menu a:visited
{
display:block;
font-weight:bold;
color: #FFF;
background-color: rgb(139,177,216);
width: 120px;
text-align: center;
padding: 5px;
text-decoration: none;
text-transform: uppercase;
}
ul#menu a:hover, ul#menu a:active
{
background-color: #365f87;
}
body#home a#homenav,
body#whatisedi a#whatisedinav,
body#billsoflading a#billsofladingnav,
body#issuesandsolutions a#issuesandsolutionsnav,
body#partners a#partnersnav,
body#locations a#locationsnav,
body#refineries a#refineriesnav,
body#sources a#sourcesnav,
body#transfercriteria a#transfercriterianav,
body#transportationmethods a#transportationmethodsnav,
body#racktopartnermappings a#racktopartnermappingsnav,
body#products a#productsnav
{
background-color: #365f87; /* highlights current page */
text-transform: lowercase;
cursor:default;
}
我对这一切都很陌生,所以它可能只是一个语法问题,或者当它应该是“div”时调用一些“body”或当它应该是“class”时调用“id”。我正处于我尝试过的任何事情都没有产生任何影响的地步。任何帮助将不胜感激。