im learning css in general and i am failling very, - v e r y - hard at it...
im trying to do a simple thing with my css grid, just animate the hidden menu right to left, instead of left to right, but i dont know what i must change to do it..
Can you guys help me? Here the fiddle: https://jsfiddle.net/xwvL2a70/
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
min-height: 100vh; /* override Safari bug */
position: fixed; /* or choose `absolute` depending on desired behavior*/
width: 300px;
left: -340px;
}
#nav:target {
transform: translateX(340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
You just need to change your left: -340px; to right: -340px; and then your transform: translateX(340px); to transform: translateX(-340px);. Both of these are within the media query.
Here's a working example (if you view in full screen and scale the window width down to preview):
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
<div class="support-grid"></div>
<div class="container">
<header role="banner">
<a class="toggle open" href="#nav">open</a>
<h1>Header</h1>
</header>
<nav id="nav" role="navigation">
<a class="toggle close" href="#">×</a>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</nav>
<section role="main">
<article>
<h2>Article</h2>
<p>Curabitur orci lacus, auctor ut facilisis nec, ultricies quis nibh. Phasellus id diam sollicitudin, malesuada turpis id, gravida erat. Maecenas placerat elit vel hendrerit convallis. Sed in mauris ut justo vulputate viverra feugiat ac dui. Fusce feugiat arcu in vehicula vehicula. Donec varius justo at nulla aliquet volutpat.</p>
<p>Ut id rutrum eros. Nulla tristique, magna et mattis vulputate, mi eros suscipit turpis, nec bibendum turpis nunc feugiat sapien. Nunc arcu est, lacinia id diam quis, sagittis euismod neque. Nullam fringilla velit sed porta gravida. Proin eu vulputate libero. Ut a lacinia enim. Etiam venenatis mauris et orci tempor congue. Sed tempor eros et ultricies congue. Aenean sed efficitur orci. Nulla vel tempus mi.</p>
<p>Ut cursus suscipit augue, id sagittis nibh faucibus eget. Etiam suscipit ipsum eu augue ultricies, at rhoncus mi faucibus. In et tellus vitae leo scelerisque fringilla nec at nunc.</p>
</article>
</section>
<aside>
<h3>Aside</h3>
</aside>
<footer>
<h3>Footer</h3>
</footer>
</div>
Related
So I'm trying to right align the itens inside of the ul. I want the item to touch the right border.
Did some research and tried to use "justify-items: end;" inside of the grid (container). Didn't work.
Tried to use "justify-self: end;" in the right element, also didn't work.
Created a flexbox, inside of the <ul> , and tried "align-items: flex-end" , also didn't work.
I don't know what to do. Probably can't align because there is a space between the item and the right margin (which I've put a green background for everyone to see), but I dont know where this space come from, also don't know how to remove it. Tried to do margin:0 and padding:0, but it didn't work.
* {
box-sizing: border-box;
}
body,html{
height:100%;
margin:0;
}
.container{
display:grid;
grid-template-columns: 35% 2fr;
grid-template-areas: "leftEl rightEl";
justify-content: center;
align-content: center;
padding: 1.5rem;
height: 100%;
}
.right{
grid-column: rightEl;
justify-self: end; /*not working*/
border: 3px solid black;
}
ul{
list-style-type: none;
background-color: aquamarine;
display: flex;
flex-direction: column;
align-items: flex-end; /* not working */
padding: 0;
}
.li-el{
display: flex;
justify-content: space-between;
padding: 1.5rem;
cursor: pointer;
border-bottom: 4px solid rgba(0,0,0,0.2);
color: white;
transform: rotateY(-22deg) rotateX(7deg);
}
.li-el p{
margin: 1.5rem;
}
.li1{
background-color: rgba(37, 187, 112);
}
.li2{
background-color: rgb(154, 169, 168);
}
.li3{
background-color: rgb(89, 188, 224);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style2.css">
<title>Document</title>
</head>
<body>
<div class="art1"></div>
<div class="art2"></div>
<div class="container">
<div class="right">
<ul>
<li class="li-el li1">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
<li class="li-el li2">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
<li class="li-el li3">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
</ul>
</div>
</div>
</body>
</html>
Because you have transformed the li elements to skew their boxes. I added margin-right: -6px on them and it bumped them over:
* {
box-sizing: border-box;
}
body,
html {
height: 100%;
margin: 0;
}
.container {
display: grid;
grid-template-columns: 35% 2fr;
grid-template-areas: "leftEl rightEl";
justify-content: center;
align-content: center;
padding: 1.5rem;
height: 100%;
}
.right {
grid-column: rightEl;
justify-self: end;
/*not working*/
border: 3px solid black;
}
ul {
list-style-type: none;
background-color: aquamarine;
display: flex;
flex-direction: column;
align-items: flex-end;
/* not working */
padding: 0;
}
.li-el {
display: flex;
justify-content: space-between;
padding: 1.5rem;
cursor: pointer;
border-bottom: 4px solid rgba(0, 0, 0, 0.2);
color: white;
transform: rotateY(-22deg) rotateX(7deg);
margin-right: -6px;
}
.li-el p {
margin: 1.5rem;
}
.li1 {
background-color: rgba(37, 187, 112);
}
.li2 {
background-color: rgb(154, 169, 168);
}
.li3 {
background-color: rgb(89, 188, 224);
}
<div class="container">
<div class="right">
<ul>
<li class="li-el li1">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
<li class="li-el li2">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
<li class="li-el li3">
<p>Pellentesque pretium ullamcorper ullamcorper. Aenean quis accumsan eros. Fusce pretium risus a risus pretium ornare. </p>
</li>
</ul>
</div>
</div>
I need some help with a practice project I'm working on. I've got my content divs (.primary, .secondary and .tertiary) sat within a wrapper that's currently set to 100% width (for the sake of debugging).
I want it so that .primary and .secondary appear next to each other side by side at a screen size of 779px and above with tertiary set at 100% of the wrapper's width below them.
All three content divs also have the class col which I've floated left so in theory, I should be able to set .primary and .secondary to 50% and they should happily sit next to each other, right?
Wrong.
They sit as blocks below each other. Both have a width of exactly half of the wrapper (used dev tools in google chrome to check) but they won't sit next to each other until I sit their widths to 48% and then they leave a gap to their immediate right.
I honestly can't make heads or tails of it. I'm going to include the full code below for anyone that wants to just copy and paste to see the weirdness. I should note as well, there is a normalize file on there, downloaded from: https://necolas.github.io/normalize.css/
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Dragon Ball Fan Site</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,400i,700" rel="stylesheet">
</head>
<body>
<header class="main-header clearfix">
<div class="container">
<h1 class="title">Dragon Ball Fan Site</h1>
<ul class="main-nav">
<li>Main</li>
<li>Manga</li>
<li>Anime</li>
<li>Video Games</li>
<li>Register</li>
</ul>
</header>
<div class="banner">
<img src="img/main-img.png" alt="Main Image, Goku" class="main-img">
<h1 class="name">Dragon Ball Fansite</h1>
<span class="tagline">A Site For Fans, By Fans</span>
</div>
</div>
<div class="wrapper clearfix">
<div class="secondary col">
<h2>Welcome</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel dui at odio imperdiet pulvinar vitae sed arcu. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel dui at odio imperdiet pulvinar vitae sed arcu. Cras accumsan leo nulla, at suscipit augue finibus ac. Aliquam ut mi vulputate, ullamcorper metus quis, tempor lorem. Praesent eleifend dignissim ligula. Nunc enim lectus, fringilla at odio vel, sagittis volutpat velit. Integer pretium ac nisl eget volutpat.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="primary col">
<h2>About Dragon Ball</h2>
<img src="img/cast.png" alt="Main Cast" class="cast">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel dui at odio imperdiet pulvinar vitae sed arcu. Cras accumsan leo nulla, at suscipit augue finibus ac. Aliquam ut mi vulputate, ullamcorper metus quis, tempor lorem.</p>
</div>
<div class="tertiary col">
<h2>About Us</h2>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Ut vel dui at odio imperdiet pulvinar vitae sed arcu. Cras accumsan leo nulla, at suscipit augue finibus ac.</li>
<li>Aliquam ut mi vulputate, ullamcorper metus quis, tempor lorem.</li>
</ul>
</div>
</div>
</div>
<footer class="main-footer">
<span class="copyright"> ©Dragon Ball Fan Site 2018</span>
</footer>
</body>
</html>
/* =========
Fonts
========= */
#font-face {
font-family: 'Roboto', sans-serif;
}
##font-face {
font-family: 'saiyain-sans';
src: url(font/Saiyan-Sans.ttf);
}
/* =========
Elements
========= */
* {
margin: 0;
padding: 0;
}
body {
font-family: 'Roboto', helvetica, sans-serif;
font-size: 1.25em;
}
h1 {
margin: 0;
font-weight: 400;
font-size: 2.441em;
}
h2 {
font-size: 1.953em;
padding-bottom: 1em;
padding-left: 0;
padding-right: 0;
}
p {
line-height: 1em;
margin: 0;
padding: 0;
}
div {
margin: 0;
}
/* =========
Classes
========= */
.main-header {
text-align: center;
color: #f85b1a;
margin-bottom: 1em;
padding-top: 2em;
}
.title {
padding-bottom: 1em;
}
.main-nav li {
padding-bottom: 0.5em;
font-weight: 400;
}
.main-nav a {
text-decoration: none;
color: #f85b1a;
display: block;
}
.banner {
text-align: center;
background-color: #f85b1a;
color: #fff;
padding: 1em;
margin-bottom: 2em;
}
.main-img {
border-radius: 50%;
border: 3px solid #000;
margin-bottom: 2em;
}
.name {
font-family: 'saiyain-sans', 'Roboto', sans-serif;
margin-bottom: 0;
}
.wrapper {
margin: 0 auto;
width: 90%;
}
.col {
border: 1px solid red;
}
.primary,
.secondary {
margin-bottom: 1em;
}
.cast {
width: 100%;
padding: 0;
margin: 0 auto;
}
.main-footer {
background-color: #072083;
text-align: center;
padding: 1em;
margin-top: 1em;
}
.copyright {
font-size: 0.8em;
color: #8a9294;
}
/* =========
media queries
========= */
#media (min-width: 779px) {
.container {
margin: 0 auto;
}
.main-header {
padding: 1em;
}
.title,
.col {
float: left;
}
.title {
padding-top: 0;
padding-bottom: 0;
font-size: 1.25em;
}
.main-nav {
float: right;
}
.main-nav li {
display: inline-block;
float: left;
list-style: none;
font-size: 1.25em;
padding: 0 0.2em;
border-right: 1px solid #8a9294;
}
.main-nav li:last-child {
border-right: none;
}
.name {
padding-bottom: 0.5em;
}
.tagline {
font-size: 1.5em;
}
.wrapper {
width: 100%;
padding: 0;
}
.secondary,
.primary {
width: 50%;
}
.copyright {
padding: 2em;
}
/* =========
Clearfix
========= */
.clearfix::after {
content: " ";
display: table;
clear: both;
}
}
I finally figured it out. It was the border box property. Adding any padding and things like that were pushing it to be bigger than the wrap. I had the border property added to test where it was going wrong and that was just adding to the problem.
Thanks to everyone that took the time to look.
i saw a website that had a cool effect when the hamburger menu opened, the site moved with the menu, how do i achieve that?
Currently i have this: https://jsfiddle.net/xwvL2a70/1/
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
I would like to make an animation like this site: https://vizir.com.br/
When you click the menu, the content moves to the left with it.
I dont know if its an easy question, im really new to this and just looking to learn some neat effects, is it hard to create a menu/website animation like this?
I think what you may be looking for is this link here How To Side Navigation
Specifically this part here, which is not only changing the width of the sidenav with a nice transition, but also changing the margin on the main content
/* Set the width of the side navigation to 250px and the left margin of the
page content to 250px */
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
}
I tried to work on your issue and it resolves. Please have a look at my Codepen https://codepen.io/navdeepsingh/pen/VyVPeP
const open = document.querySelector('#open');
open.addEventListener('click', function() {
document.querySelector('body').classList.add('menu-opened');
});
const close = document.querySelector('#close');
close.addEventListener('click', function() {
document.querySelector('body').classList.remove('menu-opened');
});
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
transition: all .3s ease-in-out;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
section {
postion: fixed;
}
body.menu-opened .container {
margin: 0 80% 0 -80%;
}
}
<div class="support-grid"></div>
<div class="container">
<header role="banner">
<a class="toggle open" id="open" href="#nav">open</a>
<h1>Header</h1>
</header>
<nav id="nav" role="navigation">
<a class="toggle close" id="close" href="#">×</a>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</nav>
<section role="main">
<article>
<h2>Article</h2>
<p>Curabitur orci lacus, auctor ut facilisis nec, ultricies quis nibh. Phasellus id diam sollicitudin, malesuada turpis id, gravida erat. Maecenas placerat elit vel hendrerit convallis. Sed in mauris ut justo vulputate viverra feugiat ac dui. Fusce feugiat arcu in vehicula vehicula. Donec varius justo at nulla aliquet volutpat.</p>
<p>Ut id rutrum eros. Nulla tristique, magna et mattis vulputate, mi eros suscipit turpis, nec bibendum turpis nunc feugiat sapien. Nunc arcu est, lacinia id diam quis, sagittis euismod neque. Nullam fringilla velit sed porta gravida. Proin eu vulputate libero. Ut a lacinia enim. Etiam venenatis mauris et orci tempor congue. Sed tempor eros et ultricies congue. Aenean sed efficitur orci. Nulla vel tempus mi.</p>
<p>Ut cursus suscipit augue, id sagittis nibh faucibus eget. Etiam suscipit ipsum eu augue ultricies, at rhoncus mi faucibus. In et tellus vitae leo scelerisque fringilla nec at nunc.</p>
</article>
</section>
<aside>
<h3>Aside</h3>
</aside>
<footer>
<h3>Footer</h3>
</footer>
</div>
`
I'm trying to making my tabs work via the radiobutton hack / checkbox hack. My tabs are positioned in the bottom and when you click them the content shows up above them, however, my tabs inactive tabs disappear. Any ideas why?
Here's my demo JSFIDDLE
HTML
<h1> id elementum risus</h1>
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1">
<label for="tab-1">Tab One</label>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus varius urna, ac venenatis arcu convallis consequat. In augue est, posuere auctor facilisis varius, dictum ac risus. Donec nibh justo, aliquam sed tempus quis, lobortis sed orci.
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab Two</label>
<div class="content">
Vivamus id elementum risus. In sit amet mi nulla, ac sollicitudin odio. Phasellus laoreet leo vitae velit lobortis at condimentum odio placerat. Nam sapien eros, accumsan id porttitor a, commodo ut urna. Cras dignissim metus quis enim placerat lobortis.
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">Tab Three</label>
<div class="content">
Phasellus scelerisque luctus ligula, a consequat orci posuere rutrum. Sed ipsum nisi, ullamcorper eget fermentum a, dignissim sed dolor. Mauris viverra pretium ante, eu mollis nisi volutpat quis. Nunc neque erat, pharetra in feugiat eget, faucibus id sem.
</div>
</div>
</div>
CSS
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin: 25px 0;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
margin-left: -1px;
position: relative;
left: 1px;
bottom: -10px;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: 0;
left: 0;
background: white;
right: 0;
bottom: 0;
padding: 20px;
height: 100px;
min-width: 350px;
display: none;
}
[type=radio]:checked ~ label {
background: white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
}
[type=radio]:checked ~ .content {
display: block;
}
[type=radio]:checked ~ label {
bottom:-149px;
}
For some reason in your code you were setting the top and bottom of content to 0 which caused it to cover the other tabs. Here is a working version:
http://jsfiddle.net/sKjc4/3/
CSS:
.tabs {
position: relative;
/* This part sucks */
clear: both;
margin: 25px 0;
min-height: 50px;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
margin-left: -1px;
position: relative;
left: 1px;
bottom: -10px;
}
.tab[type=radio] {
display: none;
}
.content {
position: absolute;
top: 100%;
left: 0;
background: white;
right: 0;
height: 100px;
min-width: 350px;
display: none;
}
[type=radio] {
display: none;
}
[type=radio]:checked ~ label {
background: white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
}
[type=radio]:checked ~ .content {
display: block;
}
I'm trying to get the #sidebar element to scroll overflow once the browser window is shorter than it's minimum height but can't seem to get it working. Any idea why?
http://jsfiddle.net/q5jKM/1/
CSS - Sorry I cant get this funky formatting working.
html,body{height:100%;margin:0}
#sidebar {
width: 20em;
position:fixed;
top: 0;
bottom: 0;
left: 0;
z-index:2;
color: #ffffff;
background-color: #333333;
overflow:auto;
min-height: 34em;
}
#sidebar .nav {
width: 3em;
float: right;
overflow: auto;
background-color: #2e2e2e;
border-left: 2px groove #454545;
height: 100%;
position:relative;
}
#sidebar .content {
height: 100%;
width: 16.875em; /* 17-(2/16) - 20em - .nav - nav border*/
float:left;
position:relative;
}
#sidebar .top {
position:absolute;
top:0;
}
#sidebar .bottom {
position:absolute;
bottom:0;
}
#sidebar .middle {
position: absolute;
bottom: 12em; /* 3.125*3 */
top: 16em; /* 3.125*4 */
background: green;
}
.content .middle {
overflow:auto;
}
#sidebar .content > div {width: 16.875em; } /*.top .middle .bottom*/
#sidebar .nav > div {width:3em; } /*.top .middle .bottom*/
/*table-cell trying get vertical-align working*/
#sidebar .table-cell {display:table-cell;}
#sidebar .middle .table-cell {vertical-align: middle;}
#sidebar .content p, #sidebar .content li, #sidebar .content img {font-size: .75em; color: #dddddd;}
#sidebar ul {margin:0; padding: 0;}
#sidebar .nav li {
padding: .5625em;
list-style:none;
}
#sidebar .nav li img {
height: 1.875em;
width: 1.875em
}
#sidebar .nav .top li { border-bottom: 2px groove #454545 }
#sidebar .nav .bottom li { border-top: 2px groove #454545 }
.content li {
position:relative;
display:block;
background-color: #444;
padding: .72em;
border-radius: .8em;
border-bottom: 1px solid #292929;
border-top: 1px solid #4c4c4c;
text-align: center;
font-size: 1em;
letter-spacing: .1em;
font-weight: normal;
height: 1.2em;
}
.content li:after {
content:"";
position:absolute;
display:block;
width:0;
top:.11em; /* controls vertical position */
right:-.852em; /* value = - border-left-width - border-right-width */
border-style:solid;
border-width:1.2em 0 1.2em 1.2em;
border-color:transparent #444;
}
.content .top li{margin: .95em 0 1.9em 0;}
.content .bottom li{margin: 1.9em 0 .95em 0;}
.content .logo {
text-align: center;
padding: 1em 0 2em 0;
width: 100%;
border-bottom: 2px groove #454545;
}
.content p.welcome {
text-align: center;
line-height: 1.5em;
margin: 1em 0;
}
HTML
<div id="sidebar">
<div class="nav">
<div class="top">
<ul>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
</ul>
</div>
<div class="middle"><div class="table-cell"><p>test</p></div></div>
<div class="bottom">
<ul>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
</ul>
</div>
</div>
<div class="content">
<div class="top">
<ul>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
</ul>
</div>
<div class="middle"><div class="table-cell">
<div class="logo"><img src="_images/g.svg"></div>
<p class="welcome">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris dictum tellus viverra neque bibendum in mattis ante dignissim. Nam mattis feugiat lorem porttitor adipiscing. Aliquam erat volutpat. Nunc feugiat magna vitae mauris egestas euismod. In hac habitasse platea dictumst. Praesent magna sem, malesuada non fermentum vel, luctus quis mauris. Duis quam purus, ornare vitae eleifend sed, malesuada eget libero. Phasellus sed lorem risus, nec placerat urna. In magna turpis, accumsan ac egestas quis, dictum vel massa. Nulla vitae magna arcu. Maecenas sit amet vestibulum urna. Integer feugiat dignissim leo sed ornare. Maecenas auctor ultricies dui, pulvinar tincidunt velit feugiat quis. Sed egestas ornare elit, et fringilla quam viverra ut.</p>
</div></div>
<div class="bottom">
<ul>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
</ul>
</div>
</div>
</div>
Got it!
Add: - So that #sidebar's is equal to the browser window.
#sidebar{height:100%}
And add: - To provide content that overflows.
#sidebar .nav, #sidebar .content {min-height:34em}
Once the browser window becomes shorter than 34ems #sidebar will overflow.
You just need to add a CSS media query rule:
#media all and (min-height: 34em) {
#sidebar{
overflow: scroll;
}
}
Once the browser height is less than 34em, then the overflow: scroll rule will be added to the #sidebar.
Use overflow scroll instead of auto
See this http://jsfiddle.net/q5jKM/2/
I got this to work using jquery - you need to get the height of the browser and adjust the css overflow to scroll when it reaches a certain height
var heightToScroll = 600;
var viewHeight = $(window).height();
$(window).resize(function() {
if(viewHeight < heightToScroll){
$('#sidebar').css("overflow","scroll");
}
});
http://jsfiddle.net/q5jKM/3/