CSS Flexbox - Sticky Top and Side navbar, with scroll - html

I would like:
A 50px tall header with a sticky nav below.
Side nav sticky at same point as top nav.
Both navs retain scroll ability.
Non-sticky footer that stays at the very bottom.
I was able to get one of the following to work at a time:
Scrolling to work with fixed header & top nav
Sticky top nav to work with non-fixed main elements
I need to get them both to work simultaneously.
HTML/CSS only solution preferred.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
/* ! BODY / HTML */
html,
body {
background-color: red;
}
/* ! CONTAINER */
.container {
display: flex;
flex-flow: column wrap;
height: 100vh;
min-height: 100vh;
background-color: #ecf0f1;
}
/* ! HEADER/FOOTER */
header,
footer {
font-size: 50px;
color: white;
background-color: orange;
}
/* ! TOP NAV */
.top_navbar {
display: flex;
flex-flow: row nowrap;
/*flex: 0 0 auto;*/
position: sticky;
top: 0px;
align-items: center;
background-color: yellow;
}
.top_navbar a {
color: white;
}
#nt_left {
background-color: green;
flex-grow: 1;
}
#nt_center {
background-color: blue;
}
#nt_right {
background-color: indigo;
}
/* ! MAIN CONTENT */
.main_body {
display: flex;
flex-flow: row nowrap;
overflow: auto;
}
#ns_left {
flex: 0 0;
flex-basis: 300px;
top: 50px;
background-color: violet;
font-size: 18px;
}
#main {
flex: 1 0;
background-color: red;
font-size: 26px;
}
<header>THIS IS A HEADER</header>
<div class="container">
<div class="top_navbar" id="top_navbar">
<div class="nav_top" id="nt_left">
<span class="material-symbols-outlined"> sentiment_satisfied </span>
</div>
<div class="nav_top" id="nt_right">
TOP LINK 1
TOP LINK 2
TOP LINK 3
</div>
</div>
<div class="main_body">
<aside class="sidebar" id="ns_left">
<h3>sidebar</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item ...</li>
</ul>
</aside>
<article class="article" id="main">
<h3>article</h3>
<p>
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
</p>
</article>
</div>
</div>
<footer>THIS IS A FOOTER</footer>

My best attempt, move <aside> into .top_navbar and use position:absolute to make the illusion.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
:root {
--aside-width: 150px;
--top-navbar-height: 30px;
}
/* ! BODY / HTML */
html,
body {
background-color: red;
}
/* ! CONTAINER */
.container {
display: flex;
flex-flow: column nowrap;
_min-height: 100vh; /* this line should be remove to become a true responsive site, here just demo */
background-color: #ecf0f1;
}
/* ! HEADER/FOOTER */
header,
footer {
font-size: 50px;
color: white;
background-color: orange;
position: relative;
}
/* ! TOP NAV */
.top_navbar {
display: flex;
flex-flow: row nowrap;
position: sticky;
top: 0px;
align-items: center;
background-color: yellow;
height: var(--top-navbar-height);
}
.top_navbar a {
color: white;
}
#nt_left {
background-color: green;
flex-grow: 1;
}
#nt_center {
background-color: blue;
}
#nt_right {
background-color: indigo;
}
/* ! MAIN CONTENT */
.main_body {
padding-left: var(--aside-width);
}
#ns_left {
width: var(--aside-width);
background-color: violet;
font-size: 18px;
position: absolute;
top: 0;
margin-top: var(--top-navbar-height);
max-height: 100vh;
overflow: auto;
padding-bottom: calc(var(--top-navbar-height) + 70px);
}
.article1 {
background-color: red;
font-size: 26px;
}
.article2 {
background-color: blue;
font-size: 26px;
}
<header>THIS IS A HEADER</header>
<div class="container">
<div class="top_navbar" id="top_navbar">
<div class="nav_top" id="nt_left">
<span class="material-symbols-outlined"> sentiment_satisfied </span>
</div>
<div class="nav_top" id="nt_right">
TOP LINK 1
TOP LINK 2
TOP LINK 3
</div>
<aside class="sidebar" id="ns_left">
<h3>sidebar</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item last</li>
</ul>
</aside>
</div>
<div class="main_body">
<article class="article1" id="main1">
<h3>article</h3>
<p>
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
</p>
</article>
<article class="article2" id="main2">
<h3>article</h3>
<p>
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
</p>
</article>
</div>
</div>
<footer>THIS IS A FOOTER</footer>

Well, here's my crappy attempt:
* {
box-sizing: border-box;
}
:root {
--aside-width: 300px;
--aside-height: 250px;
}
html,
body,
.container {
height: 100%;
}
body {
margin: 0;
background-color: red;
}
header,
footer {
font-size: 50px;
color: white;
background-color: orange;
}
section {
position: relative;
}
nav {
display: grid;
grid-template-columns: var(--aside-width) 1fr;
grid-template-areas: 'nav-left nav-right' 'aside .';
position: sticky;
top: 0;
background-color: transparent;
}
nav a {
color: white;
}
aside {
grid-area: 'aside';
width: var(--aside-width);
height: var(--aside-height);
background-color: violet;
font-size: 18px;
}
main {
display: flex;
flex-flow: row nowrap;
}
.article-main {
padding: 1em;
padding-inline-start: calc(var(--aside-width) + 1em);
background-color: red;
font-size: 26px;
}
.nav-left {
grid-area: 'nav-left';
background-color: green;
}
.nav-right {
grid-area: 'nav-right';
background-color: indigo;
}
<header>THIS IS A HEADER</header>
<section>
<nav>
<div class="nav-left">
<span class="material-symbols-outlined"> sentiment_satisfied </span>
</div>
<div class="nav-right">
TOP LINK 1
TOP LINK 2
TOP LINK 3
</div>
<aside>
<h3>sidebar</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item ...</li>
</ul>
</aside>
</nav>
<main>
<article class="article-main">
<h3>article</h3>
<p>
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over
cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO
copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest. Williamsburg neutra tilde umami vice mustache master cleanse green juice kale
chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie, church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette
DIY mixtape. Gastropub leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO copper mug coloring book tattooed waistcoat. Dreamcatcher plaid literally
kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
</p>
</article>
</main>
</section>
<footer>THIS IS A FOOTER</footer>

I don't know how I did it, but I was able to get everything accomplished. I think a key factor is remembering that nested flexboxes do not account for the height of sibling(?) flexboxes. So when trying to give the sidebar (aside) a height of 100vh, it was doing just that, but but not accounting for the height of the header & top navbar. I solved that with a calc: height: calc(100vh - (var(--top-navbar-height) + var(--header-height)));
There were some other issues I was having, but managed to work through most of them. The only thing left is to adjust the height of the sidebar (aside) when scrolling up. Because the header disappears, it leaves a whitespace until the footer is displayed. I'm assuming I'll have to use JavaScript to solve that? If anyone has an answer for that, it'd be awesome!
Here is the complete code in case anyone wants a sample:
:root {
--header-height: 50px;
--footer-height: 50px;
--top-navbar-height: 30px;
--aside-width: 250px;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
/* ! BODY / HTML */
html,
body {
background-color: red;
}
/* ! PAGE CONTAINER */
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
background-color: #ecf0f1;
}
/* ! HEADER/FOOTER */
header,
footer {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
header {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
height: var(--header-height);
font-size: 50px;
color: white;
background-color: orange;
}
footer {
height: var(--footer-height);
font-size: 25px;
color: white;
background-color: orange;
left: 0;
bottom: 0;
margin-top: auto;
}
/* ! NAVBAR & MAIN FLEXBOX */
.main {
display: flex;
flex-direction: row;
flex: 1 1 auto;
}
.navbar {
display: flex;
flex-direction: row;
flex: 0 0 auto;
position: sticky;
top: 0;
align-items: center;
padding: 0 10px 0 10px;
height: var(--top-navbar-height);
font-size: 22px;
background-color: yellow;
}
/* ! NAVBAR STYLE */
#nt_left {
flex-grow: 1;
}
#nt_right a {
margin: 10px;
}
/* ! SIDENAV STYLE */
aside {
display: flex;
flex-direction: column;
flex: 0 0 auto;
top: var(--top-navbar-height);
width: var(--aside-width);
height: calc(100vh - (var(--top-navbar-height) + var(--header-height)));
position: sticky;
overflow-y: auto;
padding: 0 10px 0 10px;
background-color: green;
font-size: 18px;
}
/* ! ARTICLE STYLE */
article {
display: flex;
flex-direction: column;
flex: 1 1 auto;
padding: 0 10px 0 10px;
background-color: blue;
font-size: 18px;
}
<body>
<div class="container">
<header>THIS IS A HEADER</header>
<div class="navbar">
<div class="nav_top" id="nt_left">
<span class="material-symbols-outlined"> sentiment_satisfied </span>
</div>
<div class="nav_top" id="nt_right">
TOP LINK 1
TOP LINK 2
TOP LINK 3
</div>
</div>
<div class="main">
<aside>
<h3>sidebar</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item ...</li>
<li>Item last</li>
</ul>
</aside>
<article>
<h3>Hipster Ipsum</h3>
<p>
Williamsburg neutra tilde umami vice mustache master cleanse green juice kale chips godard subway tile lomo. Messenger bag single-origin coffee ascot poke lyft readymade fixie,
church-key gastropub meditation. Af gochujang la croix, readymade blog pour-over cronut paleo offal heirloom. Kale chips +1 polaroid truffaut raclette DIY mixtape. Gastropub
leggings meggings tbh hot chicken slow-carb YOLO mustache lyft VHS deep v fanny pack hell of. Echo park sustainable food truck jean shorts, prism XOXO copper mug coloring book
tattooed waistcoat. Dreamcatcher plaid literally kinfolk bodega boys vaporware before they sold out pop-up fashion axe fit hammock pinterest.
</p>
<br />
<p>
Pok pok deep v schlitz, kickstarter bushwick godard sustainable umami fit small batch. +1 master cleanse offal bushwick photo booth green juice. Copper mug thundercats
stumptown, prism 90's tonx letterpress cred irony. Bruh messenger bag same organic meggings bushwick bespoke ascot sus franzen schlitz mukbang vinyl aesthetic helvetica.
</p>
<br />
<p>
Bespoke ascot waistcoat blue bottle edison bulb praxis farm-to-table seitan, put a bird on it disrupt 90's four loko. You probably haven't heard of them af celiac bushwick.
Mustache butcher coloring book, woke fixie heirloom plaid tonx 90's swag kickstarter. Craft beer shabby chic celiac try-hard tattooed edison bulb vaporware snackwave iPhone
small batch pok pok next level thundercats. Selvage deep v godard, meh vice tumblr man bun church-key bodega boys synth cloud bread ascot. Godard taiyaki tilde brunch, cornhole
single-origin coffee hexagon DIY asymmetrical lumbersexual hot chicken pabst irony tousled.
</p>
<br />
<p>
Next level hot chicken meggings cold-pressed. Health goth bicycle rights unicorn coloring book before they sold out aesthetic Brooklyn bushwick yr kickstarter sriracha.
Literally ascot tattooed tote bag poutine PBR&B. Hashtag taxidermy ennui 8-bit direct trade truffaut, disrupt prism ascot.
</p>
<br />
<p>
Pickled unicorn messenger bag helvetica pitchfork gluten-free. Next level roof party craft beer whatever tattooed, humblebrag pour-over mukbang ascot raw denim bushwick
waistcoat cloud bread austin intelligentsia. Taxidermy small batch iceland gatekeep ethical paleo gluten-free tote bag authentic neutra vaporware tumblr man braid. Green juice
slow-carb kombucha brunch chillwave plaid. Adaptogen pinterest forage, humblebrag polaroid meh next level street art big mood pug authentic bushwick. Narwhal humblebrag
meditation try-hard 90's. Organic fanny pack fingerstache mukbang, keytar vegan deep v normcore.
</p>
<br />
<p>
Hexagon skateboard listicle trust fund, shabby chic kickstarter bodega boys forage four loko slow-carb photo booth. Enamel pin prism mustache glossier 8-bit. Gochujang trust
fund seitan, drinking vinegar distillery lumbersexual slow-carb sustainable. Umami fingerstache quinoa, organic Brooklyn humblebrag poke butcher tofu.
</p>
<br />
<p>
Praxis truffaut activated charcoal kickstarter neutra. Selvage hexagon organic bruh heirloom kombucha farm-to-table actually quinoa artisan. Neutra vibecession gastropub,
locavore gluten-free polaroid succulents subway tile taxidermy sartorial poutine viral. Skateboard iceland vegan, tote bag sartorial chartreuse thundercats. Chambray same
biodiesel poke artisan keytar schlitz. Jean shorts kickstarter mixtape jianbing cold-pressed, meditation organic ramps godard post-ironic fixie skateboard. Pickled next level
jean shorts celiac shabby chic freegan.
</p>
<br />
<p>
Live-edge XOXO seitan, schlitz bushwick cornhole glossier iPhone bruh waistcoat. Fit hot chicken quinoa bodega boys semiotics, glossier farm-to-table ennui. Cardigan
letterpress coloring book schlitz viral kinfolk asymmetrical occupy succulents heirloom poutine squid flannel actually. 3 wolf moon snackwave knausgaard banjo 90's deep v you
probably haven't heard of them.
</p>
<br />
<p>
Flannel twee mukbang, church-key four dollar toast pour-over cardigan schlitz art party 8-bit wolf JOMO. Listicle shoreditch typewriter, ennui jianbing kombucha copper mug
lo-fi. Kale chips +1 pitchfork beard YOLO yes plz locavore shabby chic yuccie vexillologist leggings hot chicken lomo PBR&B wolf. Farm-to-table shabby chic four loko venmo
tumeric everyday carry bushwick leggings ugh chillwave bodega boys tilde readymade vape.
</p>
<br />
<p>
Prism cray street art, bushwick gochujang pickled mumblecore williamsburg plaid biodiesel polaroid next level gastropub lo-fi. Glossier pickled snackwave disrupt. Kogi celiac
lomo banh mi chartreuse banjo. Tofu lumbersexual craft beer sustainable, butcher woke knausgaard kogi.
</p>
</article>
</div>
<footer>THIS IS A FOOTER</footer>
</div>
</body>

Related

How is space divided amongst flex items when flex-basis and flex-grow both are set?

I am going through a basic flexbox tutorial from MDN and cant get my head around on how is the remaining space divided amongst the flex item, when flex-basis is set.
In the live demo, I set the following code:
article {
flex: 1 200px;
}
article:nth-of-type(3) {
flex: 2 200px;
}
My browser screen is 1369px, after taking the scrollbar out I am left with 1349px. MDN says that
"Each flex item will first be given 200px of the available space. After that, the rest of the available space will be shared out according to the proportion units."
So the available space after min 200px is given to each article should be 1349px - 3*200px = 749px. Now, the article three should get half of the available space plus 200px, that is 200 + 749/2 = 575.5. Taking 10px margin space out from both sides we get 555.5px, but in my laptop it occupies 535.5px.
Below is the working demo:
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
body {
margin: 0;
}
header {
background: purple;
height: 100px;
}
h1 {
text-align: center;
color: white;
line-height: 100px;
margin: 0;
}
article {
padding: 10px;
margin: 10px;
background: aqua;
flex: 1 200px;
}
/* Add your flexbox CSS below here */
section {
display: flex;
}
article:nth-of-type(3) {
flex: 2 200px;
}
<header>
<h1>Sample flexbox example</h1>
</header>
<section>
<article>
<h2>First article</h2>
<p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>
</article>
<article>
<h2>Second article</h2>
<p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>
</article>
<article>
<h2>Third article</h2>
<p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>
<p>Cray food truck brunch, XOXO +1 keffiyeh pickled chambray waistcoat ennui. Organic small batch paleo 8-bit. Intelligentsia umami wayfarers pickled, asymmetrical kombucha letterpress kitsch leggings cold-pressed squid chartreuse put a bird on it. Listicle pickled man bun cornhole heirloom art party.</p>
</article>
</section>
Please explain how is space divided amongst flex items when flex-basis and flex-grow both are set?
If I do article:nth-of-type(3) { flex: 2; } it doesn't give double space to article 3, why?
Margin should be considered initially and removed from the total width in order to calculate the free space. Not later, like you are doing.
So all your elements start with 200px width and 20px margin. The free sapce will be 1350px - 3*200px - 3*20x = 690px. Now, the article three should have a width equal to 2/4*690px + 200px = 545px (and not 555px)
without box-sizing you will have 1350px - 3*220px - 3*20x = 630px and the width will be 535px

Sticky navigation breaks when encounters floated content?

For instructional purposes, I'm working with the most basic of CSS. I have a navigation bar set to position: sticky which works great UNTIL it interacts with a set of floated columns further down the page.
gif of site scrolling and breaking nav
I'm unsure if it's because of the float, or some poor calculation regarding the simplicity of my layout. Right now, the 2-column layout is made with:
#main-menu {
width: 100%;
height: auto;
text-align: right;
position: sticky;
position: -webkit-sticky;
top: 0px;
z-index: 2;
}
.column {
width: 50%;
float: left;
}
Using an inline-block display works and does not affect the sticky menu, but as expected I can not set them to 50% width. A fix would be great, but also an explanation on why I'm experiencing this.
Thank you!
#main-menu {
width: 100%;
height: auto;
background-color: #222222;
line-height: 2em;
text-align: right;
position: sticky;
position: -webkit-sticky; /* Safari */
top: 0px;
z-index: 2;
}
.site-name {
float: left;
margin: auto 1em;
padding: 0.5em 1em;
}
#main-menu a {
color: #FFFFFF;
text-decoration: none;
}
#main-menu .site-name a:hover {
color: #00BBBB;
}
.menu-item {
min-width: 2em;
text-align: center;
display: inline-block;
padding: 0.5em 1em;
}
.menu-item:hover {
background-color: #00BBBB;
}
#main {
padding: 2em 4em;
clear: both;
}
.column-lg {
width: 50%;
float: left;
}
<h1>Site Above Fold Content</h1>
<nav id="main-menu">
<div class="site-name">
Title
</div>
<div class="menu-item">
L1
</div>
<div class="menu-item">
L2
</div>
</nav>
<h2>Under Fold Content (Before Floated Columns)</h2>
<p>Gentrify woke irony +1 tote bag lo-fi drinking vinegar. Bushwick YOLO retro pinterest cloud bread skateboard. Small batch retro twee scenester roof party humblebrag celiac 8-bit direct trade franzen flannel cray. Kogi knausgaard godard selfies umami deep v, woke whatever 8-bit prism cred.</p>
<br><br>
<h3>BYE-BYE NAV!!</h3>
<div class="column-lg">
<h2>Lorem Ipusm</h2>
<div class="row">
<h3>1 Title Impsum Amet</h3>
<p>Lorem ipsum dolor amet bitters ethical microdosing, narwhal jean shorts venmo umami YOLO 90's trust fund activated charcoal lomo pok pok hammock. Man bun marfa blog narwhal letterpress food truck. Umami forage disrupt, snackwave DIY mlkshk aesthetic kogi bitters vice.</p>
</div>
<div class="row">
<h3>2 Title Impsum Amet</h3>
<p>2 Vegan williamsburg jianbing, gluten-free tote bag try-hard mixtape yuccie +1 everyday carry shabby chic umami vexillologist pop-up edison bulb. Whatever everyday carry listicle, coloring book hell of microdosing gastropub banh mi yuccie tumblr art party. Aesthetic hammock kitsch microdosing, viral biodiesel tumblr cliche beard readymade seitan. Copper mug chambray street art raclette shaman fam neutra.</p>
</div>
</div>
<div class="column-lg">
<h2>Lorem Ipusm</h2>
<div class="row">
<p>Gentrify woke irony +1 tote bag lo-fi drinking vinegar. Bushwick YOLO retro pinterest cloud bread skateboard. Small batch retro twee scenester roof party humblebrag celiac 8-bit direct trade franzen flannel cray. Kogi knausgaard godard selfies umami deep v, woke whatever 8-bit prism cred. Intelligentsia heirloom keytar, hot chicken synth tote bag vaporware williamsburg pok pok kickstarter 3 wolf moon selvage hoodie trust fund cronut. Occupy bicycle rights drinking vinegar small batch, vaporware taxidermy flannel live-edge marfa.</p>
</div>
</div>
The floated elements are no longer in the normal flow of the DOM, reducing the overall height of the body. Using inspector, you can see this (blue representing the height of the body):
Thus, as you encounter the floats, your position: sticky which is relative to the body, will appear to scroll.
A "fix" is to clear your floats. I applied the following clearfix to the body:
body:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
Here's the snippet with demo:
body:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
#main-menu {
width: 100%;
height: auto;
background-color: #222222;
line-height: 2em;
text-align: right;
position: sticky;
position: -webkit-sticky; /* Safari */
top: 0px;
z-index: 2;
}
.site-name {
float: left;
margin: auto 1em;
padding: 0.5em 1em;
}
#main-menu a {
color: #FFFFFF;
text-decoration: none;
}
#main-menu .site-name a:hover {
color: #00BBBB;
}
.menu-item {
min-width: 2em;
text-align: center;
display: inline-block;
padding: 0.5em 1em;
}
.menu-item:hover {
background-color: #00BBBB;
}
#main {
padding: 2em 4em;
clear: both;
}
.column-lg {
width: 50%;
float: left;
}
<h1>Site Above Fold Content</h1>
<nav id="main-menu">
<div class="site-name">
Title
</div>
<div class="menu-item">
L1
</div>
<div class="menu-item">
L2
</div>
</nav>
<h2>Under Fold Content (Before Floated Columns)</h2>
<p>Gentrify woke irony +1 tote bag lo-fi drinking vinegar. Bushwick YOLO retro pinterest cloud bread skateboard. Small batch retro twee scenester roof party humblebrag celiac 8-bit direct trade franzen flannel cray. Kogi knausgaard godard selfies umami deep v, woke whatever 8-bit prism cred.</p>
<br><br>
<h3>BYE-BYE NAV!!</h3>
<div class="column-lg">
<h2>Lorem Ipusm</h2>
<div class="row">
<h3>1 Title Impsum Amet</h3>
<p>Lorem ipsum dolor amet bitters ethical microdosing, narwhal jean shorts venmo umami YOLO 90's trust fund activated charcoal lomo pok pok hammock. Man bun marfa blog narwhal letterpress food truck. Umami forage disrupt, snackwave DIY mlkshk aesthetic kogi bitters vice.</p>
</div>
<div class="row">
<h3>2 Title Impsum Amet</h3>
<p>2 Vegan williamsburg jianbing, gluten-free tote bag try-hard mixtape yuccie +1 everyday carry shabby chic umami vexillologist pop-up edison bulb. Whatever everyday carry listicle, coloring book hell of microdosing gastropub banh mi yuccie tumblr art party. Aesthetic hammock kitsch microdosing, viral biodiesel tumblr cliche beard readymade seitan. Copper mug chambray street art raclette shaman fam neutra.</p>
</div>
</div>
<div class="column-lg">
<h2>Lorem Ipusm</h2>
<div class="row">
<p>Gentrify woke irony +1 tote bag lo-fi drinking vinegar. Bushwick YOLO retro pinterest cloud bread skateboard. Small batch retro twee scenester roof party humblebrag celiac 8-bit direct trade franzen flannel cray. Kogi knausgaard godard selfies umami deep v, woke whatever 8-bit prism cred. Intelligentsia heirloom keytar, hot chicken synth tote bag vaporware williamsburg pok pok kickstarter 3 wolf moon selvage hoodie trust fund cronut. Occupy bicycle rights drinking vinegar small batch, vaporware taxidermy flannel live-edge marfa.</p>
</div>
</div>

filling/sizing empty div in bootstrap

Hi I´m working on this bootstrap grid below.
I want this first column col-1 to have the same height as the two columns at its right side.
max-heightdoesn't seems to do the trick and I've been using:
.col-1{
background-color: #555;
margin-bottom: -600px;
padding-bottom: 600px;
}
to get the look I want, but then part of the div ends behind the other div´s when the site is scaled down.
Can anyone advise me how I can get the result I want?
I somehow believe that there must be another way to do this than I'm using which is to adjust the margin-bottomand padding-bottom
A link to fiddle
/* GRID */
.col-1 {
background-color: #555;
margin-bottom: -600px;
padding-bottom: 600px;
}
.col-2 {
background-color: #558C89;
}
.col-3 {
background-color: #74AFAD;
}
.col-4 {
background-color: #D9853B;
}
.col-5 {
background-color: #ECECEA;
}
.col-6 {
background-color: #F3FAB6;
}
.col-7 {
background-color: #CBE32D;
}
.col-8 {
background-color: #A8CD1B;
}
.col-9 {
background-color: #005A31;
}
/****************************/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-6 col-1">
Some text here
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6 col-2">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies
salvia ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-6 col-3">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies
salvia ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-6 col-4">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies
salvia ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-6 col-5">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies
salvia ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-6">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-7">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-8">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-9">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
</div>
</div>
Actually nowadays with current CSS we have, this below happens to be a ugly hack.
.col-1{
background-color: #555;
margin-bottom: -600px;
padding-bottom: 600px;
}
So, use flexbox:
body,
p {
margin: 0 !important
}
body {
padding-top: 70px;
}
/* NAVBAR */
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
}
.navbar-nav>li {
float: none;
}
.navbar-collapse.collapse.in {
display: block !important;
}
/****************************/
/* GRID */
span.glyphicon {
display: block;
text-align: center;
font-size: 5em;
padding-top: 15%;
}
.container > .row {
display: flex;
flex-wrap: wrap
}
#media (max-width: 992px) {
.container > .row > [class^="col-"] {
flex: 0 0 100%;
}
}
.col-1 {
background-color: #555;
border: solid 5px #fff;
}
.col-2 {
background-color: #558c89;
border: 5px solid #fff;
min-height: 250px;
}
.col-3 {
background-color: #74AFAD;
min-height: 250px;
padding: 5px;
border: solid 5px #fff;
}
.col-4 {
background-color: #D9853B;
min-height: 250px;
padding: 5px;
border: solid 5px #fff;
}
.col-5 {
background-color: #ECECEA;
min-height: 250px;
padding: 5px;
border: solid 5px #fff;
}
.col-6 {
background-color: #F3FAB6;
min-height: 250px;
border: solid 5px #fff;
}
.col-7 {
background-color: #CBE32D;
min-height: 250px;
border: solid 5px #fff;
}
.col-8 {
background-color: #A8CD1B;
min-height: 250px;
border: solid 5px #fff;
}
.col-9 {
background-color: #005A31;
min-height: 250px;
border: solid 5px #fff;
}
/****************************/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-6 col-1 row-eq-height">
Daði Hall
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6 col-2 text-center">
<p>Web design</p>
<span class="glyphicon glyphicon-console" aria-hidden="true"></span>
</div>
<div class="col-md-6 col-3">
<p>Blog</p>
<span class="glyphicon glyphicon-text-size" aria-hidden="true"></span>
</div>
<div class="col-md-6 col-4">
<p>CV</p>
<span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span>
</div>
<div class="col-md-6 col-5">
<p>Photos</p>
<span class="glyphicon glyphicon-camera" aria-hidden="true"></span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-6">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-7">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-8">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
<div class="col-md-3 col-9">
<p>Celiac 3 wolf moon williamsburg pitchfork, squid helvetica single-origin coffee brooklyn paleo vice biodiesel. Fingerstache celiac mumblecore, try-hard yuccie helvetica chartreuse. Chartreuse wayfarers vegan, blue bottle bicycle rights selfies salvia
ugh drinking vinegar 3 wolf moon you probably haven't heard of them. Cardigan fingerstache freegan 3 wolf moon vegan. Venmo umami 8-bit, cronut raw denim direct trade locavore vinyl seitan plaid tousled.</p>
</div>
</div>
</div>
.col-1 {
background-color: #555;
}
#media(min-width: 992px) {
.col-1 {
margin-bottom: -600px;
padding-bottom: 600px;
}
}
JSFIDDLE

Vertically position three elements: flexible box, scroll box & fixed box

Is the following even possible with css? If not, what javascript events would be used even if the green box changes content?
I'd like to vertically position three boxes:
The first one (the green one) can have some variable amount of content, and the box should expand to fit the content. This box should be flush with the top of the browser.
The last one, the yellow one, will have a fixed amount of content (meaning I know what the content is at 'compile time'). This box should be flush with the bottom of the browser.
The middle one, the red one, will have a flexible amount of content, and should extend from the bottom of the green box to the top of the yellow box, and internally it needs to be scrollable if its content is larger than the box size.
This is what I've got so far, and it doesn't quite work - I can't seem to make the bottom of the yellow box flush with the bottom of the viewport in such a way as to let the red box take up all the extra space (i.e. position: absolute doesn't seem to help).
#container {
float: left;
height: 100%;
background-color:gray;
}
#header {
background-color: green;
}
#main {
overflow: auto;
background-color: red;
height: 70%;
}
#footer {
background-color:yellow;
}
<div id="container">
<div id="header">START OF HEADER CONTENT...</div>
<div id="main">Craft beer jean shorts...</div>
<div id="footer">footer some stuff goes here</div>
</div>
And this is what it looks like:
Here's a jsfiddle: https://jsfiddle.net/n6cmdcj3/, but note it might not help, as the html box doesn't obey the viewport size - not sure how to make it so
This can be done fairly easily with flexbox. Check out the support tables for compatibility.
html,
body {
width: 100%;
height: 100%;
}
#container {
float: left;
height: 100%;
background-color: purple;
position: relative;
display: flex;
flex-direction: column;
}
#header {
background-color: green;
}
#main {
overflow: hidden;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
background-color: red;
flex: 1;
flex-grow: 1;
}
#footer {
background-color:yellow;
}
<body>
<div id="container">
<div id="header">
START OF HEADER CONTENT and the viewer should be able to see all of it. Ipsum Blaster jango fett alderaan data dooku validium hypercube. Antilles mace windu uhura xindi millenium falcon bothan exterminate tylium ore. Endor maul skywalker everlasting matches antilles FTL tylium ore dooku. Paradox machine padawan speeder doctor who chewbacca AT-AT frack dagobah ice gun. Uhura data photon torpedo worf landspeeder starbuck hypercube cantina. END OF HEADER CONTENT
</div>
<div id="main">
Craft beer jean shorts beard green juice, kinfolk 8-bit hoodie single-origin coffee letterpress seitan four dollar toast hammock occupy selfies pug. Retro locavore meditation craft beer viral, vinyl health goth cred butcher echo park. Echo park portland helvetica roof party hammock, food truck messenger bag pop-up poutine master cleanse hella artisan etsy. Celiac polaroid before they sold out tousled chillwave farm-to-table, leggings craft beer mlkshk viral seitan vegan intelligentsia. Yuccie synth poutine next level food truck, meggings chambray aesthetic farm-to-table marfa helvetica dreamcatcher blue bottle mumblecore brunch. Fixie narwhal lomo, art party pinterest direct trade poutine mlkshk organic forage irony. Wolf kickstarter authentic dreamcatcher plaid.
Yuccie tilde try-hard selfies gentrify DIY. Offal celiac gentrify cornhole, chia beard scenester quinoa freegan marfa thundercats pour-over synth. Migas salvia franzen pabst, blog listicle freegan chia YOLO fashion axe locavore offal. Paleo whatever messenger bag, 3 wolf moon normcore aesthetic humblebrag pug narwhal lo-fi lomo lumbersexual. Chambray yuccie selfies, tattooed biodiesel pitchfork artisan mixtape actually iPhone single-origin coffee 8-bit master cleanse aesthetic. Kickstarter chillwave VHS tousled green juice. Meggings mumblecore gentrify chambray blue bottle brooklyn.
Four dollar toast sriracha hammock iPhone authentic, quinoa wayfarers pop-up taxidermy post-ironic next level offal YOLO chartreuse fingerstache. Forage salvia direct trade photo booth YOLO, fixie paleo sartorial deep v. Distillery art party pop-up meggings sartorial thundercats vice, portland jean shorts flannel readymade godard. 3 wolf moon single-origin coffee you probably haven't heard of them chillwave selfies cred. Scenester asymmetrical seitan blue bottle bitters banh mi swag, etsy disrupt 90's. Kombucha normcore echo park, photo booth bushwick stumptown retro before they sold out. Chillwave art party heirloom ugh.
Cliche authentic paleo fingerstache banjo actually artisan sriracha helvetica twee, trust fund portland PBR&B. Aesthetic pork belly pop-up bitters distillery, banh mi try-hard cred meditation letterpress schlitz 90's celiac neutra. Irony street art actually cliche cray asymmetrical. Bicycle rights kombucha beard crucifix, deep v cray 3 wolf moon listicle before they sold out shabby chic distillery pitchfork. Meh aesthetic tacos flannel, pug paleo DIY austin. Gastropub kinfolk cliche crucifix, swag post-ironic irony heirloom keytar thundercats 8-bit beard. You probably haven't heard of them migas marfa leggings normcore.
Four loko gentrify ramps, mixtape sartorial fashion axe ethical organic meditation williamsburg. Blue bottle freegan synth hoodie, swag bitters letterpress chillwave pop-up. Hella chicharrones next level ramps chillwave, portland freegan tattooed neutra disrupt austin 3 wolf moon kale chips roof party. Lumbersexual try-hard cold-pressed, affogato offal bushwick thundercats stumptown. Leggings knausgaard gastropub, raw denim bitters lo-fi four dollar toast tilde truffaut meh. Truffaut umami artisan, irony affogato tattooed literally yuccie pabst chia wolf hammock craft beer photo booth. Lomo roof party tumblr thundercats meggings ennui messenger bag, next level franzen synth kickstarter pork belly vegan.
</div>
<div id="footer">
footer some stuff goes here
</div>
</div>
</body>
#container {
float: left;
height: 100%;
background-color:gray;
position: relative;
}
#header {
background-color: green;
height: auto;
}
#main {
overflow: auto;
background-color: red;
height: 70%;
overflow-y: scroll
-webkit-overflow-y: scroll;
-moz-overflow-y: scroll;
}
#footer {
background-color:yellow;
height: 25px;
}
I would do it this way. No reason to get too complicated.
Link: https://jsfiddle.net/n6cmdcj3/3/
I would also utilize set pixels for the main id, since you are trying to establish a scrolling content div.
Correct me if I'm wrong but, I also believe these should be classes not id. Classes are for reusable names, for example, you would utilize a class to update all the color of the divs but you would not utilize an id. An ID would be used in the cases of you needing something specific that will not be implemented anywhere else on the site. It's just good programming practice and it pays out later on when you are using JavaScript.
ID = Single Change Element
Class = Reusable multiple Elements.
Josh Rutherford's answer is great for flexbox. If you want to use a more traditional layout, you will have to set the top element to a fixed height and use vh units. The CSS will look like this:
.container {
height: 100vh;
}
.top {
background-color: #f2f2f2;
height: 24vh;
overflow: hidden;
padding: 20px;
}
.middle {
background-color: #h2h2h2;
height: 55vh;
padding: 20px;
overflow-y: scroll;
}
.bottom {
background-color: #d2d2d2;
height: 3vh;
padding: 20px;
position: fixed;
bottom: 0;
width: 100%;
}
Demo on CodePen: http://codepen.io/staypuftman/pen/eJvdYv

Why isn't this image adjusting to the width size, if it is inside the container that I am specifying to width size?

I am attempting to adjust all width sizes of inside the container. So all sides will be 80%. Why isn't the image adjusting as well? I'm expecting the image to not be so spread out to the right as it is now. I am expecting it to be aligned with everything else.
Here is the main HTML and CSS code attempting to do the above:
.container {
width: 80%;
margin: 0 auto;
}
<div class="container">
<div class="header">
<h1>About me </h1>
</div>
<div class="image">
<img src="http://lorempixel.com/1400/300" />
</div>
<div class="intro column">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
<div class="skills column">
<ul id="skill-list">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
<div class="main_text">
<p>
Small batch wolf pug bicycle rights, letterpress kitsch Etsy listicle farm-to-table. Hoodie flannel Pitchfork normcore chambray, polaroid viral before they sold out. Wes Anderson skateboard single-origin coffee fixie shabby chic pour-over, four loko typewriter. Banksy American Apparel sartorial, irony XOXO plaid narwhal cred mumblecore keffiyeh asymmetrical sriracha. Marfa PBR lomo four loko aesthetic master cleanse, Pitchfork church-key bitters sartorial beard keffiyeh Thundercats. Mixtape aesthetic mustache readymade Blue Bottle, Banksy Wes Anderson Intelligentsia Kickstarter cliche biodiesel normcore farm-to-table polaroid narwhal. Semiotics mixtape Portland kale chips, heirloom Carles seitan pickled 3 wolf moon church-key master cleanse fingerstache.
</p>
<p>
Tofu pork belly pug Tumblr crucifix. XOXO 3 wolf moon whatever, narwhal Vice Blue Bottle distillery PBR&B lumbersexual forage tattooed leggings 90's letterpress. Brooklyn pork belly umami hashtag gentrify tilde. Blog pork belly Godard mlkshk. Kitsch letterpress kale chips narwhal messenger bag. Migas farm-to-table banjo hella. Taxidermy lo-fi mlkshk normcore paleo DIY, tofu VHS lumbersexual ugh listicle.
</p>
</div>
</div> <!-- end container -->
Images with no style on them automatically default to their true size (ex. a 1400px by 300px image will be 1400px by 300px on the screen), as #MrLister said in his comment. You could do something like this:
img {
width: 100%;
}
to set the image width to 100% of its parent's width.
Width property isn't inherited. so the width of the container is 80% of its parent (the body element). but the width of the image is its true size.
To change its width add a css style.
img{
width: 100%;
}
this changes its width to 100% of its parent (the container).
*performance note: It's better to change the size of the picture itself rather than use the width property because you download the whole picture then resize it which means useless data download.