duanfenhui5511 2014-04-22 17:25
浏览 48
已采纳

Bootstrap 3 <div>容器未对齐

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. I deliberately set the z-index to a higher value to show the overlap occurring. Seems like an offset of 11px but I can't explain that. Shouldn't they be aligned edge to edge correctly automatically? The goal is to have a sidebar 220px in width and 100% length.

I wrote some code in 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:

<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:

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;
}
  • 写回答

1条回答 默认 最新

  • douan3182 2014-04-22 18:34
    关注

    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). Essentially though, other elements don't recognize it as being there. See this post about css positions. You may have to apply a margin-top of the same amount of pixels as the navigation to get it to not overlap. For example, if the navigation bar height was 50px, then you could set the side-bar margin-top to 50px. Hopefully that was the problem. Again, this is assuming that the overflow is happening at the top.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?