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

Creating responsive designs with size ranges

In the last lesson we created a web page that was fully optimized for a specific device. With 100's of different resolutions and settings it would be impossible for us to create a specific design for every single device on earth. In a real world scenario we would usually use what we learned in the last lesson to tweak and improve our design for specific devices.

For us to design a design that don't target one specific device or resolution we need to be able to define ranges of acceptable parameters. By defining ranges we open the door to responsive designs and enable our design to look great in the ranges that we wish to manage. In this lesson, we will learn how to create a responsive design that would modify dynamically as the users change the way they interact with it. By the end of this lesson, you will know how to work with the min/max prefixes to create responsive designs.

Keynotes:

  • What are responsive designs
  • How to create responsive designs
  • Working with min/max prefixes

properties:

media queries, HTML4, CSS2.1, width, height, minprefix, max prefix

Video Transcript

00:00In the last lesson, we created an adaptive design.
00:04So it's time for us now to start creating responsive designs,
00:07and for us to be able to do that,
00:09we need a little bit more control
00:11than just the specific resolution of the device.
00:14We actually wanna move into the resolution
00:16of the browser itself,
00:18and that's really the key of responsive design,
00:21because with it, we will create the responsive design,
00:24and that's what we're gonna do in this lecture,
00:26as we get to know the min and max prefixes,
00:29and also how to see those specific sizes
00:32that relate to the specific resolution
00:34that the device is currently at,
00:36the specific width and height the device is currently at.
00:40All right, so let's get to it.
00:41So as we can see in our current browser resolution,
00:44our browser's right now at 1300 by 642.
00:50Now really the core of our design
00:52is this rectangle inside here,
00:54which its size is basically 900 pixels.
00:58So if I went ahead and I resized my item,
01:00really everything would be fine all the way
01:02until we reach the cutting point of that 900 pixels.
01:06Once we do, then suddenly now we have a horizontal scroll,
01:09and our design is not working as well as it did until now.
01:13So the next step for us is really to say,
01:15okay, we're happy with our design,
01:17and let me just take it a step back and go into our code.
01:22We met already the device with the device height,
01:25and we've even met the device ratio,
01:29well, aspect ratio.
01:30We've seen four different types of ways
01:32to configure our elements based on device.
01:35And really, the next step is saying,
01:37okay, let's get rid of device.
01:39Let's focus on the browser itself.
01:42To focus on the browser itself,
01:43all we really need to do is create a media rule,
01:46and I'm gonna go ahead and create it for the screen.
01:49And I'm just gonna say, hey,
01:50if your width is a specific width,
01:53in our case, if our width is 900 pixels,
01:56and by the way, I know that it's 900 pixels
01:58because up above in my CSS where my article is configured,
02:03its width is 900 pixels.
02:05Oh, so its margin is quite big.
02:07And really when we get to a scenario
02:09where our width is 900, we don't want so much padding.
02:14And this is a very, very theoretic sample
02:16because really the sizes would be configured
02:18based on the actual need,
02:20which is based on your actual analytics
02:23of your site that already exists.
02:25Let me just push this into our screen area.
02:28Okay, so let me continue.
02:29So let me for a rule for if my device is exactly 900 pixels,
02:33I wanna go to my article and I wanna,
02:36you know, like right now we don't even wanna do that.
02:38I'm gonna go to my body
02:39and I'm gonna set my background color to be black.
02:43Let's just go ahead and see it in action.
02:45And I'm gonna go ahead and click on refresh.
02:47And we'll see, I'm just gonna go ahead here
02:49and click go all the way to that specific size.
02:52And once I hit exactly 900 in my width,
02:55which is gonna take a little bit here
02:56of playing around,
02:58900 and four, three, two, one, boom.
03:01And notice how my background is black.
03:04If I go a little bit smaller,
03:05it goes away from that color.
03:07So it's literally only at 900 pixels.
03:09And that really is not incredibly useful for us
03:13if we wanna create a design
03:15that is gonna be based on ranges,
03:17which is exactly what we want.
03:19So be able to solve that every single parameter
03:22in CSS media queries that is a range.
03:26So not any item just because it's a number,
03:28but any range item like a width
03:31could then accept a parameter of min width or max width.
03:36And that's true also for height.
03:38It's true really for almost for many of the parameters.
03:41So in this case,
03:42what I really wanna do is I wanna say
03:44for the maximum width of 900 pixels,
03:47basically saying until 900,
03:49if you're more than than just ignore this,
03:50but if you're less than 900 or equal to 900,
03:54let's create here a few rules.
03:56So for my article,
03:57I wanna make sure that my width is actually 100%
04:00because I basically want it to resize.
04:03And by the way,
04:03this is also gonna solve our problem
04:05where we wanna have,
04:06and not only do we wanna have a design that is adaptive,
04:10that will have a different design if it's less than 900,
04:13but we also want it to be fluid.
04:15And by making it fluid and adaptive,
04:17we're making it responsive.
04:18So I'm gonna set for my article width,
04:20I'm gonna make sure that it's 100%
04:21and something that is relative.
04:23For my margin,
04:24I'm gonna go ahead to my margin,
04:25just set it to be the automatic margins
04:27because I don't wanna have those big margins
04:29that I had previously.
04:32The next thing I would like to do
04:33is I also would like to,
04:34well, I think I would do it really for this scenario.
04:37So let's go ahead and click on refresh
04:39and I'm gonna go back into my browser and click on refresh.
04:42And if I go to that 900 region,
04:45notice what will happen.
04:46Instead of creating a scroll,
04:47my design is basically gonna shrink
04:49into that specific space.
04:51Now again, right now this design is not perfect.
04:54You see how it's breaking once we cross a certain size.
04:57And in this size,
04:58the reason why that's happening
05:00is because we have hard set values,
05:01also in the value right here.
05:04So if I go back into my source files
05:06and find why that's happening,
05:07we'll see that it's actually happening in my info tab.
05:10And if I find that info right here,
05:12we'll see that that width is 400 pixels again.
05:16So what I wanna do next to here,
05:18what I wanna do next is literally go to that width
05:21and turn it to be a percentage if my width is 400 or below.
05:25So I'm gonna go ahead and do that.
05:27And I'm gonna go to my media.
05:29Again, screen and max with 400 pixels.
05:36And in a scenario where it's 400 pixels,
05:39I wanna go to that article.
05:41I wanna go to that info tab.
05:43And what I wanna say to it is,
05:44by the way, your width from now on
05:46is 100%.
05:47Now I'm not gonna go over every single item
05:50inside of this application
05:51to try to make it perfectly responsive,
05:54but you'll see that right now our design is working,
05:56might not be perfect, but it's working.
05:59And as we progress and get larger
06:01than our little elements in our design
06:03are updating based on the need.
06:06Now generally in general,
06:08we probably would wanna start from the slowest resolution,
06:11the lower resolution and grow up to higher resolutions.
06:14But in this case,
06:15if we already had a design
06:16and it is already in a specific size,
06:19then we are gonna scale it and change it based on that.
06:22For example, even if our design was a lot larger,
06:24we might wanna change things
06:25such as making maybe the fonts larger
06:27or making the fonts smaller.
06:29And that could be a great task for you
06:31to modify also the fonts in those breaking points.
06:34And there's a few ways for you to do this.
06:36One is focusing on breaking points,
06:38which is what we did,
06:39or focusing on the standard common sizes
06:42that you have based on your analytics.
06:44I myself personally prefer focusing on breaking points
06:47because usually you'll have less breaking points
06:49and it helps you think about designs and build designs
06:53that have less breaking points in general.
06:56So that's it for this lecture.
06:58And we really covered everything that we wanted to cover
07:00related to the core of responsive design.
07:04We know what responsive design is now.
07:06We've even seen it implemented now
07:08and we've seen the usage of the minimum and max prefixes
07:11although we only use the max prefix
07:13in a real world scenario
07:14for starting from a smaller application,
07:16we could start with the min.
07:17In this case, the max was the most appropriate one.
07:21All right, what are we gonna do in the next lecture?
07:23In the next lecture,
07:24we're gonna move to mobile responsiveness
07:26which there's a couple of rules
07:27and a couple of things that we need to know about
07:29to create a design that really works on a mobile device
07:32the way we expect it to work.
07:34So we're gonna talk about that in the next lecture.
07:36So see you then.

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!