【问题标题】:Background image not scaling the entire section of the body of the page背景图像未缩放页面主体的整个部分
【发布时间】:2017-07-19 14:46:02
【问题描述】:

我无法将 MVC 页面中的背景图像设置为全屏。我屏幕上的输出如下

不确定是什么问题。我已将 body 标签的背景图像设置为覆盖在 app.css 文件中。正如您在屏幕截图中看到的那样,图像位于网格后面,并且仅在顶部可见。屏幕底部有空白,

我的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;

}

布局页面

<!DOCTYPE html>

<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 class="form-control">
                                    <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>

        @RenderBody()
    </div>



</body>
</html>

【问题讨论】:

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


    【解决方案1】:

    CSS:

    html,body {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover; /* For WebKit*/
        -moz-background-size: cover;    /* Mozilla*/
        -o-background-size: cover;      /* Opera*/
        background-size: cover;         /* Generic*/
    }
    

    或:

    background-size: 100% 100%; 
    

    【讨论】:

    • 我都试过了。第一个是 css3 不喜欢的。第二个显示的内容与屏幕截图中的相同
    • 我注意到的另一件事是,如果我评论 index.html 中的网格,图像就会消失。通常只需要图像。我不明白发生了什么。 index.html 中没有对图片的引用。
    • 你设置html标签了吗?
    • 是的。我已经放了html标签
    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 2018-06-03
    • 2017-04-17
    相关资源
    最近更新 更多