I need help to make these two <div>'s (#side-nav and #content-wrapper) to scroll independently,
HTML:
<div id="wrapper">
<div id="top-nav">
Top nav
</div>
<div id="side-nav">
<ul>
<li>Thing</li>
<li>Thing</li>
</ul>
</div>
<div id="content-wrapper">
<!-- Ton of conent here -->
</div>
</div>
CSS:
#wrapper {
width: 100%;
background-color: #fff;
}
#top-nav {
position: fixed;
top: 0;
height: 60px;
width: 100%;
background-color: green;
}
#side-nav {
position: fixed;
width: 250px;
height:100vh;
overflow-y: scroll;
background-color: red;
}
#content-wrapper {
margin: 60px 0 0 250px;
padding: 0 30px;
overflow-y: scroll;
background-color: blue;
}
now if I scroll the #side-nav to the end or top, #content-wrapper will scroll too. #side-nav has to stay full-page height and fixed even if there is not that many <li>'s.
I've quickly made pen here:
http://codepen.io/blizqery/pen/QbZzRN
Thanks!
Check this: http://codepen.io/anon/pen/xGyMjM
You need to set height to content-wrapper, and also set the left, right & top.
#side-nav {
position: fixed;
width: 250px;
height:100vh;
left: 0;
right: 0;
overflow-y: scroll;
background-color: red;
top: 60px;
}
#content-wrapper {
margin: 60px 0 0 250px;
padding: 0 30px;
overflow-y: scroll;
position: fixed;
left: 0;
top: 0;
height:100vh;
background-color: blue;
}
I believe this works for your issue
body{
margin:0px;
}
#top-nav {
position: fixed;
top: 0;
height: 10vh;
width: 100%;
background-color: green;
}
#wrapper {
width: 100%;
background-color: #fff;
}
#side-nav {
float:left;
width: 250px;
height: 90vh;
overflow-y: scroll;
background-color: red;
}
#content-wrapper {
margin: 10vh 0 0 250px;
padding: 0 30px;
overflow-y: scroll;
background-color: blue;
height:90vh;
}
Related
.wrapper{
width: 1024px;
margin: auto;
}
.left-sidebar {
z-index: 9999;
width: 200px;
background: #303030;
height:100%;
overflow: auto;
}
#sidebar {
min-width: 200px;
min-height: 200px;
background: #303030;
color: #fff;
position:fixed;
transition: all 0.3s;
z-index:999;
height:100%;
width: 25%;
float: left;
}
<div class="wrapper">
<div class="left-sidebar">
<nav id="sidebar">
I would like to move this sidebar to the most left and top.
I have tried to remove padding but there is no padding so it did nothing.
How can I move the side bar to the most left and the most top?
Since you're using position: fixed. Simply set the top and left css property to 0 within your nav sidebar container.
.wrapper {
width: 1024px;
margin: auto;
}
.left-sidebar {
z-index: 9999;
width: 200px;
background: #303030;
height:100%;
overflow: auto;
}
#sidebar {
min-width: 200px;
min-height: 200px;
background: #303030;
color: #fff;
position: fixed;
top: 0;
left: 0;
transition: all 0.3s;
z-index: 999;
min-height: 100%;
width: 25%;
float: left;
}
<div class="wrapper">
<div class="left-sidebar">
<nav id="sidebar">
I have tried everything but footer is not at the bottom of page.
I tried position: fixed; but always when I scroll down it stays on the same position.
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px;
}
.footer, .push {
height: 142px;
background: black;
}
Use following CSS:
.footer {
position:fixed;
left:0px;
bottom:0px;
height:142px;
width:100%;
background:black;
}
here is test fiddle: https://jsfiddle.net/85nyb2mv/
If to use position: fixed, the element will always be at the same position of the screen. If you want footer to be at the bottom of wrapper element, try to give position: relative to .wrapper and position: absolute to .footer, it will place your footer at the bottom of wrapper. Here is an example:
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px;
background-color: gray;
position: relative;
}
.footer, .push {
height: 142px;
width: 100%;
background: black;
position: absolute;
bottom: 0;
left: 0;
}
<div class="wrapper">
<div class="footer"></footer>
</div>
Use this CSS styles:
.wrapper {
height: calc(100% - 142px);
margin: 0 auto;
}
.footer {
height: 142px;
background: black;
position: absolute;
bottom: 0;
right: 0;
left: 0;
z-index: 1;
}
CASE 1
When body' height is bigger than 100vh
body{
margin: 0;
padding: 0;
min-height: 100vh;
height: 2000px;
position: relative;
background: pink;
}
header{
width: 100vw;
height: 100px;
background: gold;
}
footer{
position: absolute;
bottom: 0px;
left: 0px;
width: 100vw;
height: 100px;
background:darkgray;
}
<body>
<header>
</header>
<footer>
</footer>
</body>
CASE 2
When body' height is smaller than 100vh
body{
margin: 0;
padding: 0;
min-height: 100vh;
height: 200px;
position: relative;
background: pink;
}
header{
width: 100vw;
height: 100px;
background: gold;
}
footer{
position: absolute;
bottom: 0px;
left: 0px;
width: 100vw;
height: 100px;
background:darkgray;
}
<body>
<header>
</header>
<footer>
</footer>
</body>
**html**
<body>
<header>
</header>
<section>
</section>
<footer>
</footer>
</body>
**CSS**
<style type="text/css">
footer {
position:fixed;
left:0px;
bottom:0px;
width:100%;
background:black;
color:#fff;
z-index:99;
}
</style>
The problem was <div class="fade">, so I removed it and added
.page-content:after {
content: "";
display: block;
}
<div class="page-content"> ----> between header and footer
I have a footer that is fixed. I have a header that is relative. In between these containers there is the content which is set to overflow-y:auto. Meaning the scrollbar should show for only in this div container. I have a container around this content div. The height for this div is set to pixels because when percentage is used, it automatically goes to 100% and the scrollbar is not visible. It looks perfect on 100% without changing the height of the screen. However, if the user were to change the height of the screen - the user can not see all of the content in the div because the fixed footer is now covering that. When the user zooms out, there is a white space in between the footer and the div. I would like it so that when the user zooms out there isn't a white space and when the user changes the height of the screen, the user can view all of the content.
HTML
<div class="top-container">
</div>
<div class="container">
<ul>
<li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li>
</ul>
</div>
<footer>
</footer>
CSS
.top-container {
position: relative;
z-index: 6;
background: #fff;
padding: 40px 40px 0;
bottom: 0;
width: 100%
}
.container {
padding: 10px 0;
margin: 0 .6%;
}
ul {
padding-top: 2px;
height: 437px;
overflow-y: auto;
overflox-x: hidden;
}
footer{
background: #fff;
padding: 20px 50px;
overflow: hidden;
position: fixed;
z-index: 5;
left: 0;
bottom: 0;
width: 100%;
}
JSFIddle This JSfiddle does not accurately show my issue. The scrollbar should only be displayed in the content and not the header. Which is what it is now.
Thanks
.top-container {
position: relative;
z-index: 6;
background: #fff;
padding: 40px 40px 0;
bottom: 0;
width: 100%;
max-height: 60px;
background: green;
}
.container {
padding: 10px 0;
margin: 0 .6%;
overflow-y: scroll;
height: calc(100vh - 100px);
background: blue;
}
ul {
padding-top: 2px;
height: 437px;
overflow-y: auto;
overflox-x: hidden;
}
footer{
background: #fff;
padding: 20px 50px;
overflow: hidden;
position: fixed;
z-index: 5;
left: 0;
bottom: 0;
width: 100%;
}
body{
max-height: 90vh;
}
footer{
background: red;
max-height: 40px;
}
<div class="top-container">
</div>
<div class="container">
<ul>
<li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li>
</ul>
</div>
<footer>
</footer>
Here is the updated jsFiddle
.top-container {
position: relative;
z-index: 6;
background: #fff;
padding: 40px 40px 0;
bottom: 0;
width: 100%
}
.container {
padding: 10px 0;
margin: 0 .6%;
}
ul {
padding-top: 2px;
//height: 437px;
overflow-y: auto;
overflox-x: hidden;
}
footer{
background: #fff;
padding: 20px 50px;
overflow: hidden;
z-index: 5;
width: 100%;
}
Is this what you want?
The idea is to have the banner and nav bar stuck to the top of the browser window which i don't want to scroll and the content underneath being able to scroll. The two sections of contentleft and contentright I want to have the same height even if the content isn't as big.
#charset "utf-8";
body {
margin: 0px;
padding: 0px;
}
.banner {
width: 100%;
height: 125px;
background-color: #034569;
position: relative;
top: 0px;
}
.nav {
width: 100%;
height: 50px;
background-color: #235B79;
}
.contentwrapper {
width: 100%;
background-color: #aaaaaa;
position: fixed;
top: 175px;
overflow-y: scroll;
}
#contentleft {
width: 25%;
height: auto;
background-color: #034569;
float: left;
}
#contentright {
width: 75%;
height: auto;
background-color: #ffffff;
float: right;
}
For your css you need the banner and nav bar to have the position:fixed property, which will prevent scrolling. If .contentwrapper has a static height declared we can make the div elements inside fill the height with height:100%;. Also we can assign html and body a height: html, body: height:100%;.
#charset "utf-8";
body, html {
margin: 0px;
padding: 0px;
height:100%;
}
.banner {
width: 100%;
height: 125px;
background-color: #034569;
position: fixed;
top: 0px;
}
.nav {
width: 100%;
height: 50px;
position: fixed;
top: 125px;
background-color: #235B79;
}
.contentwrapper {
width: 100%;
background-color: #aaaaaa;
padding-top: 175px;
height:300px;
overflow-y: scroll;
}
#contentleft {
width: 25%;
height: 100%;
background-color: #034569;
float: left;
}
#contentright {
width: 75%;
height: 100%;
background-color: #ffffff;
float: right;
}
I want #main to be 100%, but not affected by #upper -- pushed down by 39px and making the page scrollable. Overflow: hidden on body won't do it for me, since I need to see content at the bottom. How do I fix this? Something similar to sticky footer, or? I don't seem to understand it.
<body>
<div id="upper"></div>
<div id="main">
<div id="box"></div>
</div>
</body>
html, body {
margin: 0;
padding: 0;
min-height: 100%;
height: 100%;
}
#upper {
height: 39px;
width: 100%;
background: #212121;
}
#main {
display: block;
width: 100%;
min-height: 100%;
margin: 0 auto;
background: blue;
}
Picture of how it looks http://i46.tinypic.com/25k1jcn.jpg
An alternative to #Zoltan's answer:
html, body {
margin: 0;
padding: 0;
min-height: 100%;
height: 100%;
}
#upper {
height: 39px;
width: 100%;
background: #212121;
position: fixed;
top: 0;
left: 0;
}
#main {
display: block;
width: 100%;
margin: 0 auto;
background: lightblue;
position: fixed;
top: 39px;
bottom: 0;
}
<div id="upper"></div>
<div id="main">
<div id="box">Hi</div>
</div>
Try this - http://jsfiddle.net/ax7nq/
html, body {
margin: 0;
padding: 0;
min-height: 100%;
height: 100%;
}
#upper {
height: 39px;
width: 100%;
background: #212121;
position: absolute;
}
#main {
display: block;
width: 100%;
min-height: 100%;
margin: 0 auto;
background: lightblue;
}
#box {
padding-top: 39px;
}
Try changing #upper to this:
#upper
{
height: 39px;
width: 100%;
background: #212121;
position:absolute;
left:0;
top:0;
}