02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Working with the background property

In the last lecture we learned how to work with the various background properties. In this lesson we learn about properties that contain multiple directions at the same time. By the end of this lesson, you will know how to add backgrounds into CSS.

Video Transcript

00:00Last lecture was a bit long.
00:02This one is gonna be way shorter.
00:04We're still talking about backgrounds.
00:06And in the last lecture, we saw backgrounds broken down
00:09into a lot of small components.
00:12In this lecture, we're gonna see how do we combine
00:14all those components together into the background property.
00:17So let's see it in action.
00:18This rule is throughout CSS.
00:21So what we're seeing in the last two lectures,
00:22we're gonna see over and over in CSS attribute rules.
00:28In last lesson, we saw all these different backgrounds
00:31and I'm just gonna go ahead and comment them out
00:33by just dropping them into our comment section.
00:37And what I literally wanna do next is I wanna basically see
00:42how could we take everything we've done so far
00:45and basically condense it all into one property
00:48which is called the background property.
00:51Now, right now we'll see that there is no background.
00:53I just removed it.
00:54So let's start over from our background property.
00:57Now, the background property, contrary to the
00:59specificalities of background color image
01:02and so on and so forth is very true to a lot
01:04of other CSS properties.
01:06So do please pay attention.
01:09A lot of times you'll have basically a mother property
01:13that could basically contain all the other properties.
01:16Now, this mother property which is called background,
01:18I could literally just put inside of it just a color.
01:22And if I just put a color, everything will work.
01:24I don't need to type background color.
01:26And really in a real world scenario,
01:29your preference is to only work
01:31with the background property and not the specifics
01:34unless you need to.
01:35But really in general, the less you type, the better.
01:38Now, in this case, if I wanted to,
01:40I could instead of putting a color,
01:42I could go ahead and just put inside here
01:44the background image literally with the same exact property,
01:47I would just set a property instead.
01:50And then I could go ahead here and click on refresh
01:53and we'll see that now we have our pattern
01:54instead of our background.
01:57Not only that, I could go ahead and set my color
01:59by putting my color first, then putting a space,
02:03and then putting our background color.
02:05Once I've done that, if I click on refresh again,
02:08you'll see that now we'll have the background
02:10with the color combined.
02:13The next item is I could literally,
02:14without writing the words repeat in the order
02:17that I've positioned my items right now,
02:18even though the order is not as critical,
02:20I could literally say, hey, I don't want any repetition
02:24and I'm gonna just put that there.
02:27And I want my item to be fixed as well,
02:30so I'm no repeat and it's fixed,
02:32and I could go ahead there and just click on refresh
02:34and you'll see that now my item is set in position
02:38and it's not moving, it's sitting right there on the top,
02:41but what if I really wanted to put it on the bottom
02:43just like we did in our sample?
02:45So as you guessed it, all I would have to do
02:47is just put your space and put that item values as well,
02:52literally just listing out all the different
02:54background options, all the different properties
02:57that I could put inside of a background,
02:58and if I just save this, go back and click on refresh,
03:01we'll see that now our background is gonna sit
03:03right there in the bottom as we would expect it to do.
03:06So literally all those 13, 14 minutes of talking
03:10that we went through all this,
03:12the properties you could literally do in one line,
03:15and this is true to many different CSS properties
03:18which we'll explore throughout this course,
03:20but even if you don't remember something,
03:22you'll see that in general,
03:23whenever you see a background dash something
03:26or a property dash something,
03:27you know that there's a high probability
03:29that there is a property that's called
03:31just that without the dash
03:33that would condense all those different options,
03:35and it's definitely something that you'd wanna consider
03:37because this is less code, a lot less code
03:40than all of this, it's less to type,
03:43and less to type means smaller files, smaller files means
03:46faster loading websites which is always a great thing.
03:49All right, so this is it about backgrounds
03:52and we're done talking about backgrounds,
03:53and in the next lecture we're gonna move on
03:55to the foreground and we're gonna see
03:56how could we actually change the color of text
03:59in HTML using CSS.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!