Here is a simple demo that make the horizontal menu:
_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - MvcProj</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/MvcProj.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<!-- Sidebar -->
<nav class="col-md-3 col-lg-2 bg-light sidebar" style="position: fixed; top: 0; left: 0; height: 100vh;">
<div class="position-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="@Url.Action("Index", "Home")">
Home
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="@Url.Action("Privacy", "Home")">
Privacy
</a>
</li>
<!-- Add more links as needed -->
</ul>
</div>
</nav>
<!-- Main content -->
<main class="col-md-9 ms-sm-auto col-lg-10" style="margin-left: 250px; padding-top: 20px;">
@RenderBody()
</main>
</div>
</div>
<footer class="border-top footer text-muted">
<div class="container">
© 2024 - MvcProj - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Add the css in the default existing css file(site.css in wwwroot/css
folder)
.sidebar {
height: 100vh; /* Make the sidebar span the full height */
position: fixed; /* Fix it on the left side */
}
.nav.flex-column {
margin-top: 20px; /* Add some space at the top if necessary */
}
.nav-link {
font-size: 1.1rem; /* Adjust link size */
padding: 10px 15px; /* Adjust padding */
}
.main-content {
margin-left: 250px; /* Main content pushed to the right of sidebar */
padding-top: 20px; /* Add some padding at the top if necessary */
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena