Jak to zrobić — responsywne obrazy
Dowiedz się, jak stworzyć responsywny obraz za pomocą CSS.
Elastyczne obrazy automatycznie dostosowują się do rozmiaru ekranu.
Zmień rozmiar okna przeglądarki, aby zobaczyć efekt responsywności:
Jak tworzyć responsywne obrazy
Krok 1) Dodaj kod HTML:
Przykład
<img src="nature.jpg" alt="Nature" class="responsive">
Krok 2) Dodaj CSS:
Jeśli chcesz, aby obraz skalował się zarówno w górę, jak i w dół podczas reakcji, ustaw width
właściwość CSS na 100% i height
na auto:
Przykład
.responsive {
width: 100%;
height: auto;
}
If you want an image to scale down if it has to, but never scale up to be larger than its original size, use max-width: 100%
:
Example
.responsive {
max-width: 100%;
height: auto;
}
If you want to restrict a responsive image to a maximum size, use the max-width
property, with a
pixel value of your choice:
Example
.responsive {
width: 100%;
max-width:
400px;
height: auto;
}
Go to our CSS Images Tutorial to learn more about how to style images.
Go to our CSS RWD Tutorial to learn more about responsive web design.