Media Query rule combination
So far we treated every media rule as stand alone independent. There are many scenarios where we will want to define a rule based on a match of a few filters. In this lecture we will learn to create more advanced media rules with the help of %u201Cand%u201D.
Keynotes:
- Media Queries as connectable items.
- The 'and' operator.
- Teaser to the next step : expressions
properties:
media queries, HTML4, CSS2.1, print, screen, and, expressionsVideo Transcript
00:00We are nearing the end of this chapter and actually this is the last lecture in it.
00:07And what are we going to be talking about?
00:09Our main topic is going to be media query rule combination.
00:13Now what does that mean?
00:15So far all of our media queries were basically one media query per CSS or per rule.
00:21But really that's not the case, media queries could be connectable items.
00:26And we could do more things with media queries and really this is just the gateway into
00:29the next chapter which is going to be the heart of media queries where we create responsive
00:34designs.
00:36The end operator is going to be that glue that we're going to be used to connect different
00:40elements.
00:41Really not very functional at this stage but in the next chapter it will be for example
00:46in a scenario where you want to have a site only if it's in a screen and only if it has
00:53more than 800 pixels on the screen.
00:55Only in that case let's use a specific media query.
00:59The not operator enables us to negate a rule and we're going to see that in action as we
01:05take a look at the only operator that its main usage is to help us create better browser
01:11compatibility.
01:12The not, the only is really a keyword that doesn't do anything besides help us create
01:18a site that has better compatibility that works with older browsers and we're going
01:22to see it and how it works in this lecture.
01:24As we wrap up this conversation really the main goal of this lecture is kind of like
01:28a prep and get ready set for the next chapter where we dive deep into expressions.
01:35So let's jump right into this last lecture of the chapter as we prepare ourselves to
01:39start creating responsive designs.
01:42We are practically in the end of this chapter and in this chapter we've were introduced to
01:47media queries in general and seen them in action already mainly through how to create modifications
01:53and customizations based on the type of the media.
01:56But obviously media, media queries have a lot more powers and a lot more capabilities
02:02beyond that.
02:04So I want us to take us to tease into the next step as we talk about connecting different
02:09rules together and although right now we only know about the type rule, right?
02:16We only know the type of screen itself and let me just delete that because that's
02:19part of our next topic.
02:22In general older browsers did not support the media type at all.
02:25So it ignored it in general but once you go into CSS rules and you define for example
02:31a media type here by the way in general by default well the browser is going to ignore
02:36it because it doesn't know what this is.
02:38So everything inside of this is just literally going to be completely ignored.
02:42Now the next step in this is to be able to connect and say I want to create these
02:47specifications to more than one thing for example print and screen.
02:54Notice how I'm putting here a space in between each value and another thing that I usually
02:59will need to do in the second parameter is wrap it around in a round bracket.
03:06Now in this case I don't really need to because it's not an expression and we're
03:09going to see expressions in the next chapter.
03:12So in this case if I save print and screen what that actually means is that this will
03:17work only if it's both a print and a screen which basically means it would never happen.
03:25So let me just to showcase this and make this very clear.
03:27Let me just go ahead here and in my index here I'm going to go instead of just having
03:32your media screen I'm going to write here print and screen.
03:35So that's the first derivative the first connector word that we know and are meeting
03:39right now.
03:40The end what we'll do is basically say if it's both this and that and in other words
03:45because it's not it's not going to render our CSS at all because there is no scenario
03:51where both our CSS will be our that our device will both be a print device and a screen device
03:59so this combination is just not humanly possible.
04:02There's definitely a combination that's possible such as hand held and screen or hand held
04:08and print if the user is trying to print from a handheld device.
04:12So these are combinations are not very common so we're not going to talk about them too
04:15much right now but we're going to see this and in action once we move into properties
04:21really.
04:22Now beyond the screen property the next property that we might want to look at is some older
04:28devices had the control of being able to define a media type but they did not have the capability
04:34of knowing what happens afterwards so older devices that supported the media type would
04:39automatically fetch that first item and truncate all the rest so it basically would ignore everything
04:45after that screen.
04:47In this type of case if I set that end for example and I want the width to be a certain
04:52size right and I want this width to be a certain size and we're going to look at that
04:56again in the next chapter but when I want to create a screen and with it this is not
05:00going to work because if I'm in an old browser it's going to see that it's a screen that's
05:04going to automatically adhere to it so a new derivative that is there to help us fight
05:09that problem is called only.
05:11Now the only in essence for the newer browsers that support this derivative which most of
05:17them do these days when they see the word only they just basically ignore it and move on
05:21to the next thing but when you're working with an older browser that supports an earlier
05:28version of media queries and it sees the word only it treats only as if it's a media
05:32query and there is no such thing as a media query which is called only so it automatically
05:37would not load the file and not work with it so the only is not really used on a daily
05:42basis really but it's a fantastic way for you to make sure that if the browser does
05:46not support this media query combination that it will not load it at all contrary to that
05:52if I just had your screen and if it's an old version of media queries then it would
05:57just take the screen and do whatever is inside of it and ignore all the rest but
06:00by adding the word only it will basically bump up our capabilities.
06:05Now last thing I want to talk about is only three there's the end which is used
06:09throughout in between characters only is only used in the first character and one
06:13less item which is called not and not will only be used in the beginning of the
06:19the expression as well. Now the not expression will basically do the opposite
06:25of the rule that is in front of us and it negates the whole rule and it's a
06:29good idea to put a round bracket around it just for your visualization and
06:34logic so everything inside of the the element but it really is everything
06:37inside of that line will be negated so in this case if it's not screen that
06:42means if we go to this and we try to look at it on a screen itself because we're
06:46on a screen we're not going to see any CSS but if I go ahead and I try to
06:50print this and I try to showcase the print that I've just created we'll see
06:55that the design itself is going to go through and interpret it. Now notice
07:00one more thing that Oto because inside of our style we also have a print here
07:04then it's going to adhere Oto all that stuff inside of the print but in general
07:08that is how we work with not how we work with only and how we work with end
07:13now don't worry about memorizing this because this is really the teaser really
07:17into the next chapter because in the next chapter we're going to start
07:20working with expressions and one of the first expressions we're going to work
07:23with is going to be the width and height and start controlling visually how
07:27our application will look like as we resize it so if I go ahead here and I
07:31just delete this not and I'm going to let that in your and by the way if you
07:36forget all those derivative it's not going to be in the source files so as we
07:39resize our design we're going to want to make sure that our design changes
07:42and that's going to be something that we're going to be confronting with in
07:45the next chapter now in case you forgot already the references of all the
07:50things that all the keywords that we were working with in this chapter just
07:53make sure to go into the link inside of your references media query device
07:58types and go ahead and click your refresh because we made a few updates
08:01and in here you can find a rich amount of things that are very very useful
08:05obviously all the different types that we have also the media query connectors
08:10the and not and only with a little bit of a description of how they work and
08:15also some references for further reading if you want to read a little bit
08:18further before you move on to the next chapter for example how widely
08:23available our media queries so media queries if you go into that site you'll
08:27see that currently it is really widely supported all the way from IE 9 and on
08:32and that way you could test with your own analytics to see hey do you have the
08:36users to support this or is it worth the effort which in high probability it does
08:41so that's it we're done with this chapter and we'll see in the next
08:45chapter when we go into the responsive area and using these tools and media
08:50queries with with expressions to create responsive designs so see you in the
08:54next chapter when we do that
