Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Applying Background Images to Elements | Adding Decorative Effects with CSS
CSS Fundamentals
course content

Kursinhalt

CSS Fundamentals

CSS Fundamentals

1. Getting Started with CSS
2. Styling Text in CSS
3. The CSS Box Model & Spacing Elements
4. Mastering Flexbox for Layouts
5. Adding Decorative Effects with CSS

book
Applying Background Images to Elements

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

css

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.

css
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

css
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.

css
  • 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?

question mark

What does the background-image property do?

Select the correct answer

question mark

What does the background-repeat property do?

Select the correct answer

question mark

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

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 2
Wir sind enttäuscht, dass etwas schief gelaufen ist. Was ist passiert?
some-alt