How to Style Your Form
Hi there. Fun fact. Web design makes you better looking totally does. It's not really working for me personally, but it's definitely working for this form, ugly form. Good looking form. Okay, so exact same form. Just going to change the CSS There's some fun targeting that we need to do to attach ourselves to these guys and style them. We'll put some spacing between things, labels with gaps in them. We'll make our button look a little prettier. We'll update the sample text in here. Alright, let's get better looking. All right, we'll start with the text boxes here, the input text. So what is it called? So is my beginning of my form. So we're gonna start all the things inside of this down to. It's getting quite big. Here's the form. Okay. And this is my first one, not the label. We're gonna talk about the input text. Okay. And to do this in our CSS. Okay. We need to add some special syntax so it's input. Okay? But then you've got to put it in square brackets, not curly brackets, square br...
ackets. Okay. And you decide on what kind of type it is and in our case it's text. The type of text. Okay? You can kind of see it here. Basically we're just typing this at the input of these to the type equals text. So it's just a kind of different format here in CSS. Then we add our curly braces and that's how we style it. First of all, I'm going to add some padding around the outside just to make the text box a bit bigger. Okay. I want it to be kind of like 12 on the top and the bottom and I'll have 20 on. Okay, Yeah, top on the bottom, left and right. Save it. Let's have a little look and there you go. There's that one and you're like, I gotta do to this one as well because this one has a slightly different name. This has input of type email. So what we might do is just copy that and put a comma in. So I'll do both of these. Just gotta make sure this one is email. Cool muscle dude, text area while we're here. So same thing now, it's not quite the same thing. Okay, It's structured differently. Remember these input types were different from this weird thing we did. Text area was just kind of like its own tag. So the same that goes over here. So we just do text. Here we are. There it is there, that's all we need to do. So I want to start the text area to have a little look, it's all looking good. Got my padding, it's gonna look nicer. You can give these boxes widths. Okay, so all of these guys could have a width of, you could use percentages or pixels, let's say 40% Here, we go through all 40% of the available space. Now let's move the text that's inside of it. It's quite small and it's the wrong kind of font so we can do that as well. So we've targeted them, we're going to say font family and we'll use the one we've already used. We're using we're using Roboto. Doesn't pre fill it in. Gonna go steal it. Roboto, but he is Roberto. Thank you very much. Let's check it out. Okay, now it's Roboto just needs to be a bit bigger so far in size. I had it there, font size. Let's just look at one rim, see how it looks the same as the rest of them. Actually, I might make this the forms, do I make it a bit smaller? I feel like if I do, it feels good as a designer having just like a little bit of kind of hierarchy for, you know, big text, that's the most important and this is the next thing. And then these guys kind of step down another font size performs any tourists notoriously problematic for people that are visually impaired. Okay, So making it smaller and it's quite a light gray with skirting some accessibility issues. Alright, so we've got that that that's one of the things that might be driving you mad is this is on the same line as this. Okay, that's up to you. There's a couple of ways to fix it. We could we were using this wrapper. Okay, so I could say actually the label could be in its own wrapper, we'll do it together. Okay, just to show you the different ways because there's different times we need both of them. So there's label. Okay, can you just come out of that wrapper there he is there. Okay. And to have his own Okay, you go up here. I'm going to wrap them in my, what we call it? It's called input, input rapper. I can't put it there. We've got to wrap with abbreviation first, then put it in. Okay, so now he's on his own line. That line that's on the 2nd 1. Okay. We're starting to get messy in terms of the HTML. So that's our way. What we might do is a slightly I'll just show you a different way. Okay. What we could do, but it's probably not going to work is we could attack these labels. We could say label. I would like you to be on its own line. Do you do you remember This is like a pop quiz. Okay, pause it after I asked the question and see if you can work it out. I wanted to be on its own line at the moment. It's in line with this guy. Okay. How would I get him to go on his own line? Give it a go. All right. If you'll I have no idea. Remember that our display. Okay, by default. It's in line so we can say display block. Okay, so all labels that display block and that's going to work. But then you get down here and you're like actually I wanted these guys next to it. So not quite what I wanted. So what I might do is I might say I'll leave that there. But instead of using the label, I'm going to create my own one. We're going to say new line. No line. New line. Okay. So I'm going to use this and just apply it as a class to the labels specifically. So this particular one. Okay. Just at the just before the little tag ins I'm gonna say class of new line. Let's have a little look. So this guy has got his own line and what I might say is his new line with margin at the bottom of 20 pixels too much. Let's say 10 pixels. Yeah, that works for me. Make sure you close it off. The other thing I might do is just looks better I think with more spacing between them. Okay. And I probably need some space after this p tag. We'll look at that in a second. But let's do this one. So yeah, I get to reuse this one and because I've kept it reasonably generic. Okay, I could use new line throughout my whole website. Doesn't have to be for this particular form. So I could say you I want it on email as well. Okay. So before this little label closes, you're going to have a class of a new life. Cool. Alright. What next consent to the Moore Lab? There's a few other starting I want to do 40%. Is it big enough? You can make it 100%. Okay, so where is it for us? Code we sent us to our with all these fields to have a width of. There you go. Now they go across um It's kind of 100% plus the padding. Remember we've added 20 either side or 30. Okay, so we've added that plus the 100%. So it ends up going too far. Another pop quiz. How do we get it? We could start minus sing it. Okay, we could minus, we could take off, we can make it 97% and fake it. Remember there was a property that magically did it for us. It kind of takes the overall size and minuses off margins and padding had a weird name. I'll introduce it again. Do you remember pause it? Think give it a test even. It's really hard to remember. I always forget it is called, what is it called? Box sizing. Box sizing, go border box and hopefully it'll do the work for us. There you go, sliced off the padding fits in nicely. Need to add a label to this one here, which I haven't done yet. It's okay. One of the things I want to do all of this looks okay. We'll do some fun stuff in a second. But the spacing between these two. I'm happy that they're on their own line. So let's get them pushed apart a little bit so we could cheat. My instant lazy brain says cheat and in this course we're like, we shouldn't show you how to cheat, but I'm gonna show you the cheap because you'll come across it. Some other lazy person will do it and you will touch them. You'll say, I can't believe they did that. And you put an ampersand and you put it in a non breaking space semicolon. Okay. That is there because we know if we put in spaces, right, I'll delete this. Okay. If I put it in a space like this, it gets ignored by the code. He doesn't care if you got space as it returns, it's still the same. But you can, let's undo that undo it even. Okay, I could go not breaking space. I can paste a few of these in. Okay. And it will push across. The only problem with that is you're doing in the html and the styles that it's kind of, it is nasty gay but works put it in there because hey, my brain went, let's just put that in and then I thought I'll show it to you because you're going to run into are websites that people have done it lazy people like me to kind of do it for spacing. So we should do it in code. Okay, so in this case we're going to create a new class. I have a few helper classes that I use. Okay, so this one's just gonna be, I'm gonna call this one very generic. This is going to be called margin. What is this one? I want margin on the right to left. I'm not even sure I want margin. I'm going to apply it to the label, margin on the right to push over across. So it's going to be called margin. Right? I'm gonna call this one a because I'll do a few of them. Okay. And this one here is going to be as you can imagine. Imagine rights Okay. of I'm going to put in 20 pixels just check out what this one is. Okay, so I'm going to use it because I don't trust my spelling on my typing at least copy that. And I'm going to go over here and apply it to this label just before it closes. I'm going to say you have a class of this one when you are copying and pasting, be sure not to grab the full stop because the full stop doesn't it's not needed over here. If you leave it in, let's have a little look. Didn't appear. It's not working Okay. Sometimes it can appear in the html. Anyway, so there's my little class there. I've added it to it and if you want to target, say all radio buttons. You got lots of radio buttons. Okay. And you want to say push the spacing away from here. Okay you've got to kind of remember the weird input, remember input and then it's square brackets then you work out the type you're trying to target. Okay. And we're done to do the radio ones at the moment. There's a radio, Yeah, type radio. That's how you target those fellas. And then I'm going to say all right, I want a little bit of margin to the right as well mara, right, and you can see how you can get really lazy with the helpers. Okay? You just type in ma to kind of get it close and then I just started typing are and then that's all I needed. Okay, you got me close enough to it. All right. And I want just maybe 10 pixels to the right of them just to kind of open them up a little bit because we're just doing a really simple form. You might have a big giant form. Last thing we'll do is style this fire away button. I'll submit button. Okay, so in here actually I've accidentally renamed my this should be male, not mail too. I don't have a male too. Alright, so submit button you can start styling the input and type submit over here. Okay, that would work. Um We're gonna not be lazy, we're gonna be resourceful. We're going to add a class of col my button. It's a little while ago now, I can't remember. There you go now. You'll notice that it's not quite exactly like the button we had on our homepage. Okay. It's very similar. So we've kind of got close but there are some styles that we're gonna have to turn off in particular for this button for me it's close enough. Okay. But so you might make another style and start applying it. But the submit button has this kind of weird outline, you're gonna have to turn off and around the corner, you're going to have to turn off so either might create another class, start with my button and then add some border border styles of none rounded corners of zero or I'm just gonna leave mine All right, I do need some space underneath it. So what I might do the form in general. I need some stuff at the top and at the bottom. So I might just start to form might say form please. Can you have some margin? So margin. We'll use our we'll use max resolution will type margin And we'll use our shorthand. So top and bottom are going to be, I don't know, 40 pixels And the left and right are going to be zero. See how that goes. There's a bit of the top bit at the bottom. I'm happy enough with it. Are you happy? I'm happy we got a form missing a label. It's okay. We've styled it got a sweet dropdown menu, you can style that as well. Okay. Again just input. Actually it's different, it's called select not an input. Alright. So that's gonna be, it performs. There are kind of just scratched the surface in terms of forms and we did a little hack for some PHP to send us an email, but there are lots more as a bit of a rabbit warren of forms. But yeah, good overview. I hope we'll leave the forms there for now and I will see you in the next video.