Getting div tags onto one line using Flexbox in HTML & CSS
Hey there in this video, we're going to talk about stacking boxes next to each other. Seems kind of simple in the previous kind of project and I kind of stacked everything all on top of each other for a reason. Just to make that part of the course nice and easy to get it started. But you're very quickly going to want to put things next to each other, which is quite natural by default. Okay. If you start stacking things, I made these little boxes, okay? And I stuck them in my html and by default they really want to be on top of each other and you're like, just go there. Okay, so we're going to use something called flex box to get them to stack next to each other. Like we want. All right, you ready? I'm ready. Let's go. Okay. Before we can add our flex, we need to create a couple of containers. So I'm going to create inside this class um of cards out of tag here, we're going to create three new devices inside of it. Okay. And we're gonna call it card one. Okay, we're gonna have another o...
ne. Actually, I'm just gonna cheat copy paste, paste. I want three of them card one, I'm gonna call them card 12 and three. Now I'm giving them specific names because later on in the course I'm kind of forward thinking a little bit, I want they're actually to do different stuff because this one has a background of that image. This one has a different image. That one has a different image. They do different things. Okay. So I'm gonna give them specific names. If your cards are all generic, you wouldn't have to give them separate names anyway. Well, at least they could be all called card one. Now let's start all these cards. Okay. So we'll start with card one and then we'll copy and paste it a few times. So we'll give it a background color in a minimum height the same as this. Okay. We'll change the color to be something even lighter. Actually. We're gonna switch color schemes because Okay, my green plan is not working out perfect. I'm going to go for the I'm not even sure. I want to say watermelon. No grapefruit. Anyway, pink. So we're gonna go this one. It's been far too long picking a color and we're going to use the same height but minimum height in case it needs to get bigger and we're gonna give it a width because I want three of them in there. Right. So I want you could give it a pixel width. Okay. It's called an absolute with you could work out all right. I want to go one was it 1024. Okay. Divided by three and some petting for it and you can do that or a nice easy trick is it doesn't matter whether you use pixels or in this case we can do a width of You do this for everything. Not just for these cards so we can do with of percentages. So if we did 33.3% it's gonna kind of other than we lost a little bit there. But it'll fit through across easy. So let's have a little look at what we got save all. There we go. There's my first one so I'm going to duplicate that a few times twice. Who? I'm sure what you're gonna get there. Alright, so I've got three of them. You are going to be you and you are going to be three. Alright. And I'll change the colors. Okay. Mm hmm. Later not enough change then this one here is going to go super late. Alright. So I've got three different shades of my pink and by default they always line up on top of each other. Okay. Which is just the way it works in code. If you don't do anything else, they will all try and stack nicely on top of each other. And that's where flex box is going to come into this this particular video, we're gonna stick them nicely together. And the way flex box works is it's kind of new for like if you've done a previous course of mine, we were floating left and right. That still works. But it's just harder to implement because you've got a clear float and those types of things If you've never heard of flutes and don't worry, flex box just makes things easier and it's new for HTML five and it works on all browsers at the moment, which is cool. All you need to do is there needs to be a parent tag Okay. That's why with this group, these cards have their own like little gang okay or own little parent. Okay. So the parent tag, these are the Children. Okay because they're inside the parent. This parent needs to be told to flex and everybody inside of it will nicely line up together. It's just a lot easier to do. So find cards. Okay. And we're gonna say display thank you were going to say flex, make sure the semi colon goes at the end and hopefully all the work's done for us. Look at that Now if you're new to web design you're like, yeah, that's cool. Nice work. Let's go if you've done it before and you're like me and like stop. No, that is amazing. I love it floating before clearing floats with such a drama. Now it's not, but I won't go on because you probably knew and you probably don't care that much as much as I do. But the thing to recap is that because I could have got away with not having this rapper here because there's no real reason because the main finishes and then these guys start. Okay. But I wanted this rapper because or this parent because I want to apply flex to it. You can't apply them individually to the dudes and dude ettes. Okay. You have to do it to the parent. Thanks dad. So that's what we're gonna do with flex box at the moment. You can rush off and learn more about flex box. I've kind of folded into this course to try and I don't know not throw it all into one video so there is more coming about flex box and but for the moment, most of the time I'm using it is just to get things to stack on its own line. Yeah, that's it for this video. I'll see you in the next one.