Stretching Background Image
everyone. It's time to replace our boring gray background with our exciting background image. It's cool. It's kind of stretchy fits in their covers, all the background looks neat. I'm not sure what we're eating but it kind of looks tasty. You'll, the irony is a vegetarian but the meat looks so good. Especially in these kind of photographs. Anyway, let's get in and work out how to do the background. Alright, to add our background image. It's a little bit strange. The previous video or one of the previous videos, we added our image and we added it to the html and it appeared at the top of our document here. And it's great. The only trouble with adding it to your html is that you can't have things over the top or at least not very easily. So we want it in the kind of background and we want it to be more of an effect rather than something you can interact with just kind of hiding at the back. So it's more like a style let's say. Okay, so we added in the CSS styles so we do it here in our s...
tyles dot CSS and we add it to. Which one should we add it to remember our tag that covers the whole background that we made gray. It's the same tag. Okay, so the body tag here, we made gray. We can leave gray there and I leave the background color there normally because sometimes it takes a little while for the image to load. So at least there's something in the background until it loads and the way to do it Well named okay. It's called background hyphen image. Nice. The one thing that isn't very clear is what to do next. Okay. And it's U R. L. It's one of those options in there. So you are l it's a background image, your RL inside of that bracket. Sorry. Yeah, the brackets you type where it goes. So it's going to be in images forward slash and as soon as you have the forward slash and the CSS it says, hey, do you mean this image? The logo And you're like, no, no, we're not that not that I'm a logo. I want another image that I've used for the background so I've saved it for you in your exercise files. So you need to come out to your finder, Find your exercise files, find project one there's one in here called background copy it. I'm using command C on a Mac control C on a pc. Just stop. You're going to paste it into this images folder along with the logo. Now, hopefully I can delete the ford slash. There you go. Type it back in and it says do you mean this guy, you're like, I do, that's the guy or girl. Let's put in our semicolon, it's safe and let's see if it worked and that might be enough. You might be like done, move on. But if you're like me and you see the moment. Kind of doesn't do exactly what I want, you might like it. Okay. But at the moment I wanted to kind of move. So if somebody's looking on a smaller screen that the image is still kind of centered, there's a really nice easy CSS class that we can use. Okay, we're not a class attribute. So it is called background another good one. Background size and this is one thing called cover. So background size cover will allow us to do that. Let's give it a go. Resize woo. Nice. Now see down the bottom that it repeats because the ratio of this thing is a bit weird and you know the image that we've got doesn't quite fit in there. So it has to do something at the moment it's repeating it. So let's have a look at getting rid of the repeat. It's going to be half our problem fixed. So we say background repeat. Okay, so background please. I'd like to set it to no repeat please. Awesome. Let's give it a go. It's gone. But it's great boxes there you've got to decide how much that annoys you. Okay? Because the next thing we need to do is a little bit kind of strange. And so to make this work okay, what you do is the body is the tag we've been working with, right? But there is an overarching tag over everything called html and to make that go away. Okay. You've got to put in another tag just above it and say I'd like the html tag To have a height of 100 height of 100 percent. That fixes that I'm not even sure why. But that's what we do, depends. Like I said sometimes in web design I can explain it to you and sometimes I can't. Okay, so there you go covering it fits. It's nice. And one more thing if you're getting picky is that it's kind of centered and stays in there but it's not quite centered. You're like why aren't you quite centered? You can mess around with the background, what is it called? Background. A line. If I spelled it Alright. Background alignment. No, it's background man, position. That's it. Okay, so background position and we've opened center semi colon and that should fix that. So now instead of it will go from the center rather than kind of left and right. Mm hmm. Yeah, I like it. Now one thing if you are following along on a really small screen, you're like, I can't even make it do it that dan. It's true. I just thought of that. Then I'm like if you have a really small screen, it's gonna be really hard to like drag it out big enough to make it do all the kind of re sizing bits. So that's something to know. I guess what you're doing then for like you probably can get away with pretty much all of that gone. And the trouble will be is when somebody like me with a giant screen opens it up and goes, hey, it's looking not looking nice. So if you are working on a really small laptop and you're like, I can't even test this stuff and later on and of course I'm going to show you how to like fake being a really big screen. But yeah, I just thought I'd add that there just in case you're like, I can't make that work, but it is potentially necessary. Alright, Background image is done and dusted.