CSS : Sélecteur de cible
Exemple
Mettez en surbrillance l'ancre HTML active :
:target
{
border: 2px solid #D4D4D4;
background-color: #e5eecc;
}
Définition et utilisation
Les URL avec un # suivi d'un nom d'ancre renvoient à un certain élément dans un document. L'élément auquel est lié est l'élément cible.
Le :target
sélecteur peut être utilisé pour styliser l'élément cible actif actuel.
Version: | CSS3 |
---|
Prise en charge du navigateur
Les nombres dans le tableau spécifient la première version du navigateur qui prend entièrement en charge le sélecteur.
Selector | |||||
---|---|---|---|---|---|
:target | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
Syntaxe CSS
:target {
css declarations;
}
Plus d'exemples
Exemple
Créez un menu à onglets :
.tab div {
display: none;
}
.tab div:target {
display: block;
}
Exemple
Créer un modal (boîte de dialogue) :
/* The modal's background */
.modal {
display: none;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
/* Display the modal when targeted */
.modal:target {
display: table;
position: absolute;
}
/* The modal box */
.modal-dialog {
display: table-cell;
vertical-align: middle;
}
/* The modal's content */
.modal-dialog .modal-content {
margin: auto;
background-color: #f3f3f3;
position: relative;
padding: 0;
outline: 0;
border: 1px #777 solid;
text-align: justify;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}