Tous les exemples de l'annexe CSS

Les effets de survol avec :hover

div#survol:hover {
  background-color:#000;
  color:#fff;
}
Survolez ce bloc pour voir l'effet :hover

Les pseudo-classes :first-child et :last-child

ul.groupe {
  display:inline-block;
  padding:0px;
  margin:10px;
}
ul.groupe li {
  display:inline-block;
  padding:5px;
  margin:0px;
  border-top:1px solid #000;
  border-bottom:1px solid #000;
  border-left:1px solid #000;
}
ul.groupe li:first-child {
  border-top-left-radius: 5px;	
  border-bottom-left-radius: 5px;	
}
ul.groupe li:last-child {
  border-top-right-radius: 5px;	
  border-bottom-right-radius: 5px;	
  border-right:1px solid #000;
}

Les transitions

ul.groupe li {
  background-color:#fff;
  color:#000;
  transition-property: background-color, color;
  transition-duration: 0.5s, 0.5s;  
}
ul.groupe li:hover {
  background-color:#000;
  color:#fff;
}

Les pseudo-éléments ::before et ::after

/* Pseudo-élément ::after */
a[target]::after {
  content:url(media/url_icon.gif);
  padding-left:5px;  
}

Ouvrir le site officiel de FontAwesome

/* Pseudo-élément avec Fontawesome */
a.external::after {
  content:"\f35d";
  font-family:"Font Awesome 5 Free";
  padding-left:5px;
  font-weight:900;
  display: inline-block;  
  color:#aaa;
}

Ouvrir le site officiel de FontAwesome

Construction d'une boîte fléchée

div#pointe {
  margin:20px;
  display: inline-block;
  border-width: 100px;
  border-style: solid;
  border-left-color:   #00f;  /* A gauche : bleu  */
  border-top-color:    #fff;  /* En haut  : blanc */ 
  border-right-color:  #f00;  /* A droite : rouge */
  border-bottom-color: #000;  /* En bas   : noir  */
}

Ouvrir l'exemple info-bulle

Une infobulle de démo


Les transformations CSS

transform: translate(50px, -10px);
transform: rotate(10deg);
transform: transform: scale(1.2);
transform: skew(30deg, 5deg);
transform: matrix(0.9,0.5,0.1,1,150,0);;
transform: rotate3d(0, 1, 0, 160deg);

Les transformations CSS en fonction du repère d'origine

transform-origin: center
Rotation 30°
transform-origin: top left
Rotation 30°
transform-origin: -50px 50px
Rotation 30°

Les animations sur les transformations

@keyframes rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes bump {
  from { transform: translate(-50px, 0); }
  to   { transform: translate(50px,  0); }
}
@keyframes rotate3 {
  from { transform: rotate3d(0, 1, 0, 0deg);; }
  to   { transform: rotate3d(0, 1, 0, 180deg);; }
}
animation: rotate 1s linear infinite
animation: rotate 1s ease-in-out alternate infinite
animation: bump 0.5s ease alternate infinite
animation: rotate3 1s linear alternate infinite;

Les empilements avec z-index

Plus la propriété z-index est élévée, plus l'élément se rapproche du premier plan

z-index:1
z-index:2
z-index:3
z-index:4

Pastilles rondes en CSS

Une pastille devient ronde avec un border-radius de 50%

div.pastille {
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background: #d00;
  color: #fff;
  font-size:20px;
  font-weight: bold;
  border: 1px solid #000;	
  border-radius: 50%;
}
1
2
3
4
5

Zones de rognage du contenu avec clip-path

Pour Safari, il faut dupliquer la propriété avec -webkit-clip-path

Ne fonctionne pas avec Internet Explorer

clip-path:none
clip-path: circle(33% at 65% 65%);
clip-path: ellipse(20% 40% at 60% 60%);
clip-path:polygon(40% 40%, 90% 40%, 90% 90%, 40% 90%)