我无法使我的navbar-header和navbar-nav项目正确排列。导航栏标题在导航栏中垂直居中,而导航栏看起来像是align =“ top”。
这是屏幕截图:
这是菜单的代码:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
@Html.ActionLink("Thomas A Farmer, Author", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a href="~/Home/Index">Home</a> |
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About <span class="caret"></span></a> |
<ul class="dropdown-menu">
<li><a href="~/Home/About">About the Author</a></li>
<li><a href="~/Home/BKB">Black Knight Books</a></li>
<li><a href="~/Home/Contact">Contact</a></li>
<li><a href="~/MailingListEntries/Create">Mailing List</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Books and Stories <span class="caret"></span></a> |
<ul class="dropdown-menu">
<li>@Html.ActionLink("Novels", "Index", "BooksAndStories", new { novel = true }, htmlAttributes: null)</li>
<li>@Html.ActionLink("Short Stories", "Index", "BooksAndStories", new { novel = false }, htmlAttributes: null)</li>
<li>@Html.ActionLink("WIP", "WIP", "BooksAndStories", null, htmlAttributes: null)</li>
</ul>
</li>
<li class="nav-item">
<a href="~/Reviews/Index">Reviews</a> |
</li>
<li class="nav-item">
<a href="~/OtherProjects/Index">Other Projects</a> |
</li>
@if (User.Identity.IsAuthenticated)
{
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Admin Tools<span class="caret"></span></a>
|
<ul class="dropdown-menu">
<li><a href="~/MailingListEntries/Index"> Edit Mailing List</a></li>
<li><a href="~/Blog/Create">Add Blog Entry</a></li>
</ul>
</li>
}
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - TAFarmerAuthor</p>
</footer>
</div>
有人有什么想法吗?我仍在学习MVC和Razor,但我一直无法在Google上找到直接解决此问题的任何答案。
答案 0 :(得分:0)
-edit:您正在使用哪个版本的引导程序?您显示给我们的就像3.x
-edit2:https://getbootstrap.com/docs/3.4/components/#navbar是您使用的版本...我建议移至4.3.1 ...
如果这是最新版的引导程序,则您错过了类属性中的标记
//原始代码段
<ul class="navbar-nav">
<li class="nav-item">
<a href="~/home/index">Home</a> |
...
//已修改
<ul class="navbar-nav">
<li class="nav-item">
<a href="~/home/index" class="nav-link">Home</a> |
...
如@Derrick Rose建议的那样,如果您将.net core或什至.netframework与MVC一起使用,那么肯定可以通过<a>
标签来做到这一点。
<a asp-controller="home" asp-action="Index" class="nav-link">Home</a>|
看起来更好...
<li>@Html.ActionLink("Novels", "Index", "BooksAndStories", new { novel = true }, htmlAttributes: null)</li>
变成
<li><a asp-action="Index" class="nav-link" asp-controller="BooksAndStories" asp-route-novel="true">Novels</a></li>