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

Conteúdo do Curso

CSS Fundamentals

CSS Fundamentals

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

bookWorking with Images

We know that images play a crucial role on a web page. It helps to show the content effectively and clearly. Sometimes, the content image may have a size that is either bigger or smaller than the container it is intended to be displayed in, or its aspect ratio may be different from that of the container. We will consider how to show an image in the best manner.

object-fit

object-fit specifies how an image should be resized to fit its container.

  • fill stretches the image to fill the container, regardless of its aspect ratio. This may cause the image to be cropped or distorted;
  • contain scales the image to fit the container while preserving its aspect ratio. This may result in empty space around the image if the container and the image have different aspect ratios;
  • cover scales the image to completely cover the container while preserving its aspect ratio;
  • none displays the image at its original size, regardless of the size of the container. This may cause the image to overflow the container;
  • scale-down scales the image down to fit the container if it is larger than the image's natural size, or displays the image at its natural size if it fits within the container.
html

index

css

index

js

index

copy

object-position

object-position specifies the position of the image inside its container. It accepts two values: a horizontal value and a vertical value or we can use reserved words.

html

index

css

index

js

index

copy
What does the `object-fit` property do?

What does the object-fit property do?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 3
We're sorry to hear that something went wrong. What happened?
some-alt