Reputation: 49
How can I get a fixed Header with a fixed Sidebar and a Content Div?
What i did so far:
body {
margin:0;
}
.header {
width: 100%;
background: #303030;
background-repeat: repeat;
background-size: 38px 133px;
height: 40px;
background-position: 0px 39px;
box-shadow: 0px 1px 5px;
position: fixed;
z-index: 1000;
}
.sidebar {
z-index: 100;
position: fixed;
height: 100%;
width: 200px;
background: #303030;
}
.content {
padding: 10px;
width: 810px;
margin: auto;
min-height: 30px;
box-shadow: 0px 1px 5px;
background-color: rgba(255,255,255,0.7);
margin-left: 20%;
}
<div class="header"></div>
<div class="sidebar"></div>
<div class="content"></div>
But at the moment it's not stable and a bit weird. Means for example that the Content Div is floating under my sidebar and else.
Does someone know a better and more effective was to solve this?
Upvotes: 2
Views: 123
Reputation: 686
I Think it will help you, For u'r understanding i have added red border for content div. Only I changed the CSS.
.content {
position: fixed;
top: 41px;
bottom: 0px;
left: 200px;
border: 2px solid red;
right: 0px;
}
body {
margin:0;
}
.header {
width: 100%;
background: #303030;
background-repeat: repeat;
background-size: 38px 133px;
height: 40px;
background-position: 0px 39px;
box-shadow: 0px 1px 5px;
position: fixed;
z-index: 1000;
}
.sidebar {
z-index: 100;
position: fixed;
height: 100%;
width: 200px;
background: #303030;
}
.content {
position: fixed;
top: 41px;
bottom: 0px;
left: 200px;
border: 2px solid red;
right: 0px;
}
<div class="header"></div>
<div class="sidebar"></div>
<div class="content"></div>
Upvotes: 1
Reputation: 468
There are minor changes in your CSS like:
.content {
padding: 10px;
width: 810px;
min-height: 30px;
box-shadow: 0px 1px 5px;
background-color: rgba(255,255,255,0.7);
margin-left: 200px;
margin-top: 40px;
}
.header{top:0}
This will do the trick. If not please comment.
Upvotes: 1