Flex parent doesn't expand to height of child - css

This might be a bit of an amateur question as I'm just getting started with using Flexbox, but I'm having trouble creating the following layout.
https://jsfiddle.net/wp6hsnjo/
I'm aiming to have two rows (Main on top and Footer on the bottom) then 3 columns within Main, the first and last being fixed with the center column filling the remaining space. The difficulty I'm having is that the Main container won't inherit the height of the child elements.. which leaves the sticky footer in limbo. Is there a way that I can get the Main div to expand to match the height of the child elements? I've tried playing around with overflow and height settings but to no success.
html, body {
height: 100%;
}
body {
margin:0;
padding:0;
background-color: #f4f3f0;
box-sizing: border-box;
font-family: arimo, sans-serif;
color: #555760;
}
#container {
max-width:1560px;
margin: 0 auto;
display: flex;
flex-flow: wrap;
min-height: 100vh;
flex-direction: column;
}
#main {
display: flex;
flex: 1 0 auto;
height:auto;
}
header {
padding:30px;
flex: 0 0 100px;
order: 1;
}
#logo-container {
}
.logo {
width:75px;
margin-top:5px;
position:fixed;
}
nav {
width:100px;
text-align: right;
flex: 0 0 100px;
order: 3;
padding:30px;
}
nav ul {
list-style-type: none;
width:100px;
margin: 0;
padding: 0;}
.main-nav {
position:fixed;
text-transform: uppercase;
font-size: 12px;
font-weight: 700;
color: #222;
letter-spacing: 0.3px;
}
.main-nav li {
margin-bottom:7px;
}
.social-media {
position: fixed;
bottom:0;
margin-bottom:40px;
text-align: right;
width: 100px;
}
.social-media-icons {
width:16px;
height:16px;
margin-bottom:18px;
}
#page-content {
margin:30px 0 60px 0;
flex: 1;
order: 2;
}
.portfolio {
display: flex;
flex-wrap: wrap;
padding-bottom:300px;
}
.square {
position: relative;
flex-basis: calc(33.333% - 10px);
margin: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.span2 {
position: relative;
flex-basis: calc(66.666% - 10px);
margin: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.square::before {
content: '';
display: block;
padding-top: 100%;
}
.square .content {
position: absolute;
top: 0; left: 0;
height: 100%;
width: 100%;
}
footer {
order: 2;
margin: 0 0 58px 30px;
flex-shrink: 0;
font-size: 12px;
}
.hidden {
opacity: 0;
}
#keyframes fade-in {
from {opacity: 0;}
to {opacity: 1;}
}
.fade-in-element {
animation: fade-in 1.4s;
}
<div id="container"> <!-- CONTAINER -->
<div id="main">
<header> <!-- HEADER -->
<div id="logo-container">
<img src="images/icons/logo-black.png" alt="Logo" class="logo">
</div>
</header> <!-- HEADER END -->
<nav>
<ul class="main-nav">
<li>Home</li>
<li>Archive</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="social-media">
</ul>
</nav>
<section id="page-content"> <!-- PAGE CONTENT -->
<div class="portfolio">
<div class="span2">
<div class="content">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="span2">
<div class="content">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
</div>
</section> <!-- PAGE CONTENT END -->
</div><!-- MAIN END -->
<footer class="hidden" > <!-- FOOTER -->
<div id="copyright">© 2020 this is the footer</div>
</footer> <!-- FOOTER END -->
</div> <!-- CONTAINER END -->

Removing flex-flow: wrap from your #container element does the trick, and removing the 300px bottom padding from the .portfolio element to prevent a bunch of extra space.
var animateHTML = function() {
var elems;
var windowHeight;
function init() {
elems = document.querySelectorAll('.hidden');
windowHeight = window.innerHeight;
addEventHandlers();
checkPosition();
}
function addEventHandlers() {
window.addEventListener('scroll', checkPosition);
window.addEventListener('resize', init);
}
function checkPosition() {
for (var i = 0; i < elems.length; i++) {
var positionFromTop = elems[i].getBoundingClientRect().top;
if (positionFromTop - windowHeight <= 0) {
elems[i].className = elems[i].className.replace(
'hidden',
'fade-in-element'
);
}
if ((positionFromTop - windowHeight > 1) || (positionFromTop < 0)) {
elems[i].className = elems[i].className.replace(
'fade-in-element',
'hidden'
);
}
}
}
return {
init: init
};
};
html, body {
height: 100%;
}
body {
margin:0;
padding:0;
background-color: #f4f3f0;
box-sizing: border-box;
font-family: arimo, sans-serif;
color: #555760;
}
#container {
max-width:1560px;
margin: 0 auto;
display: flex;
min-height: 100vh;
flex-direction: column;
}
#main {
display: flex;
flex: 1 0 auto;
}
header {
padding:30px;
flex: 0 0 100px;
order: 1;
}
#logo-container {
}
.logo {
width:75px;
margin-top:5px;
position:fixed;
}
nav {
width:100px;
text-align: right;
flex: 0 0 100px;
order: 3;
padding:30px;
}
nav ul {
list-style-type: none;
width:100px;
margin: 0;
padding: 0;}
.main-nav {
position:fixed;
text-transform: uppercase;
font-size: 12px;
font-weight: 700;
color: #222;
letter-spacing: 0.3px;
}
.main-nav li {
margin-bottom:7px;
}
.social-media {
position: fixed;
bottom:0;
margin-bottom:40px;
text-align: right;
width: 100px;
}
.social-media-icons {
width:16px;
height:16px;
margin-bottom:18px;
}
#page-content {
margin:30px 0 60px 0;
flex: 1;
order: 2;
}
.portfolio {
display: flex;
flex-wrap: wrap;
}
.square {
position: relative;
flex-basis: calc(33.333% - 10px);
margin: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.span2 {
position: relative;
flex-basis: calc(66.666% - 10px);
margin: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.square::before {
content: '';
display: block;
padding-top: 100%;
}
.square .content {
position: absolute;
top: 0; left: 0;
height: 100%;
width: 100%;
}
footer {
order: 2;
margin: 0 0 58px 30px;
flex-shrink: 0;
font-size: 12px;
}
.hidden {
opacity: 0;
}
#keyframes fade-in {
from {opacity: 0;}
to {opacity: 1;}
}
.fade-in-element {
animation: fade-in 1.4s;
}
<body onload="animateHTML().init();">
<div id="container"> <!-- CONTAINER -->
<div id="main">
<header> <!-- HEADER -->
<div id="logo-container">
<img src="images/icons/logo-black.png" alt="Logo" class="logo">
</div>
</header> <!-- HEADER END -->
<nav>
<ul class="main-nav">
<li>Home</li>
<li>Archive</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="social-media">
</ul>
</nav>
<section id="page-content"> <!-- PAGE CONTENT -->
<div class="portfolio">
<div class="span2">
<div class="content">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="span2">
<div class="content">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
<div class="square">
<div class="content spread">
</div>
</div>
<div class="square">
<div class="content column">
</div>
</div>
</div>
</section> <!-- PAGE CONTENT END -->
</div><!-- MAIN END -->
<footer class="hidden" > <!-- FOOTER -->
<div id="copyright">© 2020 this is the footer</div>
</footer> <!-- FOOTER END -->
</div> <!-- CONTAINER END -->
</body>

Related

FlexBox: How can i keep boxes fixed one below the other

I'm trying to create a page using FlexBox so i can keep the main image always centered with the top logo and page. And add of "off-center" text, next to the left.
My problem now is that i cannot make each box (image+text) keep their place vertically, boxes float and they have different space between each other based on what i'm using to view (big screen, laptop).
Not an expert with FlexBox, can i do that?
And also, i want to add a bar after the third box, 100% width...but it's placing in the middle of the page, between the boxes.
Any help will be welcome and i'll keep learning :)
body {
margin: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
height: 100vh;
}
.top {
border: 1px solid white;
width: 50%;
height: 10%;
align-self: flex-start;
text-align: center;
}
.inner-container {
border: 1px solid white;
width: 50%;
height: 60%;
display: flex;
}
.center {
position: absolute;
width: 50%;
text-align: left;
align-self: flex-end;
}
.off-center {
position: absolute;
vertical-align: bottom;
text-transform: uppercase;
padding-left: 10px;
min-width: 200px;
align-self: flex-end;
}
.center, .off-center {
position: absolute;
}
.center img {width: 100%;}
.off-center h2 {font-size:12px; font-family: 'Open Sans', sans-serif; font-weight: 400;text-transform: uppercase; color:black; display: block!important;margin: 0px;}
.off-center p {font-size: 20px; font-family:'aileronbold', sans-serif; display: block!important;margin: 0px;text-transform: none;}
.row.subscriptionBar {display:flex; background-color: black; display: block; padding:20px;}
.subscriptionBar h2 {color:white;}
.firstPart {display: }
#media screen and (min-width: 769px) {
.off-center {
margin-left: 50%;
}
#media screen and (max-width: 768px) {
.off-center {
margin-top: 105px;
}
}
<div class="container">
<div class="top"><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 1</h2>
<p>509476ZclHtqXy</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 2</h2>
<p>Title lala 1</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 3 444</h2>
<p>Title 093830</p></div>
</div>
</div>
.wrapper {
display: flex;
flex-flow: row wrap;
font-weight: bold;
text-align: center;
}
.wrapper > * {
padding: 10px;
flex: 1 100%;
}
header{
background: tomato;
}
section{
display: flex
}
.main {
background: deepskyblue;
}
.main img{
max-width: 100%;
}
.full-width {
background: lightgreen;
}
.main { order: 2; flex: 3 0px; }
.aside { flex: 1 auto; }
.aside-1 { order: 1; background: gold; width: 10%}
.aside-2 { order: 3; background: hotpink; position: relative; width: 10%}
.aside-2 > span {
position: absolute;
bottom: 0;
left: 0;
}
.vertical {
width: 15%; /* Modify this value for different screen size*/
}
/* .full-width { order: 4; } */
/*#media all and (min-width: 600px) {
.aside { flex: 1 auto; }
}
#media all and (min-width: 800px) {
.main { flex: 3 0px; }
.aside-1 { order: 1; }
.main { order: 2; }
.aside-2 { order: 3; }
.footer { order: 4; }
}*/
body {
padding: 2em;
}
<div class="wrapper">
<header><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></header>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
<section>
<div class="main">
<img src="https://picsum.photos/200/300" alt="">
</div>
<aside class="aside aside-1 vertical"></aside>
<aside class="aside aside-2 vertical"><span>Aside Right</span></aside>
</section>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
<section class="full-width">Full Width</section>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
</div>
I'm just doing a quick sample because it's not clear on what you're looking for. If this is the direction you're hoping to move toward, then I may be able to assist further.
You just have a few too many things going on with your combination of flexbox and absolute positioning. Below is a version of your snippet with much of the unnecessary css commented out (so you can see exactly what it is) plus a couple of new additions.
Most important changes other than removing some of the absolute positioning are removing flex-wrap from your .container and adding flex-direction: column as well as matching the widths of .center and .off-center so you can use position: absolute on .off-center (good use of it in that case) along with margin-left equivalent to the width to ensure that it is positioned just to the right of your image container.
body {
margin: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
/*justify-content: center;
flex-wrap: wrap;
height: 100vh;*/
}
.top {
border: 1px solid white;
/*width: 50%;*/
height: 10%;
/*align-self: flex-start;*/
text-align: center;
}
.inner-container {
border: 1px solid white;
/*width: 50%;*/
height: 60%;
display: flex;
justify-content: space-around;
}
.center {
/*position: absolute;*/
width: 50%;
min-width: 200px;
text-align: left;
/*align-self: flex-end;*/
}
.off-center {
position: absolute;
/*vertical-align: bottom;*/
text-transform: uppercase;
padding-left: 10px;
width: 50%;
min-width: 200px;
align-self: flex-end;
margin-left: 50%;
}
/*.center, .off-center {
position: absolute;
}*/
.center img {
width: 100%;
}
.off-center h2 {
font-size: 12px;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
text-transform: uppercase;
color: black;
display: block!important;
margin: 0px;
}
.off-center p {
font-size: 20px;
font-family: 'aileronbold', sans-serif;
display: block!important;
margin: 0px;
text-transform: none;
}
.row.subscriptionBar {
display: flex;
background-color: black;
display: block;
padding: 20px;
}
.subscriptionBar h2 {
color: white;
}
.firstPart {
display:
}
/*#media screen and (min-width: 769px) {
.off-center {
margin-left: 50%;
}
#media screen and (max-width: 768px) {
.off-center {
margin-top: 105px;
}
}*/
<div class="container">
<div class="top"><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<div class="off-center">
<h2 class="">ArtistName 1</h2>
<p>509476ZclHtqXy</p>
</div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 2</h2>
<p>Title lala 1</p>
</div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 3 444</h2>
<p>Title 093830</p>
</div>
</div>
</div>

How can I prevent my columns from stacking when the browser viewport shrinks

Instead of having my columns from stacking when the browser viewport shrinks, I want the columns to remain as they are but have a horizontal scroll bar to appear so people on smaller devices can just swipe right to scroll.
Is this possible since I am using flex?
body {
color: #333;
font-family: Helvetica Neue,Arial,Helvetica,sans-serif;
font-size: 14px;
line-height: 20px;
font-weight: 400;
}
.board-container {
background-color: rgb(0, 121, 191);
height: 100%;
position: relative;
background-size: cover;
overflow: hidden;
}
#board-surface {
display: flex;
flex-direction: column;
}
#board-surface, body, html {
height: 100%;
}
#content {
flex-grow: 1;
overflow-y: auto;
outline: none;
}
.board-wrapper {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.board-main-content {
height: 100%;
display: flex;
flex-direction: column;
margin-right: 0;
transition: margin .1s ease-in;
}
.board-canvas {
position: relative;
flex-grow: 1;
}
/*#board {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
margin-bottom: 8px;
overflow-x: auto;
overflow-y: hidden;
padding-bottom: 8px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}*/
.list-wrapper {
width: 272px;
margin: 0 4px;
height: 100%;
box-sizing: border-box;
display: inline-block;
vertical-align: top;
white-space: nowrap;
background-color: #cccccc;
}
.list {
background: #e2e4e6;
border-radius: 3px;
box-sizing: border-box;
display: flex;
flex-direction: column;
max-height: 100%;
position: relative;
white-space: normal;
}
.list-card {
background-color: #fff;
border-radius: 3px;
box-shadow: 0 1px 0 #ccc;
cursor: pointer;
display: block;
margin-bottom: 8px;
max-width: 300px;
min-height: 20px;
position: relative;
text-decoration: none;
z-index: 0;
}
<html>
<head>
<title></title>
</head>
<body>
<div class="board-container">
<div class="board-inner">
<div id="board-surface">
<div id="header">
main header goes here
</div>
<div id="content">
<div class="board-wrapper">
<div class="board-main-content">
<div class="board-header">board header</div>
<div class="board-canvas">
<div id="board">
<div class="list-wrapper">
<div class="list">
<div class="list-header">list header</div>
<div class="list-cards">
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
</div>
</div>
</div> <!-- /list-wrapper -->
<div class="list-wrapper">
<div class="list">
<div class="list-header">list header</div>
<div class="list-cards">
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
</div>
</div>
</div> <!-- /list-wrapper -->
<div class="list-wrapper">
<div class="list">
<div class="list-header">list header</div>
<div class="list-cards">
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
</div>
</div>
</div> <!-- /list-wrapper -->
<div class="list-wrapper">
<div class="list">
<div class="list-header">list header</div>
<div class="list-cards">
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
<div class="list-card">
this is a list card
</div>
</div>
</div>
</div> <!-- /list-wrapper -->
</div> <!-- /board-->
</div>
</div>
</div>
</div>
<div id="footer">
</div>
</div>
</div>
</div>
</body>
</html>
DEMO: https://codepen.io/anon/pen/wxJGMx?editors=0110
I was able to achieve a horizontal scroll on flex container. I've given min-width to .list-wrapper and have added the below styles to #board item:
.list-wrapper {
min-width: 272px;
width: 272px;
margin: 0 4px;
height: 100%;
box-sizing: border-box;
display: inline-block;
vertical-align: top;
white-space: nowrap;
background-color: #cccccc;
}
#board {
display: flex;
overflow: scroll;
}

Displaying content below a fixed header

My page has a fixed header, I am aware that this causes content flows to begin at the top of the page. I've been searching for a workaround for this and nothing seems to be working, for example this one
Below is the code and here is a codepen - As you can see the content in my article is being displayed at the top of the page, although it is place at the bottom of my html.
I'd appreciate an explained workaround so that I can LEARN.
UPDATE - adding padding-top:{500px} successfully fixed this issue. Is this a recommended workaround? I was made aware of this fix here.
Thanks guys!
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
}
.col-1 {
width: 100%;
}
.inline-block-container>* {
display: -moz-inline-stack;
display: inline-block;
}
ul,
ol {
list-style: none;
margin: 0px;
padding: 0px;
}
.wrapper {
position: fixed;
height: 100px;
width: 100%;
top: 0;
z-index: 99;
}
.header {
width: 100%;
top: 0;
border-bottom: 1px solid #ddd;
background-color: white;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
}
.header .logo a img {
width: 150px;
height: 49px;
}
.logo {
margin-left: 40px;
}
.menu li {
padding-right: 50px;
margin-right: 20px;
}
.header .menu ul {
margin: 0;
padding: 0;
}
.header .menu ul li {
display: inline-block;
list-style: none;
}
.header .menu ul li a {
text-decoration: none;
display: block;
padding: 30px 20px;
}
.site-content {
margin-top: 100px;
}
.banner-home {
background: url("");
height: 100vh;
width: 100%;
background-size: cover;
position: absolute;
z-index: -1000;
}
#intro {
position: absolute;
top: 70%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
text-align: center;
color: #020000;
z-index: 50;
}
#intro a {
border: 3px solid #020000;
cursor: pointer;
}
#intro li a {
padding: 20px;
color: #020000;
font-weight: 800;
}
#intro li a:hover {
background-color: #ffd800;
}
<div id="page" class="rare-site">
<div class="wrapper">
<div id="global-navigation">
<!-- Global Header -->
<header class="header">
<div class="logo">
<a href="">
<!--<img src="images/rare-logo.png">-->
<h1>Rare Select</h1>
</a>
</div>
<nav class="menu">
<ul>
<li>HOME</li>
<!--
-->
<li>
<div class="flexbox-container">
INFO
</li>
<!--
-->
<li>
<div class="flexbox-container">
NEWSLETTER
</div>
<!--
-->
<li>
<div class="flexbox-container">
CONTACT
</li>
<!--
-->
</ul>
</header>
</div>
</div>
<div id="content" class="site-content">
<div id="primary" class="content-area">
<!-- Content Area -->
<main id="main" class="site-main" role="main">
<div class="banner large-trunk">
<div class="banner-home"></div>
<div class="banner-overlay">
<div id="intro">
<h2 class="discover"><u>The easy way to discover models.</u></h2>
<div id="button-container">
<div id="button-overlay">
<ul class="inline-block-container">
<li><a class="discover-1">I'm looking to become a model</a></li>
<li><a class="discover-2">I'm looking for a model</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<article id="newsletter">
<div class="newsletter-entry">
<section class="news-content trunk">
<div class="feature-box">
<h2>Recent News</h2>
</div>
</section>
</div>
</article>
</main>
</div>
</div>
</div>
You already have a 100px header and a margin-top applied to site-content for the content following it, as is usually done.
A position: fixed header will be taken out of the flow. So the DOM element following it will overlap.
A z-index higher that the surrounding content is given so that it comes on top (which you have done giving wrapper a z-index: 99)
The content following it is given a margin-top value. If the height of the header is fixed (as is the case here) you give it using CSS, if the height of the header is dynamic, you might have to opt for javascript to set the height dynamically.
So restrict the heights of #global-navigation and .header using height: 100% and add display: flex to the navigation ul. Also remove the absolute positioning of the banner and apply background image to site-content- see demo below:
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
}
.col-1 {
width: 100%;
}
.inline-block-container>* {
display: -moz-inline-stack;
display: inline-block;
}
ul,
ol {
list-style: none;
margin: 0px;
padding: 0px;
}
.wrapper {
position: fixed;
height: 100px;
width: 100%;
top: 0;
z-index: 99;
}
#global-navigation { /* ADDED */
height: 100%;
}
.header {
height: 100%; /* ADDED */
width: 100%;
top: 0;
border-bottom: 1px solid #ddd;
background-color: white;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
}
.header .logo a img {
width: 150px;
height: 49px;
}
.site-content { /* ADDED */
background: url("http://placehold.it/50x50");
height: 100vh;
width: 100%;
background-size: cover;
}
.logo {
margin-left: 40px;
}
.menu li {
padding-right: 50px;
margin-right: 20px;
}
.header .menu ul {
display: flex; /* ADDED */
margin: 0;
padding: 0;
}
.header .menu ul li {
display: inline-block;
list-style: none;
}
.header .menu ul li a {
text-decoration: none;
display: block;
padding: 30px 20px;
}
.site-content {
margin-top: 100px;
}
.banner-home {} /* removed absolute positioning */
#intro { /* removed absolute positioning */
width: 100%;
text-align: center;
color: #020000;
z-index: 50;
}
#intro a {
border: 3px solid #020000;
cursor: pointer;
}
#intro li a {
padding: 20px;
color: #020000;
font-weight: 800;
}
#intro li a:hover {
background-color: #ffd800;
}
<div id="page" class="rare-site">
<div class="wrapper">
<div id="global-navigation">
<!-- Global Header -->
<header class="header">
<div class="logo">
<a href="">
<!--<img src="images/rare-logo.png">-->
<h1>Rare Select</h1>
</a>
</div>
<nav class="menu">
<ul>
<li>HOME</li>
<!--
-->
<li>
<div class="flexbox-container">
INFO
</div>
</li>
<!--
-->
<li>
<div class="flexbox-container">
NEWSLETTER
</div>
<!--
-->
<li>
<div class="flexbox-container">
CONTACT
</div>
</li>
<!--
-->
</ul>
</nav>
</header>
</div>
</div>
<div id="content" class="site-content">
<div id="primary" class="content-area">
<!-- Content Area -->
<main id="main" class="site-main" role="main">
<div class="banner large-trunk">
<div class="banner-home"></div>
<div class="banner-overlay">
<div id="intro">
<h2 class="discover"><u>The easy way to discover models.</u></h2>
<div id="button-container">
<div id="button-overlay">
<ul class="inline-block-container">
<li><a class="discover-1">I'm looking to become a model</a></li>
<li><a class="discover-2">I'm looking for a model</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<article id="newsletter">
<div class="newsletter-entry">
<section class="news-content trunk">
<div class="feature-box">
<h2>Recent News</h2>
</div>
</section>
</div>
</article>
</main>
</div>
</div>
</div>

Safari isn't stretching image to flexbox grid

I'm trying to build a simple teaser grid for featured posts on a website using flexbox. It should look like this:
And in FF and Chrome it's all good. If i change the resolution of one image, all the others follow and update their size. But not in Safari. Whatever i do, it never fits to an equal height:
I really don't get the point why this is happening. Each image container on the right has exactly 50% of the height calculated by flexbox. And each image should be stretched to that height.
I could probably achieve this with background-size:cover but i would love to find a solution to use img tags instead.
Here's a demo: https://jsfiddle.net/7tjw8j83/1/
.featured-grid{
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left{
width: 66.6666%;
}
.right{
width: 33.3333%;
display: flex;
flex-direction: column;
}
.right-top{
background: green;
flex: 1;
}
.right-bottom{
background: red;
flex: 1;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057">
</div>
</div>
</div>
In addition to Michaels suggestion, you could do like this, where I used background-image instead of img (since you use a given height anyway), and how to add text at an absolute position
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
background-position: center;
background-repeat: no-reapat;
background-size: cover;
overflow: hidden;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left" style="background-image: url(https://unsplash.it/600/450?image=1055)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top" style="background-image: url(https://unsplash.it/600/400?image=1051)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom" style="background-image: url(https://unsplash.it/600/400?image=1057)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated based on a comment
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
overflow: hidden;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057"> <div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated (2:nd) based on a comment
html,
body {
margin: 0;
}
.featured-grid {
display: flex;
}
div {
position: relative;
overflow: hidden;
}
img {
visibility: hidden;
display: block;
}
img.show {
position: absolute;
visibility: visible;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
.left img {
max-height: 100vh;
}
.right img {
max-height: 50vh;
}
.left {
width: 66.666%;
}
.right {
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top {
flex: 1;
}
.right-bottom {
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/300/250?image=1055">
<img class="show" src="https://unsplash.it/300/250?image=1055">
<div class="text">
<h2>Title 1</h2>
<h3>Text 1</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 2</h2>
<h3>Text 2</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 3</h2>
<h3>Text 3</h3>
</div>
</div>
</div>
</div>

Flexbox vertical overflow issue

I am trying to create a portfolio page for FreeCodeCamp using flexbox for the layout, but I'm having trouble with vertical overflow. The HTML:
<div class="flex-container flex-column top">
<header class="flex-container">
<h1 class="logo"><i class="fa fa-hashtag"></i>DubDev</h1>
<nav>
<ul>
<li>ABOUT</li>
<li>PORTFOLIO</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
<main class="flex-container">
<a name="about"></a>
<section class="about">
<h2>About Me</h2>
</section>
<a name="project"></a>
<section class="projects flex-container">
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
<article class="card flex-container flex-column">
<img src="http://fpoimg.com/300x250">
<div class="card-title">
<h2>Project 1</h2>
</div>
</article>
</section>
<a name="contact"></a>
<section class="contact">
<h2>Contact Me </h2>
</section>
</main>
<footer class="flex-container">
<p>© 2016 Dubrick Development<p>
</footer>
</div>
The CSS:
#import url(https://fonts.googleapis.com/css?family=Passion+One:400,700);
#import url(https://fonts.googleapis.com/css?family=Droid+Serif:700);
*, *:before, *:after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
html, body {
height: 100%;
}
footer, header {
font-family: "Passion One", sans-serif;
font-weight: 400;
background: #1abc9c;
color: white;
width: 100%;
/* flex: 0 0 75px; */
}
footer, header > * {
padding: 0 5px 0 5px;
}
footer {
box-shadow:4px -4px 0 rgba(0,0,0,0.1);
justify-content: center;
align-items: center;
font-size: 18px;
}
header {
box-shadow:4px 4px 0 rgba(0,0,0,0.1);
}
main {
flex-wrap: wrap;
overflow-y: auto;
background-color: #909AA1;
justify-content: center;
position: relative;
flex: 0 1 auto;
}
nav {
flex: 1;
align-self: center;
text-align: right;
padding-right: 20px;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
nav ul li {
display: inline;
font-size: 36px;
padding: 10px;
transition: background-color 0.5s ease;
}
nav ul li:hover {
background-color: rgba(0,0,0,0.2);
}
nav ul li a {
color: white;
text-decoration: none;
}
.about {
flex-basis: 1000px;
}
.card {
box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12);
flex-basis: 300px;
height: 300px;
margin: 10px;
align-items: center;
}
.card > img {
flex-basis: 250px;
}
.card .card-title {
background-color: white;
flex: 1;
align-self: stretch;
text-align: center;
font-family: "Droid Serif";
}
.flex-container {
display: flex;
}
.flex-column {
flex-direction: column;
}
.logo {
padding: 5px;
border-radius: 5px;
border: 1px solid white;
box-shadow: 1px 1px 5px rgba(0,0,0,0.3);
text-shadow:4px 4px 0 rgba(0,0,0,0.1);
}
.projects {
flex: 0 1 1000px;
flex-wrap: wrap;
justify-content: center;
padding-top: 20px;
padding-bottom: 20px;
background-color: #D8DBDE;
max-height: 100%;
}
.contact {
flex-basis: 1000px;
}
.top {
height: 100%;
}
If I don't set height: 100%; on the top div, there is no overflow, but it doesn't seem to "flex"; that is, main does not fill the space between the header and footer with the header and footer remaining sticky. If I do set height: 100%; on the top div, as shown in the code, main fills the available space, but the flex-item children of section class="projects" now overflow. I'm very new to flexbox, so I'm probably doing something stupid here, but I can't figure out what it is.
Link to codepen
This should be the most apt-solution for you.
if you want your header's height to be relative then you will have to use jquery else you can just set a margin-top: 90px; to #content
new css required
.content{
position: relative;
}
#top-1 {
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
height: 60px;
margin: 0;
}
small js required to adjust content's margin-top (jquery required)
$(document).ready(function() {
$('#content').css('margin-top', $('#top-1').height() + 'px');
});
http://codepen.io/Rohithzr/pen/PNKmwb

Resources