How to change the layout of a responsive website for mobile vs desktop
Hi there in this video. We are going to take our sweet new media query skills along with some of our past flex box skills to do this. Go from desktop view where it's three across ready for tablet, tablet, tablet to look at that mobile one. Now this is proper responsiveness where we start changing the structure oversight to make best use of the screen real estate available. Let's jump into V. S. Code and work out how to do it. All right. First up, let's get rid of this stuff. Don't need the H one. Don't need the starting there. We'll leave our media queries. Okay? So when you are deleting the H one at the media query, don't delete the second brackets. Okay. Because it'll half work. The browser is pretty clever and c as well. I'm missing this but I'll still work kind of. Okay, So just make sure we don't. All right. We're going to add a container. Okay. Remember containers. Weird one where it feels like there should be like a specifically named H html five tag. Like what div and header bu...
t it's not. We have to call it a class called container. Okay. So this is where everything is going to go. Let's style this container. So we're going to do all of it in Global. We're going to say container. I would like you to be we'll put a background color in first to make sure it's actually appearing background color. I'm sick of these colors. I'm gonna pick my own by clicking on it and then dealing with the color picker. Cool background color. Let's preview, make sure it's working. Nothing is working. Why not? Because it doesn't have a height. I knew that. Okay, so we need a height and we're not going to use this regular height. Remember we're going to use min height. Okay. In height even I'm gonna throw in 500 pixels just so that there's some kind of guts to it. There it is there That is not, it can be any size actually I'll probably leave it off and just start building knowing that it will appear at some stage but it's a bit weird for classes. Okay, we're going to add a width like we did before, we're going to say a width of 10, pixels wide. Now, the problem with doing that A width by itself, like that is an absolute size. So it's going to always be 124 but I don't care if you're a mobile tablet. So what we're gonna do is we're going to say you can be a maximum of up to that. Okay, Because that sort of decided my like it's a bit weird having computer issues. Okay, so a max width is just going to say you go up to that but no further, but you can go smaller because that's just the maximum width. Alright, last thing we'll do is we'll get it to centered. Okay, do you remember what this was? Remember it was margin left and right. Set to auto. We're going to use our shortcut. Okay, so we're going to margin to the top and the bottom, we're going to be zero but the left and the right are going to be auto. So just the space between them that should work nice. So that's my container. I now inside of this container, I'm going to add a bunch of those kind of blocks you saw in there. So up until now we've been calling them cards in some instances boxes. Okay, in this case we're going to start calling them coals. Okay, sure. For column for no good reason, it's not like a predefined tag in here. It's just very common to use it. And when we start looking at things later on something called bootstrap, they use the word coal as a box instead of box or card tile. So we also just get in the habit of doing that. So I want 10 of them and I want inside of those boxes of one H one. So I'm going to try and impress you with some emmett. So what do we want we want to call? Okay, and inside of that coal. So the greater than bracket and so inside of it's gonna have an H one and I'll show you another fancy thing if you put in curly braces here and say so on boxing there, the curly braces is going to put inside of that H one. It's going to put some text just plain old text called box. Okay, so that's kinda half of what I want. Right? But curly braces return so that's kind of what I want. Okay, so, but if I do times 10 it's not gonna quite work because it's going to give me a call one coal and then 10 H ones. So remember we kind of did this before you put it in brackets, coding. Help tries to put two in them. So all of this to be working and you're like, that wasn't worth it and it totally wasn't. I just, I guess I'm getting used to this index showing you cool, helpful things like putting in curly braces and the other weird thing about it is that we're not weird. It's giving me kind of some nice structure but it actually looks a little bit nicer. If I just do it the long way. So I'm going to do cole I'm not going to going to use the right case. I was just duplicated. It seems easier in this case. So coal inside of here is an H1 inside of this is going to be box. That's what I wanted. Right? So to duplicate it, you hold down the option key on a Mac and the shift key down arrow. So that's option shift down arrow if you're on a Mac, Sorry, that was for a Mac. If you're on a Pc it's shift down arrow And you should count. I didn't count. We need 10 of them. I'm going to add numbering to them. That will help me and no fancy way that I know of for doing this except for ah look at that that went well. Let me guess the right number as well. That was just down arrow and start typing. Let's have a little look what we got. Okay, a bunch of boxes now let's style those boxes. So they're called coal over here, my global I'm gonna say dot cole you're going to be a color? No, you need to be a background color back. Ground color. Okay. And I'm going to pick any old color so I can click in it and pick a color that I like. Makes no real purpose. There we go. Just pick some nice colors down. Alright, so we've started the coal. Let's have a little look. Let's give it a width and a height. Sorry, going a bit fast. So yeah, it's just doing that because I have not given any dimensions. So let's give it a minimum height of I don't know, 200 pixels Nice. Let's give it a width. Okay, Because they're taking up the whole thing, let's see if the width will fix it. So instead of doing a max width or a min width we could do absolute sizes and start playing with max width but we're gonna use percentages which is basically the same thing because it's a it's not a fixed size And what I want in this case is let's look at our mock up. This is the desktop view. So I wanted to be about that. So three across and two across and one across. So kind of 100% width. This one is going to be 50% with fish. This was going to be 33.3. I'll leave it a bit of space in between them so it might just make this 30% across. Let's have a little look. It's not gonna work. Okay. The reason it's not going to work is why are they sticking on top of each other and not beside themselves or in line? You got it. Okay. So it is, we could say columns are display display in line. Okay. And you'd be totally right in line block. Okay. And that would work. Okay. But what we're going to use is go back to our flex box. Remember what we could do with flex box about display And we're gonna use flicks. It's going to be part of the thing for us. No, it's not display flex. 30%. Yes. Why are you displaying flicks? Oh, I've done to the wrong one. Has to be the parent. You remember that Dan. Okay. A good test for you to pretend it was a test. Okay. So the container. Okay. You applied to the container. So it applies to all the Children which are these coals. Let's have a look now. That kind of works. It squeezed them all in and by default it squeezed all 10 of them into the same row. Okay. And it made it 100% of the parent. What I'd like to do is actually do here do flex, flex wrap. Okay. And what kind of rap? Just the regular old rap. Okay, save it awesome. So 30%. They're rapping. Okay, so 30 30 30 we get we get to 90 K. Leaving our gap. So a couple of things actually before we go wrap you can you saw it there? I can't remember if I read reverse. Okay, so box 10 is at the top. Never use that. But it seemed I felt like I wanted to share that they're now what I want to do is put the spacing in. Okay. We could play with margins but remember that fancy thing we learned earlier on, we can justify the content. And we're going to use which one? Space around. Space between. There you go. Save it. There you go. Space around. Might be a good exposure. You'll see it here. I had to kind of like point it to you before, but we had a white background. So space around is evenly either side. Okay. And I never want that. I always want space between let's go add a bit of padding to the bottom of them. So the coals let's have a little bit of padding margin bottom of 40 pixels. Alright. It's looking good. Okay. The cool thing about them because the 30%. Okay, they responsive by themselves. They get to a max with okay, but they're allowed to go smaller, the container can get smaller. Okay, but they can't go past that and it's going to work for us at the moment. You could design for a heaps larger size and it depends on your audience but they might not have you might be designing a whole big website for all for people that just are never going to see it. There might not be that many people who have this ginormous desktop to you. Alright, that is it for that now I'm ready to adjust them for the different media queries. So down here and it's the same thing. So cole okay at our curly braces, I'm going to say coal, we're only going to do the width. Okay, so the width down here is going to be a different percentage so remember 50, it's kind of 50% for our tablet view. Okay, but a little bit less for this. So maybe 45%. I don't have to reiterate things like justify or flash flex wrap because it's already globally applied to everything. Let's have a little look. Alright, so just of you, Let's use our proper fancy one. Right click inspect. Okay, let's go to our show me decrees they're not on by default show show show. Oh they are right there in blue. Okay, Let's go to this bigger size. Alright. It's not adjusting its because of this. Okay. I left it said to IPhone four and it will not change. You could get the responsive and it will change. Okay, so Let's go big version three boxes go to this morning. Hey, it's only 45. The gap there is a bit big in the middle there so maybe 47 might be a better percentage. Okay, but you get the idea right? We did it with plain old H ones before now we're doing it with actually the structure of the site which is kind of tends to be more what you're doing. Okay, we've done it for tablet, tablet, desktop, tablet mobile. Let's do that. Next. Okay, so let's look at our media query here. Still you It's going to put in 100 because I don't have any gas and it's going to kind of fill it up probably. Here you go go. A little bit smaller, bigger 321. How cool are we? All right. And that is the kind of really big takeaway for this video is we're using the exact same thing. Okay. We have to do some styling to make it kind of looks like a website. We made some boxes but to do it with structure. All we really need to do is we need to add these two bits. Really we just need these two. Okay to get them in line and then to wrap onto the next line And then we just said at this different size, I want to change that. I don't want to be with anymore of 30%. It's gonna be 45. So we don't really say to rose or two on a row. We just kind of make it so that that happens by giving it a size that only allows for two to fit. All right, a couple of little things. One that I ignored is down here at mobile. You'll notice that there's still a white line around the outside. Okay. That's one of the first things I did, I'm like, man, that's annoying. Okay. So by default, you know like the default the H1 is black and it's times new Roman and it's nice and big and bold. It's the same with the body. The body has a global of margin. I can't I don't even know what it is but I always go through and set margin to zero. Okay, So that there's none around the outside at any of you. Okay. I didn't want it for any of them and it gets it from the top from the sides and from the mobile gets it right around the outside. It's nice and kind of joined up because on mobile you want every pixel counts right to get as much detail as you can into that width. Now we did it here and we're fighting with the defaults. Okay, so that is a really good opportunity to say actually I'm doing this, I'm about to build out some CSS resets myself. How about I just use that CSS reset? We already have. Okay, and we already got one. Remember we've got one, so I'm gonna delete that so it'll come back. Okay, I've got one. Remember the Rhys Meyers one. Okay, so I'm just going to copy and paste that and use that. So I'll show you what I do. Now as I dig around in my files for an old folder I'd go into here and say remember project to on my desktop there. Was that CSS reset? I'm just gonna copy it. Find my project three minds on my desktop. I had some shortcuts to speed things up. I'm just going to paste it in here, add it to my CSS Okay, it's a link. It's a link and it's a six S one and it's not called style so it's called CSS If you delete the text in here, it should hopefully suggest it CSS reset and I've totally done it wrong and you're like he's done it wrong. If you haven't gay, we'll discuss what I've done because it's actually done done. We wanted got rid of the margin around the outside for all the views. It also got rid of the giant text. Okay, it's now just a regular old size now, what it didn't do or what's going to run into problems later on Is let's say that I want to start the H1. So I go, Alright, each one now you are going to be a font size of let's say something big. 100 pixels. Okay, good awesome. Check it. Hmm, ticket, check it not working. Why is it not working? Okay, pause it. Have a think about it. Um pause it your own paws now. Okay, You didn't pause it? I know you didn't. It's this thing. Okay, they're in the wrong order. Okay, so my style is being applied. Remember the flow kind of goes along and it says alright, B and H one of font size 100 then this one loads. Okay, And if we have a look at that and take it over here, it says H one is a font size of 100%. Any other things that are telling you what to do? No, that thing is making us just go to 100% of the one. M Okay, So we're just gonna make sure the order is right way around. So you is there now that shortcut, you can just cut it and paste it Okay, above it. But if you click in it anywhere and hold down the option key on a Mac. Ok. On a pc. No highlight the whole line. Okay? And hold down the option key on a Mac OK. On a pc can you see I can kind of just tap my arrow key as long as I hold down my option or or alternate pc. I can just kind of move this thing along. Okay, So make sure the CSS reset first, then do that now. My phone size nice and big. I don't want get the idea to save it. Alright, So that's the kind of real foundation for our responsive website. There's a lot more to do. Okay. But that's the core of it. We're using flex box, which we kind of know or a little bit about already and we're using medical berries to kind of turn bits of CSS on and off. All right. I hope you're feeling good about responsive web design. I'll see you in the next video.