Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Background Image | Decorative Effects
CSS Fundamentals
course content

Contenu du cours

CSS Fundamentals

CSS Fundamentals

1. Introduction to CSS
2. Text Styles
3. Box Model and Layout
4. Flexbox
5. Decorative Effects

book
Background Image

background-image property allows us to add an image as the background of an HTML element. The basic syntax is so simple:

As a value for the background-image property, we use url(), and inside these brackets, we specify the image url.

html

index.html

css

index.css

copy

background-repeat

It determines if the image will be repeated horizontally, vertically, both or not at all.

html

index.html

css

index.css

copy

background-position

background-position is used to set the starting position of a background image within an element's background area. This property allows us to specify where the background image should be placed and how it should be positioned relative to the element. We have to set the position on the x and y axis

html

index.html

css

index.css

copy

background-size

background-size specifies the size of an element's background image. It can be used to scale the image to fit the element, or to set a specific size for the background image.

  • auto keeps the background image at its original size (default);
  • cover scales the image to completely cover the element while maintaining its aspect ratio, possibly cropping parts of the image;
  • contain scales the image to fit entirely within the element while maintaining its aspect ratio, possibly leaving empty spaces;
  • value sets custom dimensions for the background image, such as 100px 50px or percentages like 50%.
html

index.html

css

index.css

copy

1. What does the background-image property do?

2. What does the background-repeat property do?

3. What property determines the position of an element's background image?

What does the `background-image` property do?

What does the background-image property do?

Sélectionnez la réponse correcte

What does the `background-repeat` property do?

What does the background-repeat property do?

Sélectionnez la réponse correcte

What property determines the position of an element's background image?

What property determines the position of an element's background image?

Sélectionnez la réponse correcte

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 5. Chapitre 2
We're sorry to hear that something went wrong. What happened?
some-alt