简体   繁体   English

引导程序3 <div> 容器未对齐

[英]Bootstrap 3 <div> container not aligned

I have a little problem with the alignment of my div containers, using Bootstrap 3. There is an overlap of my left sidebar and the top navigation-bar and I don't know why. 使用Bootstrap 3,我的div容器的对齐方式存在一些问题。左侧边栏和顶部导航栏重叠,我不知道为什么。 I deliberately set the z-index to a higher value to show the overlap occurring. 我特意将z-index设置为更高的值,以显示发生的重叠。 Seems like an offset of 11px but I can't explain that. 似乎偏移量为11px,但我无法解释。 Shouldn't they be aligned edge to edge correctly automatically? 它们是否应该自动正确地边缘对齐? The goal is to have a sidebar 220px in width and 100% length. 目标是使边栏的宽度为220px,长度为100%。

I wrote some code in HTML/PHP: 我用HTML / PHP编写了一些代码:

<?php
include 'core/includes/overall/header.php';
?>
<div class="site-holder">
    <?php include 'core/includes/topNavigation.php' ?>
    <div class="row">
        <div class="left-sidebar">
            <?php include 'core/includes/leftSidebar.php'; ?>
        </div>
    </div>
    <?php include 'core/includes/overall/footer.php'; ?>
</div>

This is the site structure of the whole page. 这是整个页面的站点结构。 After including the top navigation bar I want to use the grid-system to implement a left-sidebar. 包括顶部导航栏后,我想使用网格系统实现左侧栏。 The code for both is this: 两者的代码是这样的:

TOP-NAVIGATIONBAR: TOP-导航栏:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">MEDIFAKTOR online</a>
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse navHeaderCollapse">
            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="#">Start</a></li>
                <li><a href="#">Blog</a></li>
            </ul>
        </div>
    </div>
</div>

LEFT-SIDEBAR: 左侧的侧边栏中:

<ul class="nav">
    <li class="active">
        <a href="#">Dashboard</a>
    </li>
    <li class="">
        <a href="#">Test</a>
    </li>
</ul>

The style.css used is: 使用的style.css是:

body {
    padding-top: 50px;
}

.template-setup {
    padding: 40px 15px;
    text-align: left;
}

.site-holder {
    min-height: 1200px;
    overflow: hidden;
    position: relative;
}

.box-holder {
    min-height: 1200px;
}

.content {
}

.left-sidebar {
    font-family: 'Open Sans', sans-serif;
    background-color: #BBBBBB;
    color: #80969C;
    width: 220px;
    position: absolute;
    z-index: 1050;
}

Because navigation has a class .navbar-fixed-top, bootstrap assigned a position:fixed style rule which then removes it from the flow (forgetting the official term right now). 由于导航具有.navbar-fixed-top类,因此引导程序分配了position:fixed样式规则,然后将其从流中删除(现在忘记了正式用语)。 Essentially though, other elements don't recognize it as being there. 从本质上讲,其他元素不会将其识别为存在。 See this post about css positions . 有关CSS位置,请参阅此帖子 You may have to apply a margin-top of the same amount of pixels as the navigation to get it to not overlap. 您可能必须应用与导航相同数量的像素的margin-top ,以使其不重叠。 For example, if the navigation bar height was 50px, then you could set the side-bar margin-top to 50px. 例如,如果导航栏的高度为50px,则可以将侧栏的margin-top设置为50px。 Hopefully that was the problem. 希望这就是问题所在。 Again, this is assuming that the overflow is happening at the top. 同样,这是假定溢出发生在顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM