I have another question about organizing my CSS and media queries…
In this video that @chrisofarabia turned me on to, the speaker talks about not making the browser yo-yo all over the place as it tries to find the right style.
Sounds like a good idea, but now that my Home Page is finally coded and working, I am starting to see that I have no clue of how to organize my code like this speaker was talking about.
It is a no-brainer to put things like resets and generic things like p{padding: 0 0 1em 0;} at the top of your style sheet, but for everything I have some serious questions.
Question #1:
Is it correct that you should structure your CSS so that the browser skips styles unless they apply? (Almost like how you use an IF-THEN-ELSE in programming?)
If so, how do you do this? And can it be done without using media queries?
Question #2:
If a person is coding “mobile-first”, then technically you should be writing “outlier” styles like for 320px first. Is that really how it goes?
I wrote my styles based on what I see on my MacBook which is 1280x800. Everything from there is an exception.
It seems like it is a more reasonable approach to code for the more common screen-sizes (e.g. 1280px) and then go from there. But doing so kind of invalidates “mobile-first”, right?
(I really hope going from the most common denominator is okay, because otherwise most of my CSS that I have spent the last week or two on is all mixed up?!)
Question #3:
In my masthead, I have things coded like this…
/* companyInfo (Mobile) */
@media screen and (max-width: 700px){
}
@media screen and (max-width: 500px){
}
@media screen and (max-width: 425px){
}
The first media query applies to everything under 700px, but the 2nd and 3rd media queries are mutually exclusive.
What is the best way to code this so the browser isn’t looking for styles that won’t apply?
Would this be better…
/* companyInfo (Mobile) */
@media screen and (max-width: 700px){
}
@media screen and (min-width: 0px) and (max-width: 425px){
}
@media screen and (min-width: 426px) and (max-width: 500px){
}
(That would tell the browser to always read the first media query, but to selectively choose either the 2nd or 3rd media query - or skip them both - without unnecessarily reading more than it needs, right?)
All of this might seem nit-picky, but I am trying to learn the best way to structure my CSS and media queries so I don’t have issue down the road.
I also want to make sure my CSS runs as quickly as possible for performance reasons.
So what do you think about my questions and this topic in general?
Have I created a CSS disaster not asking these questions early on?