Problem with responsive design using #media only screen - css

I have a problem with understanding how #media only screen works. I have three screen sizes:
1) #media only screen and (max-width: 640px)
2) #media only screen and (min-width: 640px) and (max-width: 1250px)
3) #media only screen and (min-width: 1250px)
I want to make that one element would be shown only on large screen size (3), so I wrote:
display: none on 1) and 2) screens and display: block on 3) screen.
I also have three style files for each screen size which are put into the main file like this:
#import "large-screen";
#import "medium-screen";
#import "small-screen";
And the small-screen size file overwrites the others:
I don't understand how it can overwrite if it's set to #media only screen and (max-width: 640px), doesn't max-width 640px mean that this code will work when screen is smaller than 640px? Can someone explain me how this work and how I should write that my element would be displayed only on large screen. Thank you!

Related

Media Query breakpoints pixel specification

I am really confused as to what the Media Query breakpoints should be. The way I am use to doing it is having one pixel less than the next break point, for instance
#media screen and (max-width: 749px) {} //Mobile design CSS applies to everything until 74ppx
#media screen and (min-width: 750px) and (max-width: 969px) {}
etc.
But some people use the exact values such as
#media screen and (max-width: 750px) {}
#media screen and (min-width: 750px) and (max-width: 970px) {}
Wouldn't the second approach break it? My understanding is the first approach is the way to go.
And what about if you do something such as
#media screen and (max-width: 750px) {}
#media screen and (max-width: 970px) {}
And I want all the mobile designs to apply to 750, but at 750 is where the tablet view starts. Same for 970. In this case would having it also one pixel less be correct? I.e max-width: 749 and max-width: 969
Yes, the first one is correct. In the second one, if the screens is exactly 750px wide, both media query sections will apply, which can cause problems.
Concerning your addition:
#media screen and (max-width: 750px) {}
#media screen and (max-width: 970px) {}
In this case the rules in the second query will overwrite those with identical CSS selectors in the first one, which will probably also cause problems.
The usual way would either be the other way round (desktop first approach), or using a mobile-first approach where you first state the general rules for mobile sizes, and then add media queries for larger sizes which overwrite the general rules. That would for example be
#media screen and (min-width: 720px) {}
#media screen and (min-width: 1280px) {}

FIX #media Queries / #media code for each individual screen size

Website issue to fix:
I’m trying to figure out why some of my #media queries are overlapping. If you look at my code you can see the #media queries are labeled for each device dimension.
#media SCREEN SIZE: MASSIVE
#media SCREEN SIZE: LARGE
#media SCREEN SIZE: MEDIUM
#media SCREEN SIZE: IPAD
#media SCREEN SIZE: SMALL TABLET
The goal is to be able to change font sizes and image sizes for each unique #media / SCREEN SIZE.
Problem: For some reason when I make changes to the image sizes or text sizes on “SCREEN SIZE: MEDIUM” it also apply’s the changes to all the other #media larger screen sizes.
However, I am able to individually change the header background “#header {background:url(../img/super” for each individual #media code just fine without it erroneously changing the background on all the #media / SCREEN SIZE’s.
How can I get the css #media codes to be completely unique to it’s own #media / SCREEN SIZE without affecting the other #media / SCREEN SIZE’s?
And how can I add the final #media for the small phone size (Website currently shows all messed up on a small phone size)?
Let me know the answer. Your all the best!
If you need non-overlapping breakpoints you will have to do something like this
/*Small*/
#media (max-width: 499px) { ... }
/*Medium*/
#media (min-width: 500px) and (max-width: 999px) { ... }
/*Big*/
#media (min-width: 1000px) and (max-width: 1499px) { ... }
/*Large*/
#media (min-width: 1500px) { ... }

CSS Media Query is affecting other queries also

Below are the media queries i have figured out and i will use as default for every project that i will do.
#media only screen and (min-width : 320px) {}
#media only screen and (min-width : 480px) {}
#media only screen and (min-width : 768px) {}
#media only screen and (min-width : 992px) {}
#media only screen and (min-width : 1200px) {}
Now, the problem i am facing with them is that when i try to change something on 768 it gets changed on 320 also. I want to change for example logo if i hide it on 768 it should only be invisible on 768 only, whereas in this case i have to manually go on each and every query and make it visible.
I have tried min-width also and max-width also.
And min-width for mobile size and max-width for big sizes but with no luck.
And if i use fixed queries then also i have to write code for every query.
So, how do i make it work only for single size and does not affect the others, and most importantly not to write code for every size.
#media screen and (min-width: 480px) and (max-width: 767px) {
// applied only between 767 px and 480px
}
It will, To avoid that you need to write specific for all the resolutions below to that. For example: If you are hiding logo in 768 then it affects 480, 320,. To get rid of that you need to write in 480, that the specific logo to be visible, so that it will be reflected in 320 too.
/* #### CSS that's applied when the viewing area's width is 768px or less #### */
#media screen and (max-width: 768px){
div#logo{
display: none;
}
}
For logo to be visible in 480 and 320 try like this:
#media screen and (max-width: 480){
div#logo{
display: none;
}
}
For more info, Reference link

Two #media variables, issue

I have two #media variables in my css thats cause a problem.
One is with smaller width #media only screen and (min-width: 1290px).
And the second one is with greater width #media only screen and (min-width: 1610px), allowing me to display more content.
Now, with my browser window in full screen, and a monitor resolution of 1680 x 1050 pixels, I still cannot get #media only screen and (min-width: 1610px) to appear.
Am I missing something?
Thanks.
Try setting the max-width also for your first condition, as currently both your "min-widths" will be hit when the resolution is > 1610px.
#media only screen and (max-width: 1609px) and (min-width: 1290px){
}

1140 CSS Grid not working on ipad

I have used 1140px CSS Grid (cssgrid.net) to code this page: http://workaday.org/dev/static/
It's restructuring all content on 750px width instead of 767px, as a result it's not working on iPad.
Can someone please suggest what i have done wrong in this?
Update:
I changed max-width to 784px, and now it's working on 767px, there is a difference of 17px. But i am not able to find reason for this so far.
You have
#media handheld, only screen and (max-width: 767px)
That is not logic to me. so you can try with variations
#media only handheld and (max-width: 767px)
or
#media handheld and (max-width: 767px)
I don't have iPad, so I can't test it.

Resources