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

Contenido del Curso

CSS Fundamentals

CSS Fundamentals

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

bookBackground 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

css

index

js

index

copy

background-repeat

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

html

index

css

index

js

index

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

css

index

js

index

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 - default value, which sets the background image to its original size;
  • cover - scales the background image to completely cover the element while maintaining its aspect ratio. This may cause some parts of the image to be cropped if the aspect ratio of the element and the image are different;
  • contain - scales the background image to fit the entire element while maintaining its aspect ratio. This may cause empty spaces to be visible around the image if the aspect ratio of the element and the image are different;
  • value - sets the width and height of the background image.

For this example, we will use the bigger picture than we need as we wish to consider the behavior difference of each value for the background-size property.

html

index

css

index

js

index

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?

Selecciona la respuesta correcta

What does the `background-repeat` property do?

What does the background-repeat property do?

Selecciona la respuesta correcta

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

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

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 2
some-alt