Making a site that responds to itself
Fluid and responsive designs are great. It's nice to have small elements change but many times when users make a screen larger or smaller they would like to see the content size scale as well. In this lecture we will learn about how to use relative measurement types to enhance the users experience with our site.
Keynotes:
- the vw and vh measurement types
- Making font sizes grow dynamically with CSS
- Doing it in a backward compatible way.
properties:
fluid fonts, vw, vhVideo Transcript
00:00We created a responsive site that is really fluid and now it's time for us to
00:05move our attention to making our site respond to itself and
00:09We're really there's only one way of doing that and that is by leveraging the viewport width and height
00:15Now this is not widely supported or it's starting to become widely supported right now
00:20So it's part of that consideration of do you want to use it or not?
00:24And because of that we're well basically what we're gonna do is we're gonna create a fund that will grow
00:29Dynamically with our CSS without us needing to manually resize the fund in different size points now
00:37When to use and what well really in this case we're talking about
00:41How to use it more than when so in this lecture we're gonna figure out
00:45How could we use it and still have some level of backward compatibility?
00:49So let's jump right into it
00:51So even before I go to the code
00:55I want to go ahead and go into your source files of section 3 and click into CSS
00:59measurement types there you're gonna find in the bottom of the article a list of links where you continue reading click into
01:07Can I use the viewport width and height and into can I use media queries?
01:11Now let's start off with the media queries and you'll see that media queries in general is widely supported
01:18It is widely supported, but ie8 does not support it
01:21But beyond that really most of them up-to-date versions of all the different browsers support media queries
01:28Contrary to that when we're talking about viewport units. You could see that there isn't as as
01:34Complete level of support there is definitely support on ie8 as well, but it's the viewport
01:41The the viewport is partial support. So really when we're talking about here in some areas
01:46There is partial support most browsers support if we're talking about it
01:50We're talking about a roughly 81% of current browsers today
01:54Support it now that might change in a year or two. So we really can't set and configure
01:59Oh the the viewport with and when I'm talking about the viewport width is really literally
02:05When we're talking about the size measurements
02:06We're talking about a relative measurement type and this relative this measurement type basically one of them
02:12equates to 1% of the viewport width or height
02:16So in this case if I configure and I go to my source files and I say I want my font to be one view
02:23Then that's going to set based on the width of our screen
02:26And I want to go ahead and really do that and to do that
02:28I'm going to scroll all the way to the let me just see why it's jumping here
02:31I'm going to go ahead and scroll all the way to the bottom of our media types and just before I set the media types
02:38I'm going to go ahead and add a new media to media only
02:41Screen that way. I'm going to make sure that anyone that does not support fully support media queries would disappear
02:47and I want to focus on minimum width and
02:51The minimum width that I want to focus on I'm going to go ahead and say minimum width of 900 pixels
02:56So I'm basically saying anything that is 9 pixels or more while the on the bottom
03:02I'm saying anything that is 900 or below. What do I want to do in this scenario?
03:06I want to go to my font out to my body font which defines of every size of everything in that in the site
03:12And I'm going to go ahead to the font size and I want to configure that font size based on those view point ports
03:19So if I go ahead and set it to one view
03:22View with viewport width and I'm just going to go ahead and save this
03:26And I go and I refresh my browser in my application. I click on refresh
03:31We'll see that everything is resizing now, obviously, this is too small
03:34What I really want is a percentage that is a little bit higher
03:37What I already played around with it a bit and the size that I'm really interested is 1.8
03:43Which is literally basically 1.8 percent of the width of the current viewport that I'm in
03:49Now what this does it first of all it created a design that is a lot wider a lot more interesting in general now
03:55You can see that I have your overages and these overages are very simple
04:00it's because in my actual code for my width itself if I go find the width itself and
04:06The width itself is configured somewhere up here. Let's find out my article
04:10I'm asking actually asking it to be 56 times whatever it was
04:14So if I'm going in I'm asking for more or less 2% of the width of the screen
04:18I'm asking for a hundred and ten percent. So I have to change the article width as well
04:23So I'll go back into this media type and I'm just gonna go ahead and type in the article and for the article itself
04:29I want to superimpose a new width and I'm gonna say I just want it to be 90% of the view width
04:36Basically saying take 90% of the screen if I go ahead and I click on refresh now
04:40Now it's gonna take 90% of our screen
04:42Making sure there's a lot of space inside here and making sure that if the user is resizing their screen
04:48The content is gonna flow and get smaller all the way until we reach 900 pixels where it's gonna snap to a certain size and
04:56Stick to that certain size now in essence really what I would probably do in a real-world project is I would probably
05:03Dismiss all these other variant sizes and create a size based on where I see that it breaks
05:08We're not gonna get into that in this lecture, but I want to close off with
05:13As we say so how would you do to create and make sure that this is gonna be supported widely throughout and the answer is because
05:19You already configured a design that works if I go ahead here and I just get rid of this and just save it
05:24I already have a design that works if a browser doesn't support our viewport width and height
05:30Then it's just not gonna show it beyond a few
05:33Minute browsers that have a few bugs and we could choose if we want to fix it or not
05:37But in general this will be what users see if they don't support viewports
05:41But if they do support viewports and they're gonna get a much more custom experience that will enable
05:46resizing the browser based on the size of the browser that they're in which is a really great solution because then if the user
05:52Zooms in zooms out if they're changing their their browser size, they're gonna automatically get it a better experience
05:58But as we go down to smaller browsers, which usually users don't have a chance to resize in them
06:03Then we could have there a much more finite control
06:07Another thing that we could do is when we decide that we're gonna go down to a certain size and we're ready
06:12Let's say in this size and we feel like the size may be too small or too big or maybe we're fine with the size
06:18But in the 400 pixel area, it's really getting too big
06:22Really for the regular font we're fine, but for our headline font we're using too much
06:26So maybe in those in that type of a scenario may be inside of the screen with area here
06:32I could go ahead and say okay from my body overall body font
06:35I might say okay from my body. What I really want is a font size that is larger
06:41So maybe I want it to be 18 pixels in size or maybe 18 points even
06:45maybe I want to configure it in a much more strict way and then I could go ahead and click on refresh and
06:50Then play around with the other sizes of the different elements to get it to be the sizes that I want it to be
06:57but really
06:58It's really a matter of playing and adjusting and figuring out because this only happens at 400 pixel range and below
07:04So in this scenario if I'm happy with most of the fonts, which I am
07:08But I'm not happy with the headline then I could go to the headline
07:11Find where the headline rule is and in this case our headline rule is right up here for it's a global h1
07:18And then I could go ahead and just copy this global h1 and just paste it right inside there and just change the rule
07:25So maybe instead of 2.8
07:26I might want it to be just two times that font size and maybe I'm gonna be happy with this size and if not
07:32I'll tweak it a little bit further and that's it
07:34That's literally all you really want to do with those fluid designs and where you would choose between a fluid design that is
07:41Completely responsive which you might decide to do that in certain sizes where your font is changing and growing
07:46Maybe once you cross a certain size because you really designed for a certain size ratio
07:52You're keeping all those ratios and all you're doing is making that initial font larger
07:57Which is making everything larger because you configured it in that way
08:00Making it easy for you to be support a wide range of browsers while not
08:05Rechanging or re-shifting your design sharply or drastically. So that's it. We're done with this lecture
08:11We're definitely not done talking about advanced
08:14Design strategies because in our next lecture we're going to be talking about optimizing for specific devices
08:20So we'll see you in the next lecture when we explore that topic
