Media Queries Hello World
There is no better way to start showcasing media queries then by showing them in action. In this lecture we will learn how to define different CSS files depending on the type of media. This capability has been around since HTML4/CSS2. By the end of this lesson, we will know how to define media type per CSS file.
Keynotes:
- Two ways to define Media Queries.
- Why set media queries file wide
- Example of Media Query for print and screen implementation.
properties:
media queries, HTML4, CSS2.1, print, screen, aural, braille, handheld, print, projection, screen, tty, tvVideo Transcript
00:00It's time for us to take our hands right into doing things and the main topic in this chapter
00:06And let me just refresh this the main topic is media queries as a low world
00:11There are two different main ways to basically create and work with media queries
00:16One of them is by defining it directly into the HTML area if we look into this HTML here for a second
00:24It would be somewhere in our link itself by defining a media type saying hey
00:28This is only relevant to print. We're gonna look at that in a few minutes
00:32Another is directly inside of the style inside of the CSS
00:36We're gonna take a look at in this lecture about how to do it in the site in the file wide version
00:43We're going to talk about why would you want to set a media query on a whole file?
00:48Why would you want to create a completely separate file for a specific media for example for a print?
00:54Is it better to do it in the first way or the other really the answer is it could be both depending on the situation
01:00But we're going to look into that in this lecture
01:02And we're going to take
01:04The that look as we showcase how to create a specific print version of our application for example in this case
01:12We want to get rid of the advert and a few other
01:15Modifications that we want to create to our printed version of our website
01:20Just like you do when you go on to gmail or any email service
01:23You want to print the email notice how the email looks completely different in the print version versus versus the regular one
01:29And this is really relevant in situations where pages are
01:33Expected to be printed for example inside of a blog where you don't want all the wrappers and all the information you want to have
01:38A little bit more control over how to lay out the content in a way that would be more fitting for print
01:43So that's it. That is our topic in this lecture
01:47So I went ahead and created a design that isn't really responsive yet
01:52But by the end of this course it will be
01:54Responsive and you can see in this design that we have here a few links and they're gonna grow and change as we go
02:00Along now you'll see that we have here an advert as well for our website
02:04This is a zero to geek ad so buy stuff from us, which is a great ad now
02:10In a real world scenario when I print this document
02:14I might want to get rid of some things in my design or I might want to change or tweak a bit my design
02:20So let me go ahead and just go ahead and print my design and I'm gonna go ahead and just go
02:25just
02:27Call to print the design. Let me just do that really quickly and I'm gonna go ahead and open it in preview
02:33All right, this is as close as we can get to seeing the whole page. Here we go
02:37We see the whole page now one of the problems we might have with this is the for example
02:41We don't want this advert to show up
02:42For example, we might be printing out a plane ticket or maybe the font that we're using on a display
02:48Just does not print out
02:49Well on print in a scenario like that
02:52We really want to create a separation between our design on the web
02:56Versus our design for print and lucky for us. We do have that capability
03:01that's exactly where
03:03Media queries come into picture and I want to show you through this problem the solution and through it introduce the topic of media queries
03:10So I'm gonna go ahead into our source files and in our source files
03:14You are also going to find inside of our source files CSS folder. You'll see that I've set here also a print dot CSS
03:21What I really want to do is I want to include this print dot CSS file
03:25So I'm gonna go ahead here and I'm just gonna call a link
03:28You know, let me just copy this whole thing and I'm gonna add right underneath our style
03:32Oh, so our print because really what's going on here is I want this style to take an effect and on top of that
03:39I then want to implement this style right underneath it for print
03:43But what I really want to do is I want to say to the browser by the way
03:46Only implement this for a print and not only for a display
03:49But before we even do that, let me go ahead and click on refresh and you'll see now how it's gonna look like in print
03:55So that that is the changes that we're doing that is modifying the layout of our document for print
04:02But really in this scenario we change it for all over
04:05So the next step for us once we've added that new file that we wanted to extend with all I really need to do is
04:11Set the media property and in the media property defined to what does this CSS file relate to in this case?
04:19it only relates to print and then I'll type in that media query type option of
04:25Print and if I go ahead and click on refresh, we'll see that now everything in our design remains the same
04:30But if I go ahead and try to print this document
04:33We'll see that this time around when I open it up in preview
04:36We'll see that now our design is gonna not have that banner and our style is gonna pushed up more to the top the way
04:43We want it to be really done in a printed version now before you finish this up
04:48I want to kind of holistically
04:50Go over this topic and if you scroll into your references
04:53There'll be more of them as we progress throughout the chapter
04:56Just make sure to click into media query device types
04:59It will open up in our blog and there you're gonna find a list
05:03Alright
05:04So media query types and you'll find inside your a list of all the two different viable options in the current world that we live
05:10In the version all basically enables is basically the default. So basically it says use this on everything
05:16Screen is when you want to do specific things that only relate to the screen print as we saw is the divine rules for printed devices
05:24Handheld is for small devices that are usually handheld
05:28TV is for smart TVs that have internet on them projected in this projection is for projectors Braille and embossed are for
05:36Visually impaired users who or the display of it that is dynamic or the print version of it
05:43I don't even know how to say that Oriel arrow arrow
05:47Anyways, that has been deprecated and it's now replaced with speech. Although it is still in the development. So speech
05:54Is really for CSS rules that relate to speech which is quite fascinating
05:58But is a completely different topic in there
06:00We'll see that there's a speech one and then there's TTY which is to be honest
06:04I don't know exactly what the situation where you would use it. I tried to do a little bit of research
06:09I've never used it myself, but it's intended for media types that use fixed characters
06:14such as
06:16teleprompters tell
06:19Which basically is maybe airport kind of stuff or you know
06:22Areas where you have a fixed width and height to the files affix hit within height for elements
06:27It's a very interested limited displays, which I don't really have any experience with them personally
06:32I would love to hear from you if you do or if you know any other
06:36Resources and references where you could learn more about it throughout this chapter
06:40We're gonna have a few extra throughout the topics in this chapter if I'm ready here
06:44You'll be able to find more referrals and more information of think further things
06:47You could learn about related to the topics of this chapter
06:51And that's it for this lecture and in the next lecture
06:54We're going to continue obviously from the first step where we looked at how to define these
07:00Media types directly externally from the file defining it file by file and how do we create these rules?
07:06Inside of the document itself merging the two styles sheets together. How could I create this rule in one CSS file?
07:13And that's exactly what we're going to look at in the next lecture
