Backgrounds
Objectives:
Discuss the
backgroundproperty.
File Location
You should be located in the following files:
DotNetProjects
└── HTMLCSSPreWork
└── 1-HTML-Basics
└── 2-CSS-Basics
05-backgrounds.css
05-backgrounds.htmlDescription
You've probably already guessed what background does; it changes the field upon which the content of an HTML element resides in.
Let's go ahead and grab a cool picture to use as a background. Go here and save the image in your 4-assets folder, with the rest of your resources.
Sample Code
Let's add this sample code to your background.html file:
CSS Sample Code
Let's add this sample code to your background.css file:
Discussion
Much like fonts, backgrounds are another aspect of an application that can make or break the user experience. You can see that implementing background isn't as challenging as many other properties, however, consider carefully what the result will be. Neutral colors, grayscales and blurred backgrounds tend to be more accessible to the average user.
It's important to note how the file path works here: ../3-assets/upfeathers.png. When we use ../, that means back up one level from the current directory, then, go look for the 3-assets folder. Inside there, look for upfeathers.png. If we wanted to look two directories above, we could say ../../.
Challenge
Find an image you like, and try using it as a background. Explore other options like gradients as backgrounds.
Last updated