I made the media queries for tablet , but i can't seem to make them work for mobile.
Tablet
#media(min-width:768px) and (max-width:1024px)
Mobile
#media (min-width:480px) and (max-width:767px)
In the mobile queries when I write some changes they don't work.
You need to make sure you handle all dimensions. The way you have it now you are ignoring any sizes smaller than 480px. Please see below for some basic media sizes.
/* XL */
#media (min-width: 1200px) {
/* style */
}
/* Large */
#media (min-width: 768px) and (max-width: 979px) {
/* style */
}
/* Medium */
#media (max-width: 767px) {
/* style */
}
/* Small */
#media (max-width: 480px) {
/* style */
}
Related
I am looking to find a way to create a sass function that alters the color of my font from white (on desktop) to black (on tablet and mobile). The reason being is that I am overlaying text on a video on desktop, but then on mobile the overlayed text switches to blocked text placed underneath the video, so the font color needs to change to black at that time.
I am relatively new to sass, but so far have tried this as a mixin (that did not work)
** I know this can be done with css but am looking to make this a bit more dynamic and reusable **
$color-media-sizes: (
"max1024": #000 or #fff,
null: #000 or #fff
);
with this function
#function color($mobile-color, $desktop-color){
#return ($mobile-color $desktop-color)
}
I don't think you really need to use SASS for this, CSS will do the trick.
Just put media queries and colors based on your device screen
(Source : https://gist.github.com/gokulkrishh/242e68d1ee94ad05f488)
Read this doc, it'll help you to understand media queries : https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
#media (min-width: 1281px) {
/* CSS */
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
#media (min-width: 1025px) and (max-width: 1280px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) {
/* CSS */
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
/* CSS */
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
#media (min-width: 481px) and (max-width: 767px) {
/* CSS */
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
#media (min-width: 320px) and (max-width: 480px) {
/* CSS */
}
Mixin in SASS is like to create a "template" of a component. E.g. : A button
#mixin button($text, $background) {
background: $background;
border-radius: 10px;
color: $text;
padding: 0 15px;
text-decoration: none;
text-transform: uppercase;
}
// Then you can call it this way :
.success-button {
#include button("#FFF", "#0F0");
}
.error-button {
#include button("#FFF", "#F00");
}
Hope I could help
Maybe you can do that using just css media queries :
#media screen and (min-width: 980px) {
body {
color: red;
}
}
#media screen and (max-width: 979px) {
body {
color: blue;
}
}
#media screen and (max-width: 500px) {
body {
color: green;
}
}
I created a website that is mostly responsive, but it needed a little help when viewed on smaller screens. I tried to add an #media query to the css page, but it doesn't seem to be making any difference.
I only added different style rules in my main css page, and did not add anything to my html. I am confused on how media queries work exactly, so maybe that's my problem?
Here is my css
/*Alt styles for smaller screens*/
#media only screen and (max-width: 780px) {
div.price-area1 {
width: 100%;
text-align: center;
}
div.price-area2 {
width: 100%;
text-align: center;
}
div.price-area3 {
width: 100%;
}
input.submit {
width: 60%;
margin-left: 20%;
}
nav {
width: 100%;
}
nav ul li {
position: relative;
float: left;
width: 50%;
font-family: 'Poiret One', cursive;
margin-bottom: 15px;
text-align: center;
font-size: 24px;
}
}
The easiest way to understand media queries is to read about it here and here:
With that said, you may want to use a framework such as bootstrap which is a great way to start a site. Otherwise you can use this template for media queries:
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media only screen and (-webkit-min-device-pixel-ratio:1.5), only screen and (min-device-pixel-ratio:1.5) {
/* Styles */
}
This is a good starting point if you want to do it all yourself.
Can anybody tell me why exactly this works
/* small desktop */
#media all and (max-width: 1200px) {
}
/* tablet */
#media all and (max-width: 1024px) {
}
/* mobile phone */
#media all and (max-width: 768px) {
}
but this not:
/* mobile phone */
#media all and (max-width: 768px) {
}
/* tablet */
#media all and (max-width: 1024px) {
}
/* small desktop */
#media all and (max-width: 1200px) {
}
since the last style always overwrite the previous style like :
[class=foo]{
background:red;
background:yellow;
}
output:
.foo background yellow
Simply: stylesheets cascade, so if the condition is true, it will override any previous. Your second example is a mobile-first approach, so you would need to use min-width.
/* mobile phone */
#media all and (min-width: 768px) {
}
/* tablet */
#media all and (min-width: 1024px) {
}
/* small desktop */
#media all and (min-width: 1200px) {
}
I am using some media queries for responsive versions, but with the smallest screen media query it breaks the whole code.
This is the structure of my media query!
/* Landscape phone to portrait tablet */*1
#media (min-width: 480px) and (max-width: 767px) {
/* All Smartphones in portrait and landscape ----------- */*2
#media only screen and (min-width: 321px) and (max-width: 479px) {
/* Styles */
/***** For HTC Mobile *******/*3
#media only screen and (min-width: 0px) and (max-width: 320px) {
With the above structure, the 3rd one media query isn't good at all.
I wrote following code in my style sheet with 3rd one media query.
/***** For HTC Mobile *******/*3
#media only screen and (min-width: 0px) and (max-width: 320px) {
.module-title {
font-size: 25px !important;
line-height: 25px;
}
}
And this code is making title of all versions into font-size 25.
Why is this not specific only for small screens and why it's taking effect on all versions?
And also, should I use "!important" on all versions for all classes?
like:
/* Landscape phone to portrait tablet */*1
#media (min-width: 480px) and (max-width: 767px) {
.module-title: 30px !important;
}
}
/* All Smartphones in portrait and landscape ----------- */*2
#media only screen and (min-width: 321px) and (max-width: 479px) {
/* Styles */
.module-title: 27px !important;
}
}
/***** For HTC Mobile *******/*3
#media only screen and (min-width: 0px) and (max-width: 320px) {
.module-title: 30px !important;
}
}
Any idea?
Remove the !important from the non-responsive class. and make sure you're closing media queries properly.
Example:
#media (max-width: 300px {
/*styles goes here*/
.tag {
} This is tag closing
} this is query closing
This syntax is very wrong:
/* Landscape phone to portrait tablet */*1
#media only screen and (min-width: 321px) and (max-width: 479px) {
/* Styles */
.module-title: 27px !important;
}
}
...because you can't just give a property to a selector!
The *1 after the comment above the code is outside the comment.
So the problem is that and the double braces. The !important below would only break other query if any of the conditions were met in other media-queries (only screen, min-width: 321px or max-width: 479).
#media only screen and (min-width: 321px) and (max-width: 479px) {
.module-title { font-size: 27px !important; }
}
It would not influence the media-query below, for instance:
#media only print and (min-width: 480px) {
.module-title { font-size: 27px; }
}
The syntax above would be the correct one.
/* 1024 and above desktop ------ */
#media only screen
and (min-width: 1008px){
/* Styles */
.outerBox{
width: 796px;
}
#media only screen
and (min-width: 600px)
and (max-width: 640px){
/* Styles */
.outerBox{
width: 600px;
}
}
The queries above doesn't seem to work properly when applied together..as only the first one works when both applied and if I remove the first one the second one works fine..
Your first rule is missing the closing }:
/* 1024 and above desktop ------ */
#media only screen
and (min-width: 1008px){
/* Styles */
.outerBox{
width: 796px;
}
}