This question already has answers here:
How to set 66% area to one element and 33% and 33% to the other two elements using flexbox? [closed]
(3 answers)
flex-grow not sizing flex items as expected
(5 answers)
How to size flex-items without percentages?
(2 answers)
Closed 4 years ago.
I am making a grid system which I am building with the flex class. It is my first time working with flex, so I am not quite sure how it is functioning yet.
The grid I have made until now
is looking like this.
I would like the flexbox item 6 is looking like the below picture:
At the moment item 5 and item 6 is taking 50% width each
The item5 and item6 is taking 50% width. I cannot seem to change that. I would like that item 5 is taking around 66% and item 6 is taking 33%, but still have the margin around the elements.
Can somebody see what I am doing wrong?
<style>
.d-flex {
display: -ms-flexbox!important;
display: flex!important
}
.d-inline-flex {
display: -ms-inline-flexbox!important;
display: inline-flex!important
}
.flex-wrap {
-ms-flex-wrap: wrap!important;
flex-wrap: wrap!important
}
.bg-img {
background-position: center center;
background-size: cover;
background-repeat: no-repeat; }
/* CTA Buttons */
.btn-top-left {
position: absolute;
left: 10%;
top: 10%
}
.btn-top-right {
}
.btn-center {
position: absolute;
left: 50%;
top: 50%
}
.btn-bottom-left {
}
.btn-bottom-right {
}
/* :: Set overlay over image and placement of text */
.single-welcome-post {
position: relative;
z-index: 1; }
.single-welcome-post::after {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.4);
content: '';
z-index: 5; }
.single-welcome-post .welcome-post-content {
position: absolute;
z-index: 100;
left: 50px;
bottom: 50px;
right: 50px; }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.single-welcome-post .welcome-post-content {
left: 20px;
bottom: 20px;
right: 20px; } }
#media only screen and (max-width: 767px) {
.single-welcome-post .welcome-post-content {
left: 15px;
bottom: 15px;
right: 15px; } }
.single-welcome-post.style-2 {
height: 645px; }
.hero-area {
position: relative;
z-index: 0;
background-color: #ffffff;
padding: 5px; }
.hero-area .hero-single-section {
position: relative;
z-index: 0;
-webkit-box-flex: 0;
-ms-flex: 0 0 50%;
flex: 0 0 50%;
max-width: 50%;
width: 50%; }
#media only screen and (max-width: 767px) {
.hero-area .hero-single-section {
-webkit-box-flex: 0;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
max-width: 100%;
width: 100%; } }
.hero-area .item1 {
height: 700px;
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item1 {
height: 600px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item1 {
height: 500px; } }
#media only screen and (max-width: 767px) {
.hero-area .item1 {
height: 350px; } }
.hero-area .item2 {
height: 340px;
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item2 {
height: 290px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item2 {
height: 240px; } }
#media only screen and (max-width: 767px) {
.hero-area .item2 {
height: 200px; } }
.hero-area .item3 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(50% - 10px);
width: calc(50% - 10px);
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item3 {
height: 300px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item3 {
height: 250px; } }
#media only screen and (max-width: 767px) {
.hero-area .item3 {
height: 200px; } }
.hero-area .item4 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(50% - 10px);
width: calc(50% - 10px);
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item4 {
height: 300px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item4 {
height: 250px; } }
#media only screen and (max-width: 767px) {
.hero-area .item4 {
height: 200px; } }
.hero-area .item5 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(130% - 10px);
width: calc(130% - 10px);
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item5 {
height: 300px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item5 {
height: 250px;
max-width: calc(100% - 10px); } }
#media only screen and (max-width: 767px) {
.hero-area .item5 {
height: 200px;
max-width: calc(100% - 10px); } }
.hero-area .item6 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(100% - 10px);
width: calc(100% - 10px);
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item6 {
height: 300px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item6 {
height: 250px;
max-width: calc(100% - 10px); } }
#media only screen and (max-width: 767px) {
.hero-area .item6 {
height: 200px;
max-width: calc(100% - 10px); } }
.hero-area .item7 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(100% - 10px);
width: calc(100% - 10px);
margin: 5px; }
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item7 {
height: 300px; } }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item7 {
height: 250px;
max-width: calc(100% - 10px); } }
#media only screen and (max-width: 767px) {
.hero-area .item7 {
height: 200px;
max-width: calc(100% - 10px); } }
.single-blog-post {
position: relative;
z-index: 1; }
.single-blog-post .blog-thumb {
position: relative;
z-index: 1; }
.single-blog-post .blog-thumb img {
width: 100%; }
.single-blog-post .blog-content .post-tag {
color: #a6a6a6;
text-transform: uppercase;
font-size: 12px;
display: block;
font-weight: 700;
margin-bottom: 5px; }
.single-blog-post .blog-content .post-tag:hover, .single-blog-post .blog-content .post-tag:focus {
color: #ff1662; }
/* Set font-size */
#media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-tag {
font-size: 10px; } }
.single-blog-post .blog-content .post-title {
font-weight: 600;
font-size: 30px;
display: block;
color: #282828;
margin-bottom: 10px; }
/* Align text */
#media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-title {
font-size: 16px; } }
.single-blog-post .blog-content .post-title:hover, .single-blog-post .blog-content .post-title:focus {
color: #ff1662; }
.single-blog-post .blog-content .post-meta {
display: -webkit-box;
display: -ms-flexbox;
display: flex; }
/* Set space between text elements*/
.single-blog-post .blog-content .post-meta a {
color: #ffffff;
margin-right: 15px;
font-size: 11px;
line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: end;
-ms-flex-align: end;
-ms-grid-row-align: flex-end;
align-items: flex-end; }
/* Set color and placement on text*/
#media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-meta a {
font-size: 8px;
margin-right: 5px; } }
.single-blog-post .blog-content .post-meta a img {
margin-right: 10px; }
.single-blog-post .blog-content .post-meta a:last-child {
margin-right: 0; }
.single-blog-post .blog-content .post-meta a:hover, .single-blog-post .blog-content .post-meta a:focus {
color: #ff1662; }
.single-blog-post.white .blog-content .post-title,
.single-blog-post.white .blog-content .post-tag,
.single-blog-post.white .blog-content .post-meta a {
color: #ffffff; }
.single-blog-post.white .blog-content .post-title:hover, .single-blog-post.white .blog-content .post-title:focus,
.single-blog-post.white .blog-content .post-tag:hover,
.single-blog-post.white .blog-content .post-tag:focus,
.single-blog-post.white .blog-content .post-meta a:hover,
.single-blog-post.white .blog-content .post-meta a:focus {
color: #008ebe; }
.single-blog-post.style2 .blog-content .post-title {
font-size: 24px; }
/* Sidebar Nyhedsbrev */
.sidebar-area {
position: relative;
z-index: 1; }
#media only screen and (min-width: 768px) and (max-width: 991px) {
.sidebar-area {
margin-top: 100px; } }
#media only screen and (max-width: 767px) {
.sidebar-area {
margin-top: 100px; } }
.single-widget-area {
position: relative;
z-index: 1; }
.single-widget-area.newsletter-widget {
background-color: #f0f4f8;
padding: 50px 20px;
text-align: center; }
.single-widget-area.newsletter-widget h4 {
margin-bottom: 25px; }
.single-widget-area.newsletter-widget form input {
text-align: center;
width: 100%;
background-color: #d4dfe3;
height: 54px;
font-size: 12px;
font-style: italic;
color: #4c4c4c;
border: none;
margin-bottom: 15px; }
.single-widget-area.newsletter-widget p {
font-size: 12px;
font-style: italic; }
.single-widget-area.news-widget h4 {
margin-bottom: 60px; }
</style>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<!-- ##### Hero Area Start ##### -->
<div class="hero-area d-flex flex-wrap">
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item1" style="background-image: url(http://vouzalis.dk/stack/1.jpg);">
<!-- Content -->
<i class="fa fa-play"></i>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
Featured
Watch a tiny cat taking a bath
<div class="post-meta">
Here is a text about the picture
</div>
<button href="#" class="btn btn-success btn-center">Read More</button>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item2" style="background-image: url(http://vouzalis.dk/stack/2.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
Featured
Spain: Take a virtual tour
<div class="post-meta">
Her er en tekst
</div>
</div>
</div>
</div>
</div>
<div class="hero-second-section d-flex flex-wrap">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item3" style="background-image: url(http://vouzalis.dk/stack/3.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post style2 white">
<div class="blog-content">
Featured
5 Tips to create your garden
</div>
</div>
</div>
</div>
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item4" style="background-image: url(http://vouzalis.dk/stack/4.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post style2 white">
<div class="blog-content">
Featured
10 Movies you need to see
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item5" style="background-image: url(http://vouzalis.dk/stack/1.jpg);">
<!-- Content -->
<i class="fa fa-play"></i>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
Featured
Watch a tiny cat taking a bath
<div class="post-meta">
Here is a text about the picture
</div>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item6" style="background-image: url(http://vouzalis.dk/stack/2.jpg);">
<!-- Content -->
<i class="fa fa-play"></i>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
Featured
Watch a tiny cat taking a bath
<div class="post-meta">
Here is a text about the picture
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ##### Hero Area end ##### -->
Percentages in width are not something I'd use. I'd wrap the last 2 elements into another div, make it flex and then add flex:1; to the first element and flex:2; to the second for this particular screen width.
This will also make the widths responsive. Bottom line is, avoid percentages, use flex: property with flexbox items.
.wrapper {
width: 100%;
min-height: 150px;
display: flex;
justify-content: center;
align-items: center;
}
.one {
min-height: 150px;
flex: 2;
background: red;
}
.two {
min-height: 150px;
flex: 1;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
</div>
You can solve this in bootstrap like this
.vh-100 {
height:100vh
}
.vh-50 {
height:50vh
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-6 bg-dark vh-100">
</div>
<div class="col-6 vh-100 bg-danger">
<div class="row">
<div class="col-6 vh-50 bg-primary">
</div>
<div class="col-6 vh-50 bg-warning">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-8 bg-success vh-100">
</div>
<div class="col-4 vh-100 bg-info">
</div>
</div>
Related
I have an example of a simple grid in which when the screen size is less than 767 pixels, all blocks stretch to fill the screen.
Section 2 moves to the very bottom when this size (767 pixels) is reached. And I have something like this: Section 1, footer, section 2. Is it possible to somehow make section 2 at the very top? (section 2, section 1, footer)
* {
box-sizing: border-box;
}
.wrapper {
max-width: 1200px;
width: 100%;
padding: 0 0px;
margin: 0 auto;
}
.leftcolumn {
float: left;
width: 65%;
}
.rightcolumn {
float: left;
width: 35%;
padding-left: 20px;
}
.row:after {
content: "";
display: table;
margin-top: 20px;
}
.footer {
padding: 20px;
text-align: center;
background: rgba(221, 221, 221, 0.3);
margin-top: 20px;
}
#media screen and (max-width: 767px) {
.leftcolumn, .rightcolumn {
width: 100%;
padding: 0;
}
}
<div class="wrapper">
<div class="row">
<div class="leftcolumn">
1 section
<div class="footer">
footer
</div>
</div>
<div class="rightcolumn">
2 section
</div>
</div>
</div>
Here is what I have now:
Here is what I want to get:
I did these changes in your code:
Use grid instead float. Then set grid-column and grid-row for grid items. Then change these for screen size smaller than 768px.
Note also I changed your HTML for this purpose:
* {
box-sizing: border-box;
}
.wrapper {
max-width: 1200px;
width: 100%;
padding: 0 0px;
margin: 0 auto;
}
.row {
display: grid;
grid-template-columns: 65% 35%;
}
.rightcolumn {
grid-column: 2 / 3;
padding-left: 20px;
}
.row:after {
content: "";
display: table;
margin-top: 20px;
}
.footer {
grid-row: 2 / 3;
padding: 20px;
text-align: center;
background: rgba(221, 221, 221, 0.3);
margin-top: 20px;
}
#media screen and (max-width: 767px) {
.row {
grid-template-columns: 100%;
}
.rightcolumn {
grid-row: 1 / 2;
grid-column: 1 / 2;
padding-left: 0;
}
.footer{
grid-row: 3 / 4;
}
}
<div class="wrapper">
<div class="row">
<div class="leftcolumn">
1 section
</div>
<div class="footer">
footer
</div>
<div class="rightcolumn">
2 section
</div>
</div>
</div>
You can simply do it by using flexbox and a little bit of change in your html code.
* {
box-sizing: border-box;
}
.wrapper {
max-width: 1200px;
width: 100%;
border: 2px solid blue;
padding: 0 0px;
margin: 0 auto;
}
.left {
width: 65%;
}
.rightcolumn {
width: 35%;
padding-left: 20px;
}
.row {
display: flex;
justify-content: space-between;
}
.footer {
padding: 20px;
width: 100%;
text-align: center;
background: rgba(221, 221, 221, 0.3);
margin-top: 20px;
}
#media screen and (max-width: 767px) {
.row {
flex-direction: column;
}
.left,
.rightcolumn {
width: 100%;
padding: 0;
}
.left {
order: 2;
}
.rightcolumn {
order: 1;
}
}
<div class="wrapper">
<div class="row">
<div class="left">
<div class="leftcolumn">
1 section
</div>
<div class="footer">
footer
</div>
</div>
<div class="rightcolumn">
2 section
</div>
</div>
</div>
You can set the width of .footer div according to your preference above 767 pixels, I have set it 100%;
I have a sidebar nav which collapses to make way for more content in a flex layout. When the user clicks to collapse the nav the content area div .ca expands to fill the space and the flex layout reflows using media queries.
See it in action here.
I have applied a CSS transition to each moving element but the .ca div jumps when the nav is opened and closed. This seems to be related to the widths of the units in the flex layout – .songgrid-unit.
The unit has a width value in px but the media queries set a min-width value in % to override this, so as to avoid large empty spaces between break points:
html:
<div class="navbar open ease">
<div class="nav-toggle">
<div class="nt-wrap">
<div class="nt-bar ease" id="ntb-top"></div>
<div class="nt-bar ease" id="ntb-bot"></div>
</div>
</div>
</div>
<div class="ca ease">
<div class="songgrid ease">
<div class="songgrid-unit ease">
<!-- post content -->
</div>
<div class="songgrid-unit ease">
<!-- post content -->
</div>
<div class="songgrid-unit ease">
<!-- post content -->
</div>
</div>
</div>
CSS:
.navbar {
position: fixed;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 214px;
height: 100vh;
left: 0;
top: 0;
box-sizing: border-box;
padding: 48px 8px 48px 32px;
background-color: #282828;
border-right: solid 1px #555;
z-index: 20;
}
.navbar.closed {
left: -214px;
}
.ca {
position: relative;
width: 100%;
padding: 48px 32px 48px 280px;
box-sizing: border-box; /*keep padding inside width*/
}
.ca.fullwidth {
width: 100%;
padding: 48px 32px 48px 64px;
}
.songgrid {
flex: 1;
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
}
.songgrid-unit {
width: 280px;
box-sizing: border-box;
padding: 0 16px 48px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
/*adjust no. of cols as per screen width in both container widths*/
#media only screen and (max-width: 623px) {
.ca.fullwidth .songgrid-unit {
min-width: 100%;
}
}
#media screen and (min-width: 624px) and (max-width: 904px) {
.songgrid-unit {
min-width: 100%;
}
.ca.fullwidth .songgrid-unit {
min-width: 50%;
}
}
#media screen and (min-width: 905px) and (max-width: 1184px) {
.songgrid-unit {
min-width: 50%;
}
.ca.fullwidth .songgrid-unit {
min-width: 33%;
}
}
#media screen and (min-width: 1185px) and (max-width: 1464px) {
.songgrid-unit {
min-width: 33%;
}
.ca.fullwidth .songgrid-unit {
min-width: 25%;
}
}
#media screen and (min-width: 1465px) and (max-width: 1744px) {
.songgrid-unit {
min-width: 25%;
}
.ca.fullwidth .songgrid-unit {
min-width: 20%;
}
}
#media only screen and (min-width: 1745px) and (max-width: 1949px) {
.songgrid-unit {
min-width: 20%;
}
.ca.fullwidth .songgrid-unit {
min-width: 16.66667%;
}
}
#media only screen and (min-width: 1950px) {
.songgrid-unit {
min-width: 16.66667%;
}
.ca.fullwidth .songgrid-unit {
min-width: 14.285%;
}
}
.ease {
transition: all 0.4s ease-in 0s;
-webkit-backface-visibility: hidden;
}
jQuery:
$(".nav-toggle").click(function(){
$(".navbar").toggleClass("open closed");
$(".ca").toggleClass("fullwidth");
});
If I remove the media queries the transitions work fine, but the min-width values are breaking the effect.
Why is this happening and how can I fix it? Thanks.
It's hard to tell because the code on the site you linked is a bit different from what you posted here. But it seems to me like the .ca div isn't actually jumping, it just looks like it is because as the items inside the grid change in size the number of items per row changes. The jump happens when the items either take up more space so that one fewer can fit in a row, or take up less space so one more can fit per row.
I played with the code you posted here a bit just to demonstrate what I think is happening. I hid the nav and added some outlines around the songgrid-container & individual songgrid items, and then I slowed down the transition a bit. So you can press the blue box and see what the transition looks like in slow motion. It looks like the widths are all transitioning fine, it just jumps when the layout inevitably changes.
Unfortunately I don't have a super easy solution to this, it's not really something you can control with a basic CSS transition. But maybe look at a library like this: https://isotope.metafizzy.co/
I don't actually think the media queries have anything to do with it, but I may also just be completely misunderstanding the effect you are seeing!
$(".nav-toggle").click(function(){
// $(".navbar").toggleClass("open closed");
$(".ca").toggleClass("fullwidth");
});
.navbar {
position: fixed;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 214px;
height: 100vh;
left: 0;
top: 0;
box-sizing: border-box;
padding: 48px 8px 48px 32px;
background-color: #282828;
border-right: solid 1px #555;
z-index: 20;
left: -214px;
}
.nav-toggle {
width: 50px;
height: 50px;
background-color: blue;
position: absolute;
right: -50px;
}
.navbar.closed {
left: -214px;
}
.ca {
position: relative;
width: 100%;
padding: 48px 32px 48px 280px;
background: lightblue;
box-sizing: border-box; /*keep padding inside width*/
}
.ca.fullwidth {
width: 100%;
padding: 48px 32px 48px 64px;
}
.songgrid {
flex: 1;
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
outline: 2px solid blue;
}
.songgrid-unit {
width: 280px;
box-sizing: border-box;
padding: 0 16px 48px;
display: flex;
flex-direction: column;
justify-content: space-between;
background: rgba(255,255,255,.5);
outline: 2px solid gray;
}
/*adjust no. of cols as per screen width in both container widths*/
#media only screen and (max-width: 623px) {
.ca.fullwidth .songgrid-unit {
min-width: 100%;
}
}
#media screen and (min-width: 624px) and (max-width: 904px) {
.songgrid-unit {
min-width: 100%;
}
.ca.fullwidth .songgrid-unit {
min-width: 50%;
}
}
#media screen and (min-width: 905px) and (max-width: 1184px) {
.songgrid-unit {
min-width: 50%;
}
.ca.fullwidth .songgrid-unit {
min-width: 33%;
}
}
#media screen and (min-width: 1185px) and (max-width: 1464px) {
.songgrid-unit {
min-width: 33%;
}
.ca.fullwidth .songgrid-unit {
min-width: 25%;
}
}
#media screen and (min-width: 1465px) and (max-width: 1744px) {
.songgrid-unit {
min-width: 25%;
}
.ca.fullwidth .songgrid-unit {
min-width: 20%;
}
}
#media only screen and (min-width: 1745px) and (max-width: 1949px) {
.songgrid-unit {
min-width: 20%;
}
.ca.fullwidth .songgrid-unit {
min-width: 16.66667%;
}
}
#media only screen and (min-width: 1950px) {
.songgrid-unit {
min-width: 16.66667%;
}
.ca.fullwidth .songgrid-unit {
min-width: 14.285%;
}
}
.ease {
transition: all 3s ease-in 0s;
-webkit-backface-visibility: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<div class="navbar open ease">
<div class="nav-toggle">
click
</div>
</div>
<div class="ca ease">
<div class="songgrid ease">
<div class="songgrid-unit ease">
content
</div>
<div class="songgrid-unit ease">
content
</div>
<div class="songgrid-unit ease">
content
</div>
</div>
</div>
</body>
</html>
With some help getting onto the right path from the reply from #sparrow here I've found that the transitions can be rendered much smoother by applying further flex properties to the items creating the columns in the grid.
Updating the CSS for the .songgrid-unit class as follows fixes the issue:
.songgrid-unit {
width: 280px;
box-sizing: border-box;
padding: 0 16px 48px;
display: flex;
flex-grow: 1; /*new line*/
flex-shrink: 1; /*new line*/
flex-basis: auto; /*new line*/
flex-direction: column;
justify-content: space-between;
}
With thanks to #sparrow and the authors over at this thread.
I have a problem with my media queries as it is not overriding each other. The first iteration (max-width: 960px) works fine but the second one (max-width: 380px) does not work and I do not know why. Help is appreciated, thanks.
.fb {
width: 50px;
margin-left: 20px;
margin-right: 20px;
}
#media only screen and (max-width: 960px) {
/* this works */
.fb {
position: relative;
width: 40px!important;
margin-left: 15px!important;
margin-right: 15px!important;
}
}
#media only screen and (max-width: 380px) {
/* this does not work */
.fb {
width: 30px!important;
margin-left: 10px!important;
margin-right: 10px!important;
}
}
<div class="social_container">
<img class="fb" src= "http://placekitten.com/200/300" alt="">
</div>
you are wrongly spelled margin-rigth please change it to margin-right and remove !important
.fb {
width: 50px;
margin-left: 20px;
margin-right: 20px;
}
#media only screen and (max-width: 960px) {
.fb {
position: relative;
width: 40px;
margin-left: 15px;
margin-right: 15px;
}
}
#media only screen and (max-width: 380px) {
.fb {
width: 30px;
margin-left: 10px;
margin-right: 10px;
}
}
<div class="social_container">
<a href="https://www.facebook.com/" target="_blank">
<img class="fb" src="https://i.stack.imgur.com/UzPkq.jpg" alt="">
</a>
</div>
see fiddle
.social_container a {
color: red;
}
#media only screen and (max-width: 960px) {
.social_container a{
color: green;
}
}
#media only screen and (max-width: 380px) {
.social_container a{
color: pink;
}
}
<div class="social_container">
fb
</div>
I'm stuck on problem with stretching flexes.
I have flexbox div with items. These items can stretch to full width and have min-width property, so that 3-4 elements can fit in large screens, and 1-2 in small.
I want to make their widths equal, but the problem is that wrapped items are wider if their quantity is less than on top elements.
Attached below my current result and expected behavior. How can I make it?
.items {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100%;
}
.item {
min-width: 400px;
border: 1px solid black;
margin: 0;
height: 200px;
flex-grow: 1;
}
<div class="items">
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
</div>
Thanks!
Update 02.05.2016
Thanks to #vals I came up with percentage width solution for different screen sizes. (But it seems I'm having some tiny problem with 33% width elements, in which 1% empty space is left around them xD)
.items {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100%;
box-sizing: border-box;
align-items: center;
}
#media only screen and (max-width: 820px) {
.item {
width: 100%;
}
}
#media only screen and (min-width: 821px) and (max-width: 1220px) {
.item {
width: 50%;
}
}
#media only screen and (min-width: 1221px) and (max-width: 1620px) {
.item {
width: 33%;
}
}
#media only screen and (min-width: 1621px) and (max-width: 2020px) {
.item {
width: 25%;
}
}
.item {
box-sizing: border-box;
border: 1px solid black;
margin: 0;
height: 200px;
}
<div class="items">
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
</div>
This is a complex case, you need media queries adapted to you specific layout and number of elements present.
I have color-coded the different media queries result to help identify them
And also, three extra divs inside the items element to help with the dimensions
.items {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100%;
}
.item {
min-width: 400px;
border: 1px solid black;
margin: 0;
height: 100px;
flex-grow: 2;
}
.filler1, .filler2, .filler3 {
height: 0px;
background-color: lightgreen;
}
#media only screen and (max-width: 820px) {
/* one item per line */
.filler2, .filler3 {display: none;}
.item {background-color: yellow;}
}
#media only screen and (min-width: 821px) and (max-width: 1220px) {
/* 2 items per line */
.item:nth-last-child(4) {
order: 9;
background-color: red;
}
.filler1 {
margin-right: 100%;
}
.filler2 {
min-width: 200px;
flex-grow: 1;
order: 4;
}
.filler3 {
min-width: 200px;
flex-grow: 1;
order: 14;
}
}
#media only screen and (min-width: 1221px) and (max-width: 1620px) {
.item:nth-last-child(4), .item:nth-last-child(5) {
order: 9;
background-color: green;
}
.filler1 {
margin-right: 100%;
}
.filler2 {
min-width: 200px;
flex-grow: 1;
order: 4;
}
.filler3 {
min-width: 200px;
flex-grow: 1;
order: 14;
}
}
#media only screen and (min-width: 1621px) and (max-width: 2020px) {
.item:nth-last-child(4) {
order: 9;
background-color: lightblue;
}
.filler1 {
margin-right: 100%;
}
.filler2 {
min-width: 400px;
flex-grow: 2;
order: 4;
}
.filler3 {
min-width: 400px;
flex-grow: 2;
order: 14;
}
}
<div class="items">
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
<div class="filler1"></div>
<div class="filler2"></div>
<div class="filler3"></div>
</div>
I am working on a site and I have two images that need to be inline when device width is more than 425px (min-width: 425px) but for some reason it does not seem to be working how it should be and my css with the #media but it doesn't work for some reason although it is fairly basic
CODE
.info-img {
width: 49.75%;
}
.info-images {
display: inline-block;
text-align: center;
}
#media screen and only (max-width: 425px) {
.info-img {
width: 100%;
padding-bottom: 1px;
}
.info-images {
display: block;
text-align: center;
}
}
<div class="info-images">
<img src="https://dl.dropboxusercontent.com/s/dd5exdwwpa13yxnthg/unspecified-4.jpeg?dl=0" class="info-img">
<img src="https://dl.dropboxusercontent.com/s/fo3bt6ruhx4qppztho/unspecified-6.jpeg?dl=0" class="info-img">
</div>
</div>
<style type="text/css">
#import url('https://dl.dropboxusercontent.com/s/ikcsorhvohzdipo/information.css?dl=0');
</style>
The problem is because you are giving inline-block to parent instead of img, plus you are writing your media wrongly (its not #media screen and only, but #media only screen and).
Snippet
.info-images {
font-size: 0;
/* fix inline-block gap */
}
.info-img {
width: 50%;
display: inline-block;
vertical-align:top; /* may be necessary */
box-sizing: border-box;
padding: 0 1%
}
#media only screen and (max-width: 425px) {
.info-img {
width: 100%;
padding-bottom: 1px;
}
.info-images {
display: block;
text-align: center;
}
}
<div class="info-images">
<img src="//lorempixel.com/1600/900" class="info-img">
<img src="//lorempixel.com/1600/900" class="info-img">
</div>