I am struggling to set an image as the background for my first ASP.NET Core project. However, when I add the image, it also appears like a footer on the page instead of being positioned between the header and footer sections.
Here is a picture of the background
Below is my shared _Layout code:
@using CarRental.Common
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name = "viewport" content="width=device-width, initial-scale=1.0" />
<title>@this.ViewData["Title"] - @GlobalConstants.SystemName</title>
<link href = "~/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" asp-append-version="true" />
<link href = "~/css/site.min.css" rel="stylesheet" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">@GlobalConstants.SystemName</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<partial name="_LoginPartial" />
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Settings" asp-action="Index">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<partial name="_CookieConsentPartial" />
<main role="main" class="pb-3">
@this.RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
© @DateTime.Now.Year - @GlobalConstants.SystemName - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js" asp-append-version="true"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js" asp-append-version="true"></script>
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js" asp-append-version="true"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.min.js" asp-append-version="true"></script>
<script src="~/js/site.min.js" asp-append-version="true"></script>
@this.RenderSection("Scripts", required: false)
</body>
</html>
Here is the home page code where I have added the background image:
@using CarRental.Common
@{
this.ViewData["Title"] = "Home Page";
}
<style>
body {
background-image: url(/images/background-home.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
<div class="text-center">
<h1 class="display-4" style="color:gold">Welcome to ElisCar! </h1>
</div>
I believe that I need to make adjustments in the home index.cshtml file to resolve this issue. Thank you.