I use mobile first principle for my sass (css), but I found quite a pattern which is quite disturbing.
.innerWrap {
display: flex;
align-items: center;
&:first-child {
margin-right: 20px;
#media only screen and (min-width: 640px) {
margin-right: 0;
}
}
#media only screen and (min-width: 640px) {
flex: 1;
}
}
Imagine there will be more screen size, there will be
#media only screen and (min-width: 1200px)
#media only screen and (min-width: 1200px)
#media only screen and (min-width: 1200px)
everywhere, how to solve this?
You can also set a map with all you breakpoints (you can call them as you want) and use it in a mixin.
// your variables.scss file
$breakpoints:(
sm: 640px,
md: 1200px,
lg: 1400px,
xl: 1900px
);
// your mixins.scss file
#mixin min-width($breakpoint){
#media only screen and (min-width:#{map-get($breakpoints, $breakpoint)}) {
#content;
}
}
// your module.scss file
.innerWrap {
display: flex;
align-items: center;
&:first-child {
margin-right: 20px;
#include min-width(sm){
margin-right: 0;
}
}
#include min-width(sm){
flex: 1;
}
}
you can use #mixin to manage it
https://jsfiddle.net/wyd6pxnh/2/
#mixin mediaQuery($point) {
$mq-device1: "(min-width: 640px)";
$mq-device2: "(min-width: 1200px)";
#if $point=="device1" {
#media #{$mq-device1} {
#content;
}
}
#else if $point=="device2" {
#media #{$mq-device2} {
#content;
}
}
}
.innerWrap {
display: flex;
align-items: center;
&:first-child {
margin-right: 20px;
#include mediaQuery('device1') {
margin-right: 0;
}
}
#include mediaQuery('device1') {
flex: 1;
}
}
Output
.innerWrap {
display: flex;
align-items: center;
}
.innerWrap:first-child {
margin-right: 20px;
}
#media (min-width: 640px) {
.innerWrap:first-child {
margin-right: 0;
}
}
#media (min-width: 640px) {
.innerWrap {
flex: 1;
}
}
Related
HTML
<div class="container">
<div class="photos" id="box">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
<img src="image4.jpg">
</div>
</div>
CSS
.container {
max-width: 1280px;
margin: 0 auto;
}
.photos {
display: flex;
background-color: #000;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-content: stretch;
padding: 0;
max-width: 1280px;
}
.photos img {
display: block;
float: left;
flex: 0 0 auto;
background-color: #fff;
width: calc(25%-120px);
/*
box-sizing: border-box;
border-right: 40px solid #FFFFFF;
*/
}
#media screen and (min-width: 1024px) {
.photos img {
width: calc(100%/4);
height: calc(100%/4);
}
}
#media screen and (min-width: 769px) and (max-width: 1024px) {
.photos img {
width: calc(100%/4);
height: calc(100%/4);
}
}
#media screen and (min-width: 481px) and (max-width: 768px) {
.photos img {
width: calc(100%/2);
height: calc(100%/2);
}
}
#media screen and (min-width: 321px) and (max-width: 480px) {
.photos img {
width: calc(100%/2);
height: calc(100%/2);
}
}
#media screen and (max-width: 320px) {
.photos img {
width: 100%;
height: 100%;
}
}
How can I place a row of 4 square images that reduce into 2 rows of 2 square images using flexbox, with 40px between everything including the sides
Unable to get a 40px gap between images, messes with calc grid, not sure on how to easily create a grid with 40px gap between everything (including by the edges of the page)
I am learning HTML & CSS from a video step-by-step. In the beginning, we should make a header.
But I don't why the code is not working the same.
The problem is the header must be full width but in my case, it's not. It only became full width when I remove "max-width: 100%" from the .col class
here is my code:
/* app.css */
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.body {
font-family: "Nunito Regulsr";
}
.content {
background-color: yellow;
width: 100%;
height: 100px;
}
/* grid.css */
.container {
width: 100%;
margin-left: auto;
margin-right: auto;
padding: 0 15px;
}
#media only screen and (min-width: 576px) {
.container {
max-width: 576px;
}
}
#media only screen and (min-width: 768px) {
.container {
max-width: 768px;
}
}
#media only screen and (min-width: 992px) {
.container {
max-width: 992px;
}
}
#media only screen and (min-width: 1200px) {
.container {
max-width: 1400px;
}
}
.row {
display: flex;
flex-wrap: wrap;
}
.col {
max-width: 100% flex-grow: 1;
}
<div class="container">
<div class="row">
<div class="col">
<div class="content">text</div>
</div>
</div>
</div>
I've setup these breakpoints
X-Small devices (portrait phones, less than 576px)
#media (max-width: 576px) {
body {
background-color: red;
}
}
Small devices (landscape phones, less than 768px)
#media (max-width: 768px) {
body {
background-color: blue;
}
}
Medium devices (tablets, less than 992px)
#media (max-width: 992px) {
body {
background-color: green;
}
}
Large devices (desktops, less than 1200px)
#media (max-width: 1200px) {
body {
background-color: purple;
}
}
X-Large devices (large desktops, less than 1400px)
#media (max-width: 1400px) {
body {
background-color: yellow;
}
}
Why if I try to resize the screen the colour is always yellow and doesn't change according with the breakpoints?
Because max-width: 1400px is also true for smaller screens. Either place the larger screens at top so that the queires for smaller screens overwrite the value or use #media (min-width: value) and (max-width: value) { ... }
Starting with the largest to the smallest screen:
#media (max-width: 1400px) {
body {
background-color: yellow;
}
}
#media (max-width: 1200px) {
body {
background-color: purple;
}
}
#media (max-width: 992px) {
body {
background-color: green;
}
}
#media (max-width: 768px) {
body {
background-color: blue;
}
}
#media (max-width: 576px) {
body {
background-color: red;
}
}
Using the and-keyword:
#media (max-width: 576px) {
body {
background-color: red;
}
}
#media (min-width: 577px)
and (max-width: 768px) {
body {
background-color: blue;
}
}
#media (min-width: 769px)
and (max-width: 992px) {
body {
background-color: green;
}
}
#media (min-width: 993px)
and (max-width: 1200px) {
body {
background-color: purple;
}
}
#media (min-width: 1201px)
and (max-width: 1400px) {
body {
background-color: yellow;
}
}
I'm trying to hide the navigation bar and display another thing in it place when the resolution is low and for small screens (mobile)
I did manage to hide the navigation bar but the the other thing won't display.
#media only screen and (max-device-width: 500px) {
.small-menu {
display: block;
}
.regular-menu {
display: none;
}
}
#media only screen and (max-width: 1279px) {
.small-menu {
display: block;
}
.regular-menu {
display: none;
}
}
.small-menu {
display: none;
}
.regular-menu {
display: block;
}
Write your css this seqvence
write to your hole page css
write to your css max-width 1279
write to your css max-device-width 500
.small-menu {
display: none;
}
.regular-menu {
display: block;
}
#media only screen and (max-width: 1279px) {
.small-menu {
display: block;
}
.regular-menu {
display: none;
}
}
#media only screen and (max-device-width: 500px) {
.small-menu {
display: block;
}
.regular-menu {
display: none;
}
}
<div class="samll-menu">This is small menu</div>
<div class="regular-menu">This is regular-menu</div>
I am trying to make users comments responsive on my website, so that at full width three show,at tablet size two and mobile one. I have attached the link to the website so you can get more of an idea of what i mean: http://www.bfi-film-festival.com/movie.php?id=269
.cmt {
float: left;
width: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
margin: 15px 0;
}
.cmt_inr {
width: 100% !important;
float: left;
margin: 2%;
min-height: 100px;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-box-flex: 1;
flex: 1;
position: relative;
padding-bottom: 80px;
}
#media only screen and (max-width: 480px)
.cmt_inr {
width: 100%;
}
#media only screen and (max-width: 768px)
.cmt_inr {
width: 50%;
}
The # media screens i am using don't seem to work and i have no idea why.
the "{}" are missing for the #media-tag
#media screen and (max-width: 768px) "{"
"}"
Try this to see a result:
#media screen and (max-width: 768px) {
.cmt_inr {
background-color: red;
width: 50%;
}
}
#media screen and (max-width: 480px) {
.cmt_inr {
background-color: blue;
width: 20%;
}
}
The "!important" would override the witdth so try to avoid it or set the !important for the widths in the #media-tag too.