02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Optimizing for a specific device

CSS media queries enable us to filter out devices based on a set of parameters. We have met in the last chapter many parameters that were hard set defined as "yes" or "no". For example, a device could only be a hand held device or not. In this chapter we move away from boolean expressions and move into a rich world of values starting with the width and height expressions. In this lecture we will be introduced to the way to work with expressions.

Keynotes:

  • How to define media query expressions.
  • Combining multiple expressions.
  • Designing for a specific device(such as an iPhone X).

properties:

media queries, HTML4, CSS2.1, width, height, and, expressions, iphone, design for device, device-width, device-height, device-aspect-ratio

Video Transcript

00:00It's time for us to start designing our sites for specific devices, but really let's start off from that core sample
00:08That we talked about in the last lecture, which was really about creating a design that is not static
00:14So it's a design that although not fluid yet, although not responsive yet
00:18It's a design that is adaptive that it adopts to the screen of the user depending on their resolution
00:25So we're going to look at how to define these type of media queries or really learn about expressions and how to define them in
00:32CSS media queries
00:34We're also going to combine different multiple expressions to create rules that will enable us in the end to design for specific devices
00:41Such as an iPhone whatever version is out now six seven. Maybe eight will be out when you're watching this video
00:49Okay, so let's get started. I'm gonna jump right into my browser and
00:54and
00:55what I want to do next is I'm gonna I'm gonna take my design that I currently have and what I really want to do with this
01:01Design is I want to be able to resize it and literally when I resize to a specific size
01:06I want something in my design to change. So let's take a look and see how could we do that?
01:11And there's really two specific items that I want to take a look at and I'm going to start with designing for specific
01:19Browsers specific designs and you can see in our design here that my device resolution is
01:252560 by
01:271440 that is the resolution of my screen. What if people with that specific resolution?
01:33I want to create a specific design just for them
01:36No matter what is their current browser size because really currently our browser size is 1300 ish by 640 ish
01:45So let's go into our code and I'm gonna go right into our CSS rules and just scroll all the way down to my style
01:51And give myself a nice clear screen here
01:53And I'm gonna create a new media rule and the way I create media rules that have specific contrary to just screen that I
02:02Screen that we said I could just place it like this and everything is fine
02:06That was true when there was only one thing going on here
02:09Not true anymore once you have actually things going on and if you recall I told you to put things into a round bracket for
02:16Organization, but really when it comes down to using expressions. We have to put each expression inside of a round bracket
02:25So I'm gonna go ahead and start with device with and the device with parameter accepts a pixel. So my screen
02:34I know is 200 and 256
02:36Pixels, although each any other numbering system would work
02:39But really it has to be relative to that device if you're in our case, we're on a screen
02:44So it's pixels if we were trying to do it for print then it might be inches or it might be another measurement
02:50Okay, so the next step that I want to do once I define this one specific rule
02:55I'm gonna go ahead and save this this rule is going to be automatically applied because in my current device
03:01My width of my current device really is to
03:042560
03:06So let's go ahead and add here something to make it noticeable
03:10So I'm gonna go to my body and for my body
03:12I'm gonna say by the way whenever your device with is that specific item we're gonna change the background color
03:18And I'm gonna go ahead and paste here a color that I pre-configured earlier and I'm gonna go to to my article and
03:26I want to go to my advert and I want to change the background of my advert to a shade of green
03:32That I pre-configured earlier as well, which is the same green that we're using for our font
03:38Alright, so I saved it
03:39I'm gonna go back into my browser and you'll notice now that if I click on refresh
03:43Because this rule applies to any device that has 2560 pixels as it's with you'll see that now
03:49My background color is gonna change
03:52My advert is gonna change although
03:54I think I probably didn't change here to the right color or maybe just double double triple check that I don't don't have here
04:00any spelling error
04:02This looks oh, yeah. Well, there you go. That's what I did. I forgot to write your background
04:07I just put the color directly which was a mistake. Okay, so let's go ahead and click on refresh there and
04:13Now we'll get our color the way I wanted it to be and there we go
04:16we just created our first adaptive design really because it's adopting to the specific browser of the user and only if that
04:24Specific device really and only if that user has that specific device then they would be
04:30Exposed to that specific color now
04:33I want to close off this lecture by go ahead and go into that you're targeting devices with media queries
04:38Which you'll find inside of our sample and in there you're gonna find a short little article explaining the different device
04:45Parameters that you could use the device height the device width the device aspect ratio and the device pixel ratio
04:53Now I want to show you how to combine the two and you could see the example right here below
04:58Where we just add the word and to append to the different values
05:02So going back into our code if I wanted to say hey
05:05I only want this to be if it's a screen because obviously this is not relevant if it's anything but a screen and
05:11Not only the width I also want to make sure that my height is a specific height. So I'm going to go to my device
05:17Height and let me just make everything a little bit smaller here. Oopsie
05:21Let me just scroll a little bit up here and I'm gonna for my device height
05:27I'm gonna go ahead and set the actual height of my device, which is which is which is which is 1440
05:33So I'm gonna go ahead there
05:351440 pixels and there you go
05:38And now you see that I'm adding I'm combining rules of saying I want it to be screened and also have a device width of a certain
05:44Size and also have a device height of a certain size and this really answers the question of how do we target to a specific?
05:51device so if I go ahead here and click on refresh
05:53you'll see that it's still in that new color that we configured for this specific resolution and
05:59For you to be able to if you wanted to create for a specific device now that you know
06:03How these rules work there is also something that's called device pixel ratio
06:07Which is not currently part of the standard as of the day of this recording in late 2015
06:13But if you click on the attachment link here in this post
06:16You'll see a list of different modern browsers different modern devices that you could target to so for example
06:22If you want to target to the iPhone 6 plus you'll see that
06:26it's the it's with the device width the device height the pixel ratio and then you could create a
06:32combination that would adhere to that rule basically saying device width of that item and the height and the device pixel ratio and
06:40notice how you have your
06:42Minus web kit and that is because this the iPhone runs on a web kit and because this is not currently a standard
06:47This is the way to access that feature. So it's a really
06:51Your best bet is if you want to target a specific device is to go literally into one of these lists
06:57Find a specific list that really targets that specific item that you need and you're set so that's it
07:04That is it for this lecture and we really covered everything we wanted to cover
07:09Because now we know
07:11Everything about how to target a specific device and how to target a specific resolution
07:16So now that we're done with that topic and now that we know really in essence how to create
07:22Adoptive designs really the next step is to really create a responsive design and the way we create a responsive design is we
07:29Can't just put specific sizes. We have to put a size range and that's gonna be our main topic in the next lecture
07:36So we'll see in the next lecture where we actually start creating a responsive design

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!