Bootstrap主容器被navbar黯然失色

时间:2018-07-21 14:44:28

标签: html css twitter-bootstrap containers navbar

我正在尝试从入门页面试用引导程序。我希望一切都会顺利进行,并且该页面应按照初始页面显示的方式呈现。但是我遇到了一个奇怪的问题(据我所知),不能将主容器放置在页面的中心。实际上,如屏幕截图所示,主容器与导航栏位于同一位置。 IE和Firefox上的结果相同。而且我还没有自定义bootstrap.min.css。

the position of main container in inspection mode

源html如下:

PreparedStatement

能请你帮忙吗?

3 个答案:

答案 0 :(得分:1)

导航栏应放在这样的容器中

<main class="container" role="main">
    <nav class="navbar navbar-expand-sm navbar-dark fixed-top" style="background-color: #124191;">
        <a class="navbar-brand" href="#">
            <Google></Google>
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse" id="navbarsExampleDefault">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item"><a class="nav-link" href="#">Google </a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Google</a></li>
                <li class="nav-item dropdown"><a class="nav-link dropdown-toggle" id="dropdown01" href="https://example.com" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
                    <div class="dropdown-menu" aria-labelledby="dropdown01"><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Another action</a><a class="dropdown-item" href="#">Something else here</a></div>
                </li>
            </ul>
        </div>
    </nav>
    <div class="card" style="width: 18rem;">
        <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card&apos;s content.</p><a class="card-link" href="#">Card link</a><a class="card-link" href="#">Another link</a></div>
    </div>
</main>

答案 1 :(得分:1)

您必须在主体上添加填充,以便将其推入导航栏下方。将其放在引导文件之后引用的css文件中

body { padding-top: 70px; }

答案 2 :(得分:0)

只需将“ navbar-fixed-top”类添加到navbar calss