Learn CSS Practically

Explore a variety of different CSS exercises which includes margin, padding, styling, formatting and creating basic structures of a website.

CSS Introduction
CSS Properties

CSS Background

CSS background property is used to define the background effects on element. There are 5 CSS background properties that affects the HTML elements:

  1. background-color

  2. background-image

  3. background-repeat

  4. background-attachment

  5. background-position

1) CSS background-color

The background-color property is used to specify the background color of the element.

For example :

Run code

2) CSS background-image

The background-image property is used to set an image as a background of an element. By default the image covers the entire element. You can set the background image for a page like this.

For example :

Run code

3) CSS background-repeat

By default, the background-image property repeats the background image horizontally and vertically. Some images are repeated only horizontally or vertically.

The background looks better if the image not repeated multiple times.

For example :

Run code

4) CSS background-attachment

The background-attachment property is used to specify if the background image is fixed or scroll with the rest of the page in browser window. If you set fixed the background image then the image will not move during scrolling in the browser. Let?s take an example with fixed background image.

    background-attachment: fixed;  

5) CSS background-position

The background-position property is used to define the initial position of the background image. By default, the background image is placed on the top-left of the webpage.

You can set the following positions:

Now that you know ways to style background of any tag CSS, let's learn the selectors of CSS


Share this page on :