Tutoriel CSS

CSS ACCUEIL Présentation CSS Syntaxe CSS Sélecteurs CSS CSS Comment faire Commentaires CSS Couleurs CSS Arrière-plans CSS Bordures CSS Marges CSS Rembourrage CSS CSS Hauteur/Largeur Modèle de boîte CSS Aperçu CSS Texte CSS Polices CSS Icônes CSS Liens CSS Listes CSS CSS Tables Affichage CSS CSS Max-width Poste CSS Index Z CSS Débordement CSS Flottant CSS Bloc en ligne CSS Alignement CSS Combinateurs CSS Pseudo-classe CSS Pseudo-élément CSS Opacité CSS Barre de navigation CSS Listes déroulantes CSS Galerie d'images CSS Sprites d'image CSS Sélecteurs d'attributs CSS Formulaires CSS Compteurs CSS Mise en page du site Web CSS Unités CSS Spécificité CSS CSS !important Fonctions mathématiques CSS

CSS avancé

Coins arrondis CSS Images de bordure CSS Arrière-plans CSS Couleurs CSS Mots-clés de couleur CSS Dégradés CSS Ombres CSS Effets de texte CSS Polices Web CSS Transformations CSS 2D Transformations 3D CSS Transitions CSS Animation CSS Info-bulles CSS CSS Style Images Réflexion d'image CSS Ajustement d'objet CSS Position d'objet CSS Masquage CSS Boutons CSS Pagination CSS CSS plusieurs colonnes Interface utilisateur CSS Variables CSS Dimensionnement des boîtes CSS Requêtes média CSS Exemples CSS MQ Boîte flexible CSS

CSS réactif

RWD Introduction Fenêtre RWD Affichage de la grille RWD Requêtes multimédia RWD Images RWD Vidéos RWD Cadres RWD Modèles RWD

Grille CSS

Grille d'introduction Conteneur de grille Élément de grille

CSS SASS

Tutoriel SASS

Exemples CSS

Modèles CSS Exemples CSS CSS Quiz Exercices CSS Certificat CSS

Références CSS

Référence CSS Sélecteurs CSS Fonctions CSS Audit de référence CSS Polices sécurisées pour le Web CSS CSS animable Unités CSS Convertisseur CSS PX-EM Couleurs CSS Valeurs de couleur CSS Valeurs CSS par défaut Prise en charge du navigateur CSS

Images de style CSS


Apprenez à styliser des images à l'aide de CSS.


Images arrondies

Utilisez la border-radiuspropriété pour créer des images arrondies :


Paris

Exemple

Image arrondie :

img {
  border-radius: 8px;
}
Paris

Exemple

Image encerclée :

img {
  border-radius: 50%;
}

Images miniatures

Utilisez la borderpropriété pour créer des images miniatures.

Vignette :

Paris

Exemple

img {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
  width: 150px;
}

<img src="paris.jpg" alt="Paris">

Vignette sous forme de lien :

Exemple

img {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
  width: 150px;
}

img:hover {
  box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}

<a href="paris.jpg">
  <img src="paris.jpg" alt="Paris">
</a>


Images réactives

Les images réactives s'ajusteront automatiquement pour s'adapter à la taille de l'écran.

Redimensionnez la fenêtre du navigateur pour voir l'effet :

Cinq terres

Si vous souhaitez qu'une image soit réduite si nécessaire, mais jamais agrandie pour être plus grande que sa taille d'origine, ajoutez ce qui suit :

Exemple

img {
  max-width: 100%;
  height: auto;
}

Conseil : En savoir plus sur la conception Web réactive dans notre didacticiel CSS RWD .


Centrer une image

Pour centrer une image, définissez les marges gauche et droite sur autoet transformez-la en blockélément :

Paris

Exemple

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

Images Polaroid / Cartes

Cinq terres

Cinq terres

Norvège

Aurores boréales

Exemple

div.polaroid {
  width: 80%;
  background-color: white;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

img {width: 100%}

div.container {
  text-align: center;
  padding: 10px 20px;
}

Image transparente

La opacitypropriété peut prendre une valeur comprise entre 0,0 et 1,0. Plus la valeur est faible, plus la transparence est grande :

forêt

opacité 0.2

forêt

opacity 0.5

forêt

opacity 1
(default)

Example

img {
  opacity: 0.5;
}

Image Text

How to position text in an image:

Example

Cingue Terre
Bottom Left
Top Left
Top Right
Bottom Right
Centered

Try it Yourself:


Image Filters

The CSS filter property adds visual effects (like blur and saturation) to an element.

Note: The filter property is not supported in Internet Explorer or Edge 12.

Example

Change the color of all images to black and white (100% gray):

img {
  filter: grayscale(100%);
}

Tip: Go to our CSS filter Reference to learn more about CSS filters.


Image Hover Overlay

Create an overlay effect on hover:

Example

Fade in text:

Avatar
Hello World

Example

Fade in a box:

Avatar
John

Example

Slide in (top):

Avatar
Hello World

Example

Slide in (bottom):

Avatar
Hello World

Example

Slide in (left):

Avatar
Hello World

Example

Slide in (right):

Avatar
Hello World

Flip an Image

Move your mouse over the image:

Paris

Example

img:hover {
  transform: scaleX(-1);
}

Responsive Image Gallery

CSS can be used to create image galleries. This example use media queries to re-arrange the images on different screen sizes. Resize the browser window to see the effect:

Cinq terres
Add a description of the image here
forêt
Add a description of the image here
Aurores boréales
Add a description of the image here
Montagnes
Add a description of the image here

Example

.responsive {
  padding: 0 6px;
  float: left;
  width: 24.99999%;
}

@media only screen and (max-width: 700px){
  .responsive {
    width: 49.99999%;
    margin: 6px 0;
  }
}

@media only screen and (max-width: 500px){
  .responsive {
    width: 100%;
  }
}

Tip: Read more about Responsive Web Design in our CSS RWD Tutorial.


Image Modal (Advanced)

This is an example to demonstrate how CSS and JavaScript can work together.

First, use CSS to create a modal window (dialog box), and hide it by default.

Then, use a JavaScript to show the modal window and to display the image inside the modal, when a user clicks on the image:

Aurores boréales, Norvège

Example

// Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
  modal.style.display = "block";
  modalImg.src = this.src;
  captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
}