Vertically Center Content
Hi there. This video is about centering vertically. Super easy using flex box. This text here is inside this larger purple color here and it's centered vertically. Same with this image. It's kind of hovering here in the middle. It's jumping now and work out how to do it. All right. Remember in the last video we kind of got this centered ish. We put padding at the top and the bottom to kind of fake it. Okay, So what we're going to do now is use flex box because it's super easy to do. So what we want to do is our other mock up, we want the content to let these little boxes I added Uh to be kind of centered in this kind of main div here. Now, the thing there's a couple of things you need to do, first of all, the main div that it's going inside of. So these two little guys are inside. Okay, this main div needs a height. Okay, min height. So it's gotta mean height of 300, which is going to work perfectly. And then what we need to do is we need to tell her to do something. We want to use the...
align items align items to the center, let's save it. Let's check it out. Cool. Huh? Okay. So by default, we saw in the last video, if you don't if you just turn the flex box, flex box on it kind of stretches to fit its parent. Okay, remember that. Let me just comment that out and save it actually remember our contents only that big, but it stretches out so you can kind of override it by doing different things. So we're saying actually go center? So it assumes all right, we'll give up all the extra stuff and we'll just be right in the middle there. Go on. Now. This is the one to bookmark. This is by far the one I emailed the most about like, hey, how did you send her in the middle again? Okay, vertically. It's yeah, it's hard to remember to do. But anyway, how would you remember? Okay, either bookmark this video or in your cheat sheet, you kind of just go through this and you have a look and you're like, is this what I want justify content to the end. It's not what I want, justify content center. That's an interesting one because it centers all your content. Most people don't use that. They'll just do text align center and we did that earlier for our image. That works just as good. Anyway, um spacing between we did that knows you just kind of scroll through and I love that this is all visual because I'm like, you know, look at that. We could do a line flex end. Okay, but we're doing center. Let's test flex end. Just just just good. So our parent tag, let's do flex end. To flex start flex start is by default preview. Cool, flex and flex start would be useful if you didn't want it to stretch out? Let's have a look. Do you see it goes to the top without kind of filling up the rest of the space. Cool. I'm going to undo that. There's a couple of things we want to do before we go just to tidy up because we just got placeholder text before we do that. Let's just recap. And for this to work, it needs a parent. Okay, So these two girls in the middle here or guys, they are my little Children and I want to do the effect to them. So you apply it to the parent so you don't have a parent and say you're watching this video later on and you're like my website doesn't have a parent tag. Just put one around. Just wrap it around and say call it wrapper tag and all you're gonna do is apply a height to it and you're going to apply where is the display flex has to be on. Okay. We turn dials on by default in the last video. So if you're just watching this video that has to be on as well. So needs a height display flex and then align items to the center and everything inside of it. We'll do that. All right, what do I want to do now? I want to start removing some of my colors. So where is it? I want to get rid of the main color. Save it. We'll just keep testing this as we go along. You can see the background. That's the color that we used for the container and I'm going to get rid of that now as well if you're finding them not very useful anymore, we're going to start getting rid of bits where else will get rid of the blue and very hard color to see that one cornflower blue and mint green cream. Goodbye mint cream. Cool because that's what I want and we're going to fill in the background in a little bit with this big background gradient in this image and next I want to replace out the text here and the image. So the text is easy, it's in your exercise files, okay? There's one in their project to and there's one called text or is it project to text. Okay. And in here never mobile bike repairs, you could equally type that in, save it and this is the body copy kind of bit underneath the p tag, make sure when you are doing this, I often will accidentally lose see that last angle brackets and I do this and then it all goes wrong. Just be careful. You can see it's put in this weird break in here because I copied and pasted from this because there's a soft return in there, it won't matter when it goes through to the other side. It just kind of ignores it. You might not like that though, you can just tidy it up if you want and if you want to be on two lines, that's a good point. We've never covered that. So if you wanted to be on two separate lines because it won't it'll just be on one big line Even if you put a return in or 10 returns, it doesn't matter. Okay. So what you need to do is put it into two individual P tags. I'm going to cut that out to try and make it nice and clear. There's that guy. All right, put my full stop. So I need another P tag in here. Okay, so p I'm going to paste it in this. There you go. Two separate tax. Alright. We're gonna replace this text with an image. So where are we? I don't want any of that in there. I'm going to put an image tag So img and where is it coming from? We haven't actually put it in our local folder yet. So you remember our exercise files, there's one called. I have no idea what it's called. Wait there there is. There. We're going to use this one here. The service a leave this one for the moment. We're going to look at that later on. Okay, just use this one. Image bike repair service. A I'm going to copy it. Oh, a actually no, he's the one without the A. It doesn't really matter but humor me for the moment. Use this one. We're going to look at these when we do responsive images in a little bit. I'm gonna put it in my desktop in my project to I want to put it in it Images folder. Okay so a new folder in here called Images. Open it, paste it in. Don't worry about that. I'll remove him in a sec. He's not meant to be there, hang on. There you go. He's gone. And now in V. S. Code we should be able to stipe images slash and there it is there. Don't forget to put in some all text. Okay. Remember the old text is what gets loaded and what you know if the image doesn't load but mainly is what google likes to see and I put in person servicing a bike in Dublin because it really does explain the photograph but really um stuffing good keywords into my website so that I can potentially rank better. Alright so that's it. Let's have a little look at it now. Alright, got an image and we've got some text that we need to format which we'll do in a little bit. Alright. It's looking terrible then let's it's going to get better I promise but for now that's it. I will see you in the next video