Why Can't I Add Margin or Paddding
Hello, frustrated people we can't add margin to the top of our button. We've styled in a tag and we want to push it either from the top margin or the bottom margin but it's not working. Why is it not working? It's because the display property is set to in line. So the quick version of this video is just put display in line block on your button and make sure you save it and then you can do it hang around for this whole video because we're going to talk about the different display properties block in line, block in line and we're going to do some fancy CSS where we connect a couple of classes and a tag together. Are you ready? Let's add top margin to a button. Alright. So remember in the last video we had problems putting padding or sorry, margin above this. Okay. And it's something to do with its display property. So I've created this like little throwaway bit of html. Okay, so you don't have to do this, you can play along if you want. But it's just a just a plain old text html document...
. We're going to talk about the main there's lots of display properties. We're going to talk about the main ones that will affect you as a kind of beginning web designer and which is in line and block. So there are some things that are displayed by block by default and what that means is let's look at a p tag with some some text actually let's add a chunk of text. So Lauren but in Another one is an H one. That's my default, what's called block level. Okay. And all this really means is let's add a couple more and I'm going to put in an unloaded list, which is a bullet point list with some list items, but I want like 10 of them. Okay. And inside of this, I'm going to put in items. Okay. So these are all block level. What that means is if I look at this, can you see that guy pushes that guy down onto his own line? He's his own block of stuff. This is a guy as a big block as well. All of these guys in their own little block, they push each other over the opposite for these guys are in line. Okay. And they're useful for things like let's say an attack. So I'm gonna put in a space tag. Okay. And this one's going to hash and it's going to be my link. Okay. And it's an in line. Okay. Which is giving us our problem, the difference between in line is can you see it didn't push everybody else are a Okay. Plays well with others. It works in line. Whereas block says you have to be in your own line online in line with an image if I need to add an image here. Okay, So I? M g the sources, images slash that one in going to give it a size, give it a height at least it's not too big. You can do heights kind of in the html which is kind of weird. Okay. It's in line so you can change them around. Okay. You can say actually I would like up here in my style. I'm not using a CSS sheet for this particular one just to save some time. So I'm going to say I want the images to be ah image please to be displayed property of let's be in line block actually know to be block. Okay. You block things out. You are now all by doing his own thing. Cool. So one of the properties for a tag here because it's in line. Okay. By default. Is that you can't put a height, you can do left and right. I can say actually I want an a tag that has um I want a big old margin on the right so imagine Imagine right, that works perfectly. 200 pixels. So look so it's got a big margin to the right. Okay. But I can't do a big old margin to the top, which we already know from our last video. Let's go 100 pixels to the top please. Doesn't do anything you like. Doesn't push it 100 pixels down. What you can do though is you can say actually a tag I'd like you to stop being in line and I want you to be a display. Okay. Of I don't want it to be blocked because block in this case would kind of not do what I wanted to do. Man having trouble. Come on, there we go because it's kind of pushing down to its own line. You're like actually it's kind of what I want. I want a bit of in between okay in the in between is I want you to stay in line okay in line but also be a bit blocky that does a bit of both. And basically what it's gonna do for us is it's going to stay in line. Okay so it's still on that same line as our paragraph. Let's get rid of the get rid of the image tag. He's making everything look a bit confusing. Okay so stay in this paragraph but allow me to do things like hitting okay or margin top. So they all have their natural ability. Say these list items. Remember these guys really want to be on their own lines, They're called block level. They're actually called, what are they called? I've got a special one for them. Okay so list items, we're going to say display please and they've got this one called where is there one list item which does the same as block. Okay with a few extra perks. And so instead of being blocked I want you to be in line and let's have a little look at what it does. See the list items are all stacked on the same line now there'll be lots of times where you need to leave it as the default. Occasionally though you're like actually just just be part of the gang. I want H one with a P tag right next to it because I've done some cool design stuff and I need to implement that. Whereas headings really want to be on their own line because they are block elements. Does that kind of help to recap? Okay, eight eggs by default are in line okay. Which means they stay on the same line as everybody else tags. H one's block. Okay there a display block property so they all be on their own line. But if you want a bit of both in line, block is a great little bit of both bitter burden line, better block and mainly what it's going to allow us to do now is we're gonna go back to this page, double click you that will kick you, drag him around, you go over here. Okay. Is I'm gonna say to my where are you? My button? I'd like you to be now I'm not going to do it for all of them because I could say at the top here I want all eight tags to be in line block but I'm not committed to you know, I don't want to do that for all of them. I'm just going to do it for this one and you're gonna be in line block block. Block block go now I get to do a margin at the top. Imagine top and we're going to put in. I have no idea. 20 pixels. Let's have a look. Not this one genius. All right. This one's not working save all. Have a little look still not working my button. Alright. So it's not working for the class applied to my A tag. So what I'm going to have to do is say actually I want there to be an A tag with my button applied. This is still not going to work. Oh this is a good juicy bit of information. So if I grab these two king and I say you would like you to do that. It's probably still not going to work. Still not cool because what's happening is what it's looking for in terms of the selector that I just made is that saying I want to find my button inside of an attack but it's not inside. I've got an a tag that is my button. Okay. It's not inside of it. Like we've done in the past where we've got you know hair box, an H. One that's inside here A box that is inside my main inside of it. It's actually just an a tag with a label of my button. So how do you fix that? Okay. It's weird spaces means kind of shows you like this kind of bread crumbs of like my button is inside of the attack. Okay. Whereas if I joined them up so there's no space between them, it says an a tag that is in my button, apply this stuff, let's save it, see if it works, it's still not working, come on, it's still not working. What else do we do? Alright I had a brain bender there and I'm leaving it in the course because it's really useful. Brain bender. I thought I knew what I was doing, I was like yeah so we just do this and we can join them up and that's why it was broken and it still wasn't working okay the reason it wasn't working, like I was adjusting this, I'm like man that works, I was checking syntax. The reason it wasn't working code was perfect. It was because we did this little throw down course. Okay I opened this up, remember the little test of one and I opened it up and kind of tested it in the browser and I made a connection between venus code and this page and then I just closed it down and went on my business and went on with this one and closed it down. And then I started and then what I didn't realize well what I forgot is that that connection that live connection got broken between my original page here and the s code because I kind of went off and did something else. Can only kind of tethered to one at a time. So now I'm gonna wear this, going, scratching my head going, I don't know how this works. Okay. And that's because I yeah, I went to this other page previewed it now, I'm going to have to close it down, open it back up so that the tether and connection between my new, well the existing site now I will show it to me a bit flustered. I am okay. So now it works alright. So we learned a few things. I want to wrap it up and I want to leave in the badness in there. Just you'll run into that problem. And it's one of those things where you're like, it's just not working. I'm going to bed and you wake up in the morning and we'll start working. Like it wasn't working last night. I promise. It's because you've closed down and reopened that up. So we learned a couple of things we learned about displays. Okay. And we displayed block which is our kind of block level stuff. That's why we say block level tag selectors when I've been talking okay, You've got in line okay. Which is things like our image tags and our tags. There's lots of in line um attributes elements, but there's some of them do a bit of both. That's what we wanted in this case on my button to allow me to do some margin on the top and the other nice thing. We worked out was this other bit of way of writing? CSS So we've done commas, okay, we did it here. Where are we comments? We said I'd like you to I'd like you to target card one and card to and card three. So commas do the ends if you put a space between things trying to find one that has a space now there's got to be one. Do we even have one? We do. So I want p tags inside of cards and apply this stuff, but only if there's a P tag inside of it. This one here is I would like an a tag with this class applied to it and you can kind of use that like it's applied to it literally like it's stuck right next to it. It's applied to the side. No space space bad. Alright. And we also learned you need to restart your browser preview. If you jump between different projects, go with dan. Getting lost in front of people. Hope it's well you will use it as a learning experience. That's what I'll call it. All right on to the next video