Creating a flexbox grid with images that resizes properly - html

I'm creating a grid in flexbox that has images on one side and then text on the other. The problem I'm facing is that the images aren't aligning properly in the grid.
Here is my code:
/* iPhone */
#media only screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.body-img {
background: url('background-mobile.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
width: 100%;
}
.search-img {
background: url('search-img-mobile.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
padding-bottom: 10%;
}
.logo {
width: 150px;
margin-top: 15%;
}
h1,
h2 {
font-family: 'Open Sans', sans-serif;
color: #ffffff;
font-weight: 300;
padding-top: 20%;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.5em;
padding-bottom: 15%;
}
h3 {
font-family: 'Open Sans', sans-serif;
font-size: 1.0em;
font-weight: 400;
}
.searchbar {
margin-top: 15%;
}
.btn {
background-color: #1075C1;
color: #ffffff;
border-radius: 0px;
}
#keyframes bouncing {
0% {
bottom: 0;
}
50% {
bottom: 20px;
}
100% {
bottom: 0;
}
}
.arrow {
animation: bouncing 1s infinite ease-in-out;
bottom: 0;
display: block;
height: 26px;
left: 50%;
margin-left: -25px;
position: absolute;
width: 26px;
}
.left {
background-color: #1075C1;
}
.col-md-12 {
min-height: 0px;
}
.container-flex {
display: flex;
flex-direction: column-reverse !important;
justify-content: space-between;
}
.container-flex2 {
display: flex;
flex-direction: column-reverse !important;
justify-content: space-between;
}
.searchbox {
background-color: rgba(255, 255, 255, 0.6);
padding-top: 5%;
padding-left: 5%;
padding-right: 5%;
padding-bottom: 5%;
}
.form-check-label {
font-size: 0.8em;
}
.btn-lg {
padding-left: 25%;
padding-right: 25%;
padding-top: 5%;
padding-bottom: 5%;
}
.btn-lg:hover {
background-color: #003e6c;
}
}
#media only screen and (min-width: 1024px) {
body {
overflow-x: hidden;
}
.body-img {
background: url('nathan-dumlao-609935-unsplash.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
width: 100%;
}
.logo {
width: 250px;
margin-top: 15%;
}
h1,
h2 {
font-family: 'Open Sans', sans-serif;
color: #ffffff;
font-weight: 300;
padding-top: 5%;
}
.searchbar {
margin-top: 8%;
}
.btn {
background-color: #1075C1;
color: #ffffff;
border-radius: 0px;
}
.arrow {
display: none;
}
.container-flex {
display: flex;
flex-direction: row !important;
justify-content: space-between;
background-color: #1075C1;
}
.container-flex2 {
display: flex;
flex-direction: row-reverse;
background-color: #1075C1;
justify-content: space-between;
}
.left {
background-color: #1075C1;
}
.description {
background-color: #1075C1;
}
}
<section id="one">
<div class="container-flex">
<div class="left">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Sign up for our career guide and receive free insight into available jobs</h2>
</div>
</div>
</div>
<div class="right">
<img src="section1-mobile.png" class="img-fluid">
</div>
</div>
<div class="container-flex2">
<div class="left">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Answer questions as we help you with your job search</h2>
</div>
</div>
</div>
<div class="right">
<img src="section2.png" class="img-fluid">
</div>
</div>
<div class="container-flex">
<div class="left">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Get matched with companies looking for talent like you</h2>
</div>
</div>
</div>
<div class="right">
<img src="section3.png" class="img-fluid">
</div>
</div>
</section>
The end result I'm looking for.
I'm not sure what I'm doing wrong in the CSS?

There's a few things to point out here that might help you in getting things how you want them to look.
Firstly, your indentation in your markup is a wee bit skew, so, at first glance, it's a little bit tricky to figure out, sorting the indentation in both your markup and css will make it easier for you, and others, to debug.
Secondly, you've got a lot of superfluous styles / class in your markup that look like they're from bootstrap. These could potentially be affecting your own custom styles and causing conflicts.
Thirdly you've got an awful lot going on in terms nesting in your markup that makes it difficult to apply styles too.
I would suggest simplifying your markup first.
I would also suggest stripping back your css to the bare minimum needed, removing your vendor prefixes (-webkit-, -o-), the #keyframes declaration (or at the very least commenting them out). You can always add them after or put you css through a preprocessor or autoprefixer afterwards but for debugging they can make things difficult.
Flexbox can be a bit tricky at times, so I put together a pen on codepen showing how I would approach your mockup (full code below). It's just a quick draft but maybe some other community members will have some input / suggestions. In the meantime have a play around with the values and look at the outcome.
I'd also recommend this SO question regarding flexbox, the top answer is fairly concise about horizontal and vertical alignment. I'd also recommend checking out flex box froggy for honing you flex box skills.
markup:
<section class="section">
<div class="row">
<div class="content">
<span class="icon">🎨</span>
<span class="text">here is some text</span>
</div>
<img class="image" src="http://lorempixel.com/400/200" />
</div>
<div class="row">
<div class="content">
<span class="icon">🐳</span>
<span class="text">here is some other text</span>
</div>
<img class="image" src="http://lorempixel.com/400/200" />
</div>
<div class="row">
<div class="content">
<span class="icon">💰</span>
<span class="text">here is some more text</span>
</div>
<img class="image" src="http://lorempixel.com/400/200" />
</div>
</section>
css:
body {
width: 100%;
text-align: center;
font-family: sans-serif;
}
.section, .row {
width: 75vw;
background: dodgerblue;
color: #fff;
font-size: 1.5em;
}
.section {
display: inline-block;
}
.row {
display: flex;
justify-content: space-between;
flex-direction: row;
}
.row:nth-child(odd) {
flex-direction: row-reverse;
}
.content {
width: 50%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.text {
width: 50%;
text-align: center;
}
.image {
width: 50%;
height: auto;
}
.icon {
font-size: 1.5em;
}
I hope this helps.

I have tested both snippets on screen size (1024x786) and ipad pro (1024x1366)
/* iPhone */
.left {
width: 50%;
left: 0px;
}
.right {
width: 50%;
right: 0px;
}
h2 {
font-family: arial !important;
}
#media only screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.body-img {
background: url('background-mobile.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
width: 100%;
}
.search-img {
background: url('search-img-mobile.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
padding-bottom: 10%;
}
.logo {
width: 150px;
margin-top: 15%;
}
h1, h2 {
font-family: 'Open Sans', sans-serif;
color: #ffffff;
font-weight: 300;
padding-top: 20%;
}
h1 {
font-size: 1.3em;
}
h2 {
font-size: 1.3em;
padding-bottom: 15%;
}
h3 {
font-family: 'Open Sans', sans-serif;
font-size: 1.0em;
font-weight: 400;
}
.searchbar {
margin-top: 15%;
}
.btn {
background-color: #1075C1;
color: #ffffff;
border-radius: 0px;
}
.arrow {
animation: bouncing 1s infinite ease-in-out;
bottom: 0;
display: block;
height: 26px;
left: 50%;
margin-left: -25px;
position: absolute;
width: 26px;
}
.left {
background-color: #1075C1;
}
.col-md-12 {
min-height: 0px;
}
.container-flex {
display: flex;
justify-content: space-between;
}
.container-flex2 {
display: flex;
justify-content: space-between;
}
.searchbox {
background-color: rgba(255, 255, 255, 0.6);
padding-top: 5%;
padding-left: 5%;
padding-right: 5%;
padding-bottom: 5%;
}
.form-check-label {
font-size: 0.8em;
}
.btn-lg {
padding-left: 25%;
padding-right: 25%;
padding-top: 5%;
padding-bottom: 5%;
}
.btn-lg:hover {
background-color: #003e6c;
}
.text-center {
height: 200px;
line-height: 200px;
text-align: center;
border: 2px dashed #f69c55;
}
.text-center h2 {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
}
#media only screen and (min-width: 1024px) {
body {
overflow-x: hidden;
}
.body-img {
background: url('nathan-dumlao-609935-unsplash.png') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100vh;
width: 100%;
}
.logo {
width: 250px;
margin-top: 15%;
}
h1, h2 {
font-family: 'Open Sans', sans-serif;
color: #ffffff;
font-weight: 300;
padding-top: 5%;
}
.searchbar {
margin-top: 8%;
}
.btn {
background-color: #1075C1;
color: #ffffff;
border-radius: 0px;
}
.arrow {
display: none;
}
.container-flex {
display: flex;
justify-content: space-between;
background-color: #1075C1;
}
.container-flex2 {
display: flex;
flex-direction: row-reverse;
background-color: #1075C1;
justify-content: space-between;
}
.left {
background-color: #1075C1;
}
.description {
background-color: #1075C1;
}
.text-center {
height: 500px;
line-height: 500px;
text-align: center;
border: 2px dashed #f69c55;
}
.text-center h2 {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section id="one">
<div class="container-flex">
<div class="left">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Sign up for our career guide and receive free insight into available jobs</h2>
</div>
</div>
</div>
<div class="right">
<img src="https://dummyimage.com/500x500/000/fff" class="img-fluid">
</div>
</div>
<div class="container-flex2">
<div class="right">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Answer questions as we help you with your job search</h2>
</div>
</div>
</div>
<div class="left">
<img src="https://dummyimage.com/500x500/000/fff" class="img-fluid">
</div>
</div>
<div class="container-flex">
<div class="left">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h2>Get matched with companies looking for talent like you</h2>
</div>
</div>
</div>
<div class="right">
<img src="https://dummyimage.com/500x500/000/fff" class="img-fluid">
</div>
</div>
</section>
</body>
</html>
I also attached output screenshots for both size
Hope, you find your solution.

Use <img> instead of background image, because you can make them responsive more easy with
.img-responsive {
display: block;
height: auto;
max-width: 100%;
}
Therefore use big sizes for the images so that they always fill up the space.
Use flex-basis to handle width, e.g. 60% for the left side and 40% for the right side.
Make the container flex-wrap: wrap so that the columns in the container are wrapped and not in a row.
Set the column inside a container
.container > div {
display: flex;
flex-direction: column;
justify-content: center; // Center vertically
align-items: center; // Center horizontally
}
to center the content within horizontally and vertically.
Example
body {
background: black;
}
.container {
display: flex;
flex-wrap: wrap;
margin: 0 auto;
max-width: 960px;
border: 3px solid white;
background: #0F75C0;
}
.container>div {
display: flex;
flex-direction: column;
box-sizing: border-box;
justify-content: center;
align-items: center;
}
/* Columns on the left side */
.container>div:nth-child(odd) {
flex-basis: 60%;
}
/* Columns on the right side */
.container>div:nth-child(even) {
flex-basis: 40%;
}
/* Make images responsive */
.container>div>img {
display: block;
height: auto;
max-width: 100%;
}
.container .info {
max-width: 70%;
text-align: center;
padding: 15px;
font-size: 22px;
color: white;
}
#media screen and (max-width: 320px) {
.container {
flex-direction: column;
}
}
<div class="container">
<div>
<div class="info">
<img src="http://via.placeholder.com/48x48?text=icon" alt="">
<p>Sign up for our career guide</p>
</div>
</div>
<div>
<img src="http://via.placeholder.com/800x600" alt="">
</div>
<div>
<img src="http://via.placeholder.com/1000x500" alt="">
</div>
<div>
<div class="info">
<img src="http://via.placeholder.com/48x48?text=icon" alt="">
<p>Answer a few questions as we aid you in your job search</p>
</div>
</div>
<div>
<div class="info">
<img src="http://via.placeholder.com/48x48?text=icon" alt="">
<p>Get matched with companies looking for talent like you</p>
</div>
</div>
<div>
<img src="http://via.placeholder.com/800x600" alt="">
</div>
</div>

Related

How can I add an element in a flex column without affecting other item's position?

I wan't to add a p like this.
I can add it, but when I use margin-top to put it down, it affects the elements above like this.
I don't know how to solve this.
Thank you.
HTML.
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
CSS:
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
}
}
}
}
position: absolute; is your friend...
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
position: relative;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
position: absolute;
}
}
}
}

Flexbox: how to put another object here [duplicate]

This question already has answers here:
Make a div span two rows in a grid
(2 answers)
Closed 2 years ago.
I'm using display: flex; to create tiles view.
I'm trying to put the third picture under the second picture.
But, whenever I do it, the third picture went under the first picture and won't come under second picture,
#media screen and (min-width: 1000px) {
.main {
height:1800px;
width: 100%;
margin: 0px 0px 0px 0px;
position: relative;
z-index: 0;
}
.parallax {
/* The image used */
background-image: url("https://i.ibb.co/r272XPt/2019-2020.png");
/* Set a specific height */
min-height: 400px;
opacity: 60%;
filter: blur(2px);
-webkit-filter: blur(2px);
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.tiles{
position:relative;
top:100px;
width:90vw;
margin-left:5vw;
display: flex;
flex-wrap: wrap;
}
.chromebookHelpdesk img{
margin-left:5vw;
width:50vw;
display:block;
}
.subhelp{
height:25vw;
}
.subhelp img{
margin-left:5vw;
width:25vw;
display:block;
}
.studentsTour img{
margin-left:5vw;
width:20vw;
margin-top:5vw;
display:block;
}
#projects img {
text-align: center;
display: block;
width: 25vw;
margin: 20px;
}
.mission_logo {
width: 200px;
display: inline-block;
float: left;
text-align: center;
}
.mission {
text-align: center;
margin-top: 100px;
font-size: 20px;
}
.ingenuity {
color: #3cba54;
font-size: 60px !important;
}
.creativity {
color: #f4c20d;
font-size: 60px !important;
}
.innovation {
color: #db3236;
font-size: 60px !important;
}
}
#media only screen and (max-width: 1000px) {
.main {
height:2500px;
width: 100%;
margin: 0px 0px 0px 0px;
position: relative;
z-index: 0;
}
.parallax {
display: none;
}
.mission_logo {
width: 60vw;
text-align: center;
}
.mission {
text-align: center;
margin-top: 100px;
font-size: 15px;
}
.ingenuity {
color: #3cba54;
font-size: 40px !important;
}
.creativity {
color: #f4c20d;
font-size: 40px !important;
}
.innovation {
color: #db3236;
font-size: 40px !important;
}
}
.tiles h1 {
text-align: center;
font-size: 50px;
color: black;
}
.follow{
position:relative;
top:100px;
text-align:center;
border-radius: 50%;
background-color: #84e3ca;
width: 50vw;
height: 50vw;
margin-left: 25vw;
opacity:70%;
}
.follow h1{
font-size:35px;
padding-top: 20vw;
}
.follow h2{
font-size:30px;
}
<div class="main">
<div class="tiles">
<div class="chromebookHelpdesk"><a href="https://sledteam.github.io/sled/chromebook"><img
src="https://github.com/sledteam/sled/blob/master/Chromebook%20Helpdesk.png?raw=true" alt="Chromebook-Helpdesk"></a></div>
<div class="subhelp"><a href="https://sledteam.github.io/sled/chromebook"><img
src="https://github.com/sledteam/sled/blob/master/Sub%20Help.png?raw=true" alt="Sub Help"></a>
</div>
<div class="studentsTour"><a href="https://sledteam.github.io/sled/chromebook"><img
src="https://github.com/sledteam/sled/blob/master/New%20Students%20Tour.png?raw=true" alt="New Students Tour"></a></div>
</div>
I'm stuck with this for a week.
I would appreciate it if anyone knows a solution for this.
Complete guide to css flexbox
.tiles {
display: flex;
flex-wrap: wrap;
flex-direction: row;
flex: 1;
}
.section {
display: flex;
flex: 1;
flex-direction: column;
}
.item {
display: flex;
flex: 1;
padding: 1rem;
margin: 4px;
background: green;
color: white;
}
<div class="tiles">
<div class="section">
<div class="item">
<p>Chromebook Helpdesk</p>
</div>
</div>
<div class="section">
<div class="item">
<p>Sub Help</p>
</div>
<div class="item">
<p>Student Tour</p>
</div>
</div>
</div>
It is simple if you understand the concept here is the example:
As per your requirement you need 2 columns with single row so you will be creating flex property, now you need 2 columns hence you make it flex:50% like 2. Now coming to your image section where you need 2 images to be underneath so you will provide the height:50%(right images) and you will give height:100%(left image).
You can keep changing the sizes as you desire. You can also add responsive design for the same. Hope it helps.
* {
box-sizing: border-box;
}
.row {
display: flex;
}
.column {
flex: 50%;
padding: 5px;
}
<div class="row">
<div class="column">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg" style="width:100%" />
</div>
<div class="column">
<div class="row">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg" style="width:50%" />
</div>
<div class="row">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg" style="width:50%" />
</div>
</div>
</div>

Flexbox row with min-height does not stretch in IE

I have one flexbox with two rows and min-height. The right row has another flex with 2 columns with justify-content space between.
It works perfectly fine in Chrome but it does not fill the min-height in IE. There are many questions about it but none of them worked for me. Please note I have different styles of this where image is on top, bottom or right. I need to expand both content and image to fill the entire card in IE.
Here is the code.
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
Image from IE
Its a bug in IE 10-11. In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.
More info: https://github.com/philipwalton/flexbugs#flexbug-3
Workaround
Simply wrap the flex container (here it div with classname card) with another flex-container having flex direction column
.ie-fix-wrapper{
display: flex;
flex-direction:column;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class="ie-fix-wrapper">
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
The solution provided by #Soothran works well. There is also alternative solution that is quicker to implement - inherit min-height in the children. In this case of the code above:
.image-wrap {
min-height: inherit;
}
.card-content {
min-height: inherit;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
min-height: inherit;
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.image-wrap {
min-height: inherit;
}
.card-image {
width: 100%;
width:80px;
height: 100%;
background: black;
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
You need to wrap any flex-direction:column inside a flex-direction:row
(or just display:flex for simple)

How to make dynamic div overflow without fixed height

I'm trying to create a scrolling element without a fixed height parent. I want #SECTION1 of my code to be scrollable to show the rest of the images. I can't seem to find a way to do this. I've attempted to set #SECTION1 to a fixed height but it forces my images to be squashed. Any help would be appreciated. Thank you.
Here is my code:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
text-decoration: none;
}
::-webkit-scrollbar {
width: 15px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
html,
body {
margin: 0;
padding: 0;
height: 100vh;
overflow: hidden;
}
/*----------SECTION 1----------*/
header {
height: 80px;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
#header-wrapper {
display: flex;
width: 55%;
justify-content: space-between;
align-items: center;
}
#logo {
width: 70px;
}
nav a {
color: white;
padding: 20px;
font-family: 'Roboto';
font-size: 0.8em;
font-weight: bold;
}
#media only screen and (max-width: 750px) {
nav {
display: none;
}
}
#mobile-menu {
color: white;
font-size: 1.3em;
}
#media only screen and (min-width: 750px) {
#mobile-menu {
display: none;
}
}
#body-wrapper {
display: flex;
height: 100%;
}
aside {
width: 300px;
height: 889px;
background-color: #0c0c0c;
display: flex;
align-items: center;
padding-top: 50px;
flex-direction: column;
}
#aside-wrap {
width: 70%;
}
#user-info {
display: flex;
margin: 10px;
margin-left: 0;
margin-bottom: 50px;
justify-content: center;
align-items: center;
font-family: 'Roboto';
font-weight: 400;
}
#user {
font-size: 40px;
color: white;
margin-right: 20px;
}
aside h3 {
color: white;
font-size: 1.2em;
}
#hello {
color: white;
font-size: 20px;
}
#box-1 {
color: #808080;
margin-bottom: 60px;
}
#box-1 p {
margin: 20px;
margin-left: 0;
font-family: 'Roboto';
font-size: 0.9em;
}
#box-2 {
color: #808080;
}
#box-2 p {
margin: 20px;
margin-left: 0;
font-family: 'Roboto';
font-size: 0.9em;
}
#section1 {
background-color: #191919;
/*background: linear-gradient(rgba(0,0,0,0.3),rgba(0,0,0,0.3)),
url("listen_background.jpg");*/
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 100%;
overflow: auto;
}
#section1-wrapper {
width: 80%;
display: flex;
font-family: 'Roboto';
padding-top: 50px;
padding-bottom: 50px;
align-items: center;
flex-direction: column;
}
#section1 h1 {
color: white;
font-size: 3em;
margin-bottom: 50px;
text-align: center;
}
.image-box {
max-width: 280px;
margin: 20px;
}
img {
max-width: 100%;
}
#image-row-1,
#image-row-2,
#image-row-3,
#image-row-4 {
width: 100%;
margin-bottom: 50px;
display: flex;
justify-content: space-between;
}
#media only screen and (max-width: 1080px) {
#image-row-1,
#image-row-2,
#image-row-3,
#image-row-4 {
flex-direction: column;
align-items: center;
}
}
/*----------------SECTION 2--------------*/
#pusher {
height: 889px;
width: 300px;
}
#player {
height: 80px;
width: 100%;
position: fixed;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: black;
}
#media only screen and (max-width: 750px) {
#player {
height: auto;
}
}
#player-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
width: 80%;
}
#media only screen and (max-width: 750px) {
#player-wrapper {
flex-direction: column;
}
}
.button-controls {
color: white;
margin: 20px;
}
#player-bar {
width: 100%;
height: 3px;
background-color: white;
}
#player-filler {
width: 50%;
height: 100%;
background-color: #2A4B5A;
}
#timeline {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
}
#media only screen and (max-width: 750px) {
#timeline {
width: 100%;
}
}
#timeline p {
color: white;
margin: 20px;
}
#share,
#phone {
color: white;
margin: 20px;
}
#media only screen and (max-width: 750px) {
#share,
#phone {
display: none;
}
}
<head>
<meta charset="utf-8">
<title>Flo Music</title>
<link rel="stylesheet" type="text/css" href="listen.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
</head>
<body>
<div id="test">
<div id="body-wrapper">
<aside>
<div id="aside-wrap">
<div id="user-info">
<i class="far fa-user-circle" id="user"></i>
<h3>Emmanuel</h3>
</div>
<div id="box-1">
<p>Your Library</p>
<p>Recently Played</p>
<p>Songs</p>
<p>Playlist</p>
</div>
<div id="box-2">
<p>Your Library</p>
<p>Recently Played</p>
<p>Songs</p>
<p>Playlist</p>
</div>
<p>HOME</p>
</div>
</aside>
<section id="section1">
<div id="section1-wrapper">
<h1>New Releases</h1>
<div id="image-row-1">
<div class="image-box"><img src="album1.jpg"></div>
<div class="image-box"><img src="album2.jpg"></div>
<div class="image-box"><img src="album3.jpg"></div>
<div class="image-box"><img src="album4.jpg"></div>
</div>
<div id="image-row-2">
<div class="image-box"><img src="album5.jpg"></div>
<div class="image-box"><img src="album6.jpg"></div>
<div class="image-box"><img src="album7.jpg"></div>
<div class="image-box"><img src="album8.png"></div>
</div>
<div id="image-row-3">
<div class="image-box"><img src="album9.jpg"></div>
<div class="image-box"><img src="album10.jpg"></div>
<div class="image-box"><img src="album11.jpg"></div>
<div class="image-box"><img src="album12.jpg"></div>
</div>
<div id="image-row-4">
<div class="image-box"><img src="album13.jpg"></div>
<div class="image-box"><img src="album14.jpg"></div>
<div class="image-box"><img src="album15.jpg"></div>
<div class="image-box"><img src="album16.jpg"></div>
</div>
</div>
</section>
</div>
<div id="player">
<div id="player-wrapper">
<div id="controls">
<i class="fas fa-backward button-controls"></i>
<i class="fas fa-play button-controls"></i>
<i class="fas fa-forward button-controls"></i>
</div>
<div id="timeline">
<p>0:00</p>
<div id="player-bar">
<div id="player-filler"></div>
</div>
<p>0:00</p>
</div>
<div id="icon-right">
<i class="fas fa-share-square" id="share"></i>
<i class="fas fa-mobile" id="phone"></i>
</div>
Flex items are set to flex-shrink: 1 by default. This means they can shrink to prevent an overflow of the container. In your case, you may need to disable this feature (flex-shrink: 0).
Also, consider using height: 100vh, instead of height: 100% on your flex container. Percentage heights are tricky and often require the parent to have a defined height.
See this post for details: Working with the CSS height property and percentage values
Lastly, remove justify-content: center from your flex container. It makes content inaccessible via scroll in some cases.
See this post for details: Can't scroll to top of flex item that is overflowing container
Make these adjustments to your code:
#body-wrapper {
display: flex;
/* height: 100%; */
height: calc(100vh - 80px); /* subtract footer height */
}
#section1 {
background-color: #191919;
display: flex;
align-items: center;
/* justify-content: center; */ /* remove to avoid scrolling problems */
flex-direction: column;
width: 100%;
overflow: auto;
}
#section1-wrapper {
width: 80%;
display: flex;
font-family: 'Roboto';
padding-top: 50px;
padding-bottom: 50px;
align-items: center;
flex-direction: column;
flex-shrink: 0; /* add to disable flex default shrinking feature */
}
jsFiddle demo
You should change your overflow property in the #section1
#section1-wrapper {
overflow: scroll;
}

how to make website responsive vertically?

I have a webpage and I have the "body" wrapped around all my content. But when I do this webpage responsive and want the body to enlarge the web content the body stops enlarge the content vertically. It do enlarge the content when I increase the width but not vertically. I don't want the extra black area.
body {
background-color: black;
padding-bottom: 10vh;
padding-top: 10vh;
padding-right: 10vh;
padding-left: 10vh;
margin: 0;
height: 100%;
align-content: center;
justify-content: center;
position: relative;
}
#wrapper {
position: static;
align-items: center;
height: 100%;
width: 100%;
align-content: center;
display: flex;
flex-direction: row;
margin: 0 auto;
justify-content: center;
overflow: auto;
}
#wrapper2 {
align-items: center;
width: 100%;
height: 100%;
align-content: center;
display: flex;
flex-direction: row;
margin: 0 auto;
justify-content: center;
overflow: auto;
}
img {
width: 100%;
height: 100%;
display: block;
}
.cell1 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.cell2 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.cell3 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.dogname {
color: white;
top: 20px;
font-family: 'Roboto Condensed', sans-serif;
text-align: center;
position: absolute;
width: 100%;
margin: 0;
}
.dogtext {
color: white;
top: 0;
font-family: 'Roboto Condensed', sans-serif;
text-align: center;
position: relative;
width: 100%;
margin-bottom: 30px;
margin-top: 0px;
display: none;
}
#media screen and (max-width: 500px) {
#wrapper {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
#wrapper2 {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.cell1 {
width: 100vw;
}
.cell2 {
width: 100vw;
}
.cell3 {
width: 100vw;
}
.dogname {
display: none;
}
.dogtext {
display: block;
}
body {
background-color: black;
height: 100%;
padding: 0;
margin: 0;
}
}
<body>
<div id="wrapper">
<div class="cell1">
<p class="dogname">David Neal</p>
<img src="images/image1.jpg" />
</div>
<p class="dogtext">After the hunt (1870) by David Neal</p>
<div class="cell2">
<p class="dogname">BG Tiepolo</p>
<img src="images/image2.jpg" />
</div>
<p class="dogtext">Portrait of a Toy Spaniel Belonging to the Infanta Maria Josefa of Bourbon (1763) by Giovanni Battista Tiepolo</p>
<div class="cell3">
<p class="dogname">AF Desportes</p>
<img src="images/image3.jpg" />
<p class="dogtext">Chienne blanche devant un buisson de sureau (1714) by Alexandre-François Desportes</p>
</div>
</div>
<div id="wrapper2">
<div class="cell1">
<p class="dogname">JC Merck</p>
<img src="images/image4.jpg" />
<p class="dogtext">Ulmer Dogge (1705) by Johann Christof Merck</p>
</div>
<div class="cell2">
<p class="dogname">John Wootton</p>
<img src="images/image5.jpg" />
<p class="dogtext">A Grey Spotted Hound (1738) by John Wootton</p>
</div>
<div class="cell3">
<p class="dogname">EH Landseer</p>
<img src="images/image6.jpg" />
<p class="dogtext">A Distinguished Member of the Humane Society (1838) by Edwin Henry Landseer</p>
</div>
</div>
</body>
It really depends on what do you want to achieve, but generally, you can use media queries for height and combine them with the ones for width.
#media screen and (max-width: 800px) , screen and (max-height: 600px) {
...
}
By default, your webpage is vertically scaled based on the height of the content. To always have it at least be one viewheight high, you can insert this rule into your css:
html, body {
min-height: 100vh;
}