Jak na to – responzivní obrázky
Naučte se, jak vytvořit responzivní obrázek pomocí CSS.
Responzivní obrázky se automaticky přizpůsobí velikosti obrazovky.
Změňte velikost okna prohlížeče, abyste viděli responzivní efekt:
Jak vytvářet responzivní obrázky
Krok 1) Přidejte HTML:
Příklad
<img src="nature.jpg" alt="Nature" class="responsive">
Krok 2) Přidejte CSS:
Chcete-li, aby se obrázek zvětšoval i zmenšoval při citlivosti, nastavte vlastnost CSS width
na 100 % a height
na auto:
Příklad
.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.