固定元素的问题

时间:2017-04-15 12:38:56

标签: html css

我正在与我的页面的前端挣扎,

当需要滚动内容时,我试图将侧边栏,导航栏和标题栏保留在同一位置,同时允许内容滚动。

我认为我有这个工作,直到我在我的页面添加了一个面板,现在导致重叠。我故意让我的textarea大大低于显示这一点。

我无法直接发布图片,所以这是一个链接(我现在可以编辑): picture

正如您所看到的,我也在努力让我的面板内容扩展到面板的宽度

JSFiddle:https://jsfiddle.net/duwew6ke/

我的css文件:

    .body-content {
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 200px;
}

body {
    font-family: "Helvetica Neue",Roboto,Arial,"Droid Sans",sans-serif;
}


.dl-horizontal dt {
    white-space: normal;
}


input,
select,
textarea {
    max-width: 280px;
}


#sidebar {
    position: fixed;
    left: 0;
    width: 230px;
    height: 100%;
    border-right: 0.1px solid rgb(225, 225, 225);
    margin-top: 60px;
}

    #sidebar .sidebar-brand {
        height: 50px;
        width: 230px;
        font-weight: bold;
        padding-top:10px;
        display: block;
        margin: 0;
        border-bottom: 0.1px solid rgb(225, 225, 225);
        background-color: #fafafa;
        font: 500 20px Roboto,RobotoDraft,Helvetica,Arial,sans-serif;
    }

        #sidebar .sidebar-brand .search {
            display: block;

        }


        #sidebar .sidebar-brand h2 {
            margin: 0;
            padding-left: 10px;
            padding-top: 10px;
        }


#navbarwrapper .navbar-inverse {
    background-color: white;
    border-bottom: 0.1px solid rgb(225, 225, 225);
    font-family: 'Indie Flower', cursive;
    height: 60px;
    position: fixed;
    width: 100%; 
}

#navbarwrapper .navbar-brand {
    font-size: 2em;
    margin-top: 10px;
    color: #1976d2;
}

#navbarwrapper .userpicture {
    height: 50px;
    width: 50px;
}

#navbarwrapper .username {
    display: block;
    margin-top: 30px;
    font-size: 20px;
}

#navbarwrapper .bell {
    margin-right: 20px;
}


#navbarwrapper .envelope {
    margin-right: 20px;
}


#titlenavwrapper {
    margin-left: 230px;
    margin-top: 60px;
    position: fixed;
    width: 100%;
}

    #titlenavwrapper .navbar-inverse {
        height: 50px;
        background-color: #1976d2;
        font-size: 25px;
        color: whitesmoke;
        padding-left: 10px;
        padding-top: 7px;
    }

.body-content {
    margin: 0;
    margin-left: 230px;
    top: 110px;
    background-color: #fafafa;
    height: 100%;

}

    .body-content h2 {
        margin: 0;
    }

html, body {
    height: 100%;
}

面板代码:

<div class="row">
<div class="col-sm-6 col-sm-offset-3">
    <div class="panel">
        <div class="panel panel-heading">
            <i class="fa fa-telegram"></i> Contact Us!
        </div>

        <div class="panel panel-body">

            <form id="contactform" method="post">
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>

                <div class="form-group Name">
                    <label>Name</label>
                    <input class="form-control" />

                </div>

布局代码:

     <div id="sidebar">
    <div class="sidebar-brand">
        <span class="text-muted text-center"><i class="fa fa-search"></i>Search...</span>
    </div>

</div>


<div id="navbarwrapper">
    <nav class="nav navbar-inverse navbar-static-top">
        <div class="navbar-brand">
            Title
        </div>
        <div class="navbar profile-area">
            <img src="~/Content/img/default.jpg" class="userpicture img-circle pull-right" alt="userpicture"/>
            <span class="username pull-right"><i class="bell fa fa-bell"></i><i class="envelope fa fa-envelope"></i> Name</span>
        </div>
    </nav>
</div>

<div id="titlenavwrapper">
    <nav class="nav navbar-inverse navbar-static-top">
        <div class="navbar-title">
           @ViewBag.Title
        </div>
    </nav>
</div>

1 个答案:

答案 0 :(得分:2)

您需要将一个z-index添加到#titlenavwrapper

#titlenavwrapper{
  z-index:5;
}

click here for demo