Contenido del Curso
CSS Fundamentals
CSS Fundamentals
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.
index
index
index
background-repeat
It determines if the image will be repeated horizontally, vertically, both or not at all.
index
index
index
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
index
index
index
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.
index
index
index
¡Gracias por tus comentarios!