Come fare per - Immagini reattive
Scopri come creare un'immagine reattiva con CSS.
Le immagini reattive si regoleranno automaticamente per adattarsi alle dimensioni dello schermo.
Ridimensiona la finestra del browser per vedere l'effetto reattivo:
Come creare immagini reattive
Passaggio 1) Aggiungi HTML:
Esempio
<img src="nature.jpg" alt="Nature" class="responsive">
Passaggio 2) Aggiungi CSS:
Se vuoi che l'immagine ridimensioni sia in alto che in basso in base alla reattività, imposta la width
proprietà CSS su 100% e height
su auto:
Esempio
.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.