在mvc布局页面中设置背景图像

时间:2017-02-27 18:49:51

标签: html css3 asp.net-mvc-5

我正在尝试在MVC布局页面中设置背景图像。我创建了CSS。如何在布局中设置它。不确定放在哪里。

以下是我的css文件

app.css

body {
    font-family: Helvetica, sans-serif, sans-serif;
    font-size: 13px;
    border-top: none;
    background-image: url('../Images/iNeed__waterfall_BG.jpg');
    background-repeat: no-repeat;
    background-size: cover;
      background-color:red;
}



.navbar {
    margin-bottom: 0px;
    padding: 0;
    background-color:white;
}

.navbar-header img{
    width: auto;
    height: auto;
    padding-top:15px;
}

nav navbar-nav navbar-right{
    text-align:center;
}

.hideli {
    padding-right: 200px;
}

以下是我项目的布局页面。

布局页面

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2017.1.223/kendo.common-bootstrap.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2017.1.223/kendo.mobile.all.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2017.1.223/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2017.1.223/kendo.bootstrap.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2017.1.223/kendo.dataviz.bootstrap.min.css")" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <link href="~/Content/app.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-3.1.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script src="@Url.Content("~/Scripts/kendo/2017.1.223/jquery.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/2017.1.223/angular.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/2017.1.223/jszip.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/2017.1.223/kendo.all.min.js")"></script>

</head>
<body >

    <header>
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a href="#"><img src="~/Images/NGSR-logo.jpg" /> </a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

                    <ul class="nav navbar-nav navbar-right text-center">
                        <li><a href="#"><span class="glyphicon glyphicon glyphicon-file" aria-hidden="true"></span><p>Requests</p></a></li>
                        <li><a href="#"><span class="glyphicon glyphicon-tasks" aria-hidden="true"></span><p>Activities</p></a></li>
                        <li><a href="#"><span class="glyphicon glyphicon glyphicon-file" aria-hidden="true"></span><p>Reports</p></a></li>
                        <li><a href="#"><span class="glyphicon glyphicon glyphicon-file" aria-hidden="true"></span><p>Admin</p></a></li>


                        <li class="dropdown hideli">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                <select>
                                    <option><a href="#">ALL</a></option>
                                    <option><a href="#">DE</a></option>
                                    <option><a href="#">GB</a></option>
                                    <option><a href="#">FR</a></option>
                                </select>
                                <p>Country</p>
                            </a>
                        </li>

                        <li><a href="#"><span class="glyphicon glyphicon-save" aria-hidden="true"></span><p>Save View</p></a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>

    </header>

    <div>

        @*<img src="~/Images/iNeed__waterfall_BG.jpg" />*@
        @RenderBody()
    </div>
</body>
</html>

的HomeController

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }
  }

的index.html

@{
    ViewBag.Title = "Home Page";
}

3 个答案:

答案 0 :(得分:0)

我认为你把它放在正确的地方,但你需要用引号包装你的文件路径并使用&#39;背景&#39;属性。

背景:网址(&#39; ../ Images / iNeed__waterfall_BG.jpg&#39;);

答案 1 :(得分:0)

您没有将Main.css包含在HTML中。

将以下内容添加到HTML <head>部分。

<link rel="stylesheet" type="text/css" href="Main.css">

答案 2 :(得分:0)

我会把它放在这里:

<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/app.css" rel="stylesheet" />
<link href="~/Content/Main.css" rel="stylesheet" />  /* <-- HERE */