How to vertically center content in a html div tag using flexbox css

This lesson is exclusive to members

Course contents
SECTION: 4
Project 2: Bike Repair Website 6:12:48
SECTION: 6
Project 4: Bootstrap Yogurt Website 3:35:39

Questions

You need to be a member to view comments.

Join today. Cancel any time.

Sign Up

Course info

128 lessons / 17 hours 5 projects Certificate of achievement

Overview

Hi there, my name is Daniel Scott and together we’re going to learn how to build professional responsive websites. which look good on mobiles, tablets and desktop screens.

We will build 4 sites together...
  • a simple but elegant restaurant website.
  • a bike repair website. 
  • a responsive portfolio website.
  • a Bootstrap website.  

We cover everything you need to build your first website. From creating your first page through to uploading your website to the internet. We’ll use the world’s most popular (and free) web design tool called Visual Studio Code.

There are exercise files you can download and then work along with me. At the end of each video I have a downloadable version of where we are in the process so that you can compare your project with mine. This will enable you to see easily where you might have a problem.

We will delve into all the good stuff such as how to create your very own mobile burger menu from scratch learning some basic JavaScript and jQuery. 

 You will...
  • Learn how to work with responsive images and icons. and stunning full screen background images and probably one too many gradients. 
  • Learn how to create forms and to choose great fonts for your website. 
  • Learn how to work with Bootstrap 4 to easily add carousels, cards and complex looking menus. 
  • Setup a domain name with hosting so that your website is live on the internet for others to see.  

There are fun class projects for you to work on which will enable you to practice what you learn. By the end of this course you’ll have a great understanding of important web design topics like HTML5, CSS3, Flex box, Responsive design and Bootstrap.   

If that all sounds a little too fancy - don’t worry, this course is aimed at people new to web design and who have never coded before. We’ll start right at the beginning and work our way through step by step. 

Who am I? 

I’m Dan, and I’ve been building websites for about 15 years now. I am award winning instructor, and have won a MAX Master award for the last 2 years in a row at the prestigious Adobe Max conference.

Time to upgrade yourself?
Sign up for the course and let’s learn how to build responsive websites.

Course duration 16 hours 42 mins
Daniel Scott

Daniel Scott

Founder of Bring Your Own Laptop & Chief Instructor

instructor

I discovered the world of design as an art student when I stumbled upon a lab full of green & blue iMac G3’s. My initial curiosity around using the computer to create ‘art’ developed into a full-blown passion, eventually leading me to become a digital designer and founder of Bring Your Own Laptop.

Sharing and teaching are a huge part of who I am. As a certified Adobe instructor, I've had the honor of winning multiple Adobe teaching awards at their annual MAX conference. I see Bring Your Own Laptop as the supportive community I wished for when I was first starting out and intimidated by design. Through teaching, I hope to bring others along for the ride and empower my students to bring their stories, labors of love, and art into the world.
True to my Kiwi roots, I've lived in many places, and currently, I reside in Ireland with my wife and kids.

Certificates

We’re awarding certificates for this course!

Check out the How to earn your certificate video for instructions on how to earn yours and click the available certificate levels below for more information.

Downloads & Exercise files

Download Exercise Files Download Completed Files

Transcript

Hi there, this video is about centering vertically. Super easy using Flexbox. 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. Let's jump in now and work out how to do it. 

Remember, in the last video we kind of got this centered, we put padding at the top and the bottom to kind of fake it. So what we're going to do now is use Flexbox because it's super easy to do. So what we want to do-- where's our other mockup? We want the content - I want to delete these little boxes I added. - to be kind of centered in this kind of Main Div here. Now 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 who are inside, this Main Div needs a height, Min-height. It's got a Min-height of 300, which is going to work perfectly, and then what we need to do is we need to tell it 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. By default-- we saw in the last video, if you don't, if you just turn the Flexbox on it kind of stretches to fit its parent. Remember that, let me just comment that out. I'll save it actually. Remember, our content is 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, I will give up all the extra stuff, and will just be right in the middle here. 

Now this is the one to bookmark, this is by far the one I get emailed the most about. It's like, "Hey, how  did you center in the middle again, vertically?" Yeah, it's hard to remember to do, but anyway. How would you remember? 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, that's not what I want. Justify Content Center, it's an interesting one, because it centers all your content. Most people don't use that, they'll just do text-align:center. We did that earlier for our image, that works just as good, but anyway. Space in between, we did that, no. So you just kind of scroll through, and I love that this is all visual, because I'm like, "No, oh, look at that." See, we could do align, flex-end. but we're doing center, this test flex-end, just because. 

So our parent tag, let's do flex-end. I can do flex-start, flex start is by default. Cool, flex-end. Flex-start would be useful if you didn't want it to stretch out, let's have a look. You see, it goes to the top without kind of filling up the rest of this space. 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. 

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 going to do is apply a height to it, and you're going to apply, where is he? Display Flex has to be on. We turned ours on by default in the last video, so if you're just watching this video, that has to be on as well. So it needs a height, display flex, and then align items to the center, and everything inside of it will do that. 

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 just keep testing this as we go along, and see the background, that's the color that we used for the container. 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. What else? We'll get rid of the blue and-- it's a very high color to see that one. Corn flower blue and mint green, cream; applying the cream. Cool, because that's what I want. 

We're going to fill in the background in a little bit  with this big background gradient and this image. Next I want to replace out the text here and the image. So the text is easy, it's in your Exercise Files. There's one in there, Project2, and there's one called Text; where is it? Project2 - Text. And in here, Nav - Mobile Bike Repairs. You could equally type that in. Save it, and this is the Body copy, kind of a 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 brake in here, because I copied and pasted it from this-- because there's a soft return in there. It won't matter when it goes through to the other side, 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 we want to be on two separate lines, because it won't, it will just be on one big line, even if you put a Return in, or ten Returns, it doesn't matter. So what you need to do is put it into two individual P-tags. So I'm going to cut that out, let's try and make it nice and clear. There's that guy. All right, we have to stop. 

So I need another P-tag in here, so P, I'm going to paste it in this. There you go, two separate tags. We're going to replace this text with an image; so where are we? I don't want any of that in there. We're going to put in 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, in our Exercise Files there's one called, I have no idea what it's called. Wait there. There it 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. Just use this one, Image Bike Repair - Service A. 

I'm going to copy it. Oh, A, actually no, use 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 going to put it in my Desktop, in my Project2. I want to put it in the Images folder. So a new folder in here, click Images, open it, paste it in. Don't worry about that, I'll remove that in a sec, he's not meant to be there, hang on. There you go, it's gone. And now, in VS code, we should be able to start images/, and there it is there. 

Don't forget to put in some Alt text. Remember the Alt text is what gets loaded, and what-- if the image doesn't load, but mainly is what Google likes to see. And I put in a person servicing a bike in Dublin, because it really does explain the photograph, but really I'm stuffing good keywords into my website, so that I can potentially rank better. So that's it, let's have a little look at it now. We got an image and we've got some text that we need to format, which we'll do in a little bit. It's looking terrible, Dan, let's-- it's going to get better, I promise, but for now that's it, I will see you in the next video.
  • Powered by Marvin
  • Terms of use
  • Privacy policy
  • © Bring your Own Laptop Ltd 2024