Bootstrap - 为单页格式化Navbar和Container

时间:2016-11-07 21:00:13

标签: html css twitter-bootstrap

我想使用固定在页面顶部的引导程序导航栏。然后我想要一个覆盖页面其余部分的分区。我通过应用类容器流体来解决宽度问题。但是我已经将容器高度调整为93.5%并将html溢出设置为隐藏。这可以在全屏窗口中正常工作。但是,此解决方案似乎没有响应,并且在窗口大小调整时失败。我希望div容器的高度自动填充页面的其余部分。代码如下:

CSS

    html {
    height:100%;
    overflow:hidden;
}
body {
    height:100%;
}

#map-container{
    height:93.5%;
    border-color: black;
    border-style:solid;
    border-width:2px;
    margin:5px;

}
.navbar{
    margin-left:5px;
    margin-right: 5px;
    margin-top:5px;
    margin-bottom:0px;

}

HTML

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>quickMap</title>

    <!-- Bootstrap Core CSS -->
    <link href="~/Content/bootstrap.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="~/Content/quickMap.css" rel="stylesheet" >

</head>
<body>
    <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 class="navbar-brand" href="#">Brand</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">
                    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                    <li><a href="#">Link</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                    </li>
                </ul>
                <form class="navbar-form navbar-left">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default">Submit</button>
                </form>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">Link</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                        </ul>
                    </li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
    <div class="container-fluid" id="map-container">
        <div>

        </div>
    </div>
    <!-- jQuery -->
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我觉得溢出:隐藏着搞砸了你。我将它改为auto,它对我来说运作得很好。

    html {
height:100%;
overflow:auto;
}

不确定93.5%是高度的正确数字,因为,至少在我的浏览器中,div最终对于窗口来说有点太高了,但这可以通过稍微调整高度来修复。更像是91%。