c# - 尝试在 MVC 4 Web 应用程序中将页脚置于容器之外

标签 c# html css asp.net-mvc-4

本质上,当使用 Visual Studio 2017 创建 MVC 4 应用程序时,页脚被限制在类 container body-content 的 div 内。在_layout.cshtml中。当然,这使得页脚被限制在 div 内:

enter image description here

但是我们想要的是页脚能够延伸页面的整个宽度,就像页眉一样。

当我注释掉div时,

enter image description here

页脚获得 100% 的宽度,但现在正文中的其他所有内容也是如此:

enter image description here

页脚下方还有一堆空白区域。这是 _layout.cshtml 的完整代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/Style.css")
@Scripts.Render("~/bundles/modernizr")

</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" id="navbar-gradient">
    <div class="container">
        <div class="navbar-header">
            <!--<img src="~/images/lion-logo.png" />-->
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <img src="~/images/lion-logo.png" id="logo"/>
                @Html.ActionLink("LION TECHNOLOGIES", "Index", "Home", new { area = "" }, new { @class = "navbar-brand", @id = "logo-text" })
        </div>
        <div class="navbar-collapse collapse" id="navbar-gradient">
            <!--hide links-->
            <ul class="nav navbar-nav" id="hidden">
                <li>@Html.ActionLink("Reports", "Index", "Home")</li>
                <li>@Html.ActionLink("Accounts", "About", "Home")</li>
                <li>@Html.ActionLink("Settings", "Contact", "Home")</li>
            </ul>
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>

   <!-- <div class="container body-content">-->
    @RenderBody()
    <!--<hr />-->
    <footer>
        <p>&copy; @DateTime.Now.Year - <img src="~/images/lion-logo.png" id="logo-footer" /> LION TECHNOLOGIES</p>
    </footer> 
    <!--</div>-->

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

</body>
</html>

我还尝试将所有内容包装在 <body></body>带有 container body-content 的标签div 但这没有任何效果。还有其他建议吗?

最佳答案

如果您使用的是 bootstrap 3,请尝试从具有类容器的 div 中删除页脚,然后使用类 continer-fluid 创建另一个 div,并将页脚代码放入其中。 .container 是固定宽度,.container-fluid 是全宽。请参见bootstrap 3的网格系统http://getbootstrap.com/css/#grid

<div class="container body-content">
    @RenderBody()
</div>
<div class="container-fluid">
    <hr />
    <footer>
          <p>&copy; @DateTime.Now.Year - <img src="~/images/lion-logo.png" id="logo-footer" /> LION TECHNOLOGIES</p>
    </footer>
</div>

关于c# - 尝试在 MVC 4 Web 应用程序中将页脚置于容器之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43989734/

相关文章:

c# - ASP.NET 核心 3.0 : The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace

javascript - 如何在ajax中使用动态添加的html类

javascript - 消息不显示在新行上

html - 使用母版页的网络表单不会占用整个页面

c# - Managed Wifi Win32 API 是否有可靠的 .Net 包装器?

c# - 使用 Selenium Webdriver 测试 SSRS Reporting Services 报告

c# - 从 BackgroundWorker 操作表单

jquery - 在悬停时突出显示每个表的相应元素的行和列

javascript - 为什么图像和边框之间有空间?

javascript - 使用 javascript 的 ASP 经典站点中的字体颜色不会改变