CSS :target Pseudo-class
- Previous Page :root
- Next Page :user-invalid
- Go to the Previous Level CSS Pseudo-class Reference Manual
Definition and Usage
CSS :target
Pseudo-classes are used to set the style of the current active target element.
Tip:A URL with a hash followed by an anchor name links to a specific element in the document. The element being linked to is the target element.
Example
Example 1
Set the style of the current active target element:
:target { border: 2px solid darkorange; background-color: beige; }
Example 2
Create a Tab Menu:
.tab div { display: none; } .tab div:target { display: block; }
Example 3
Create a Modal (Dialogue Box):
/* Modal 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 the target is active */ .modal:target { display: table; position: absolute; } /* Modal */ .modal-dialog { display: table-cell; vertical-align: middle; } /* Modal 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); }
CSS Syntax
:target { css declarations; }
Technical Details
Version: | CSS3 |
---|
Browser Support
The numbers in the table specify the first browser version to fully support the pseudo-class.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4 | 9 | 3.5 | 3.2 | 9.5 |
- Previous Page :root
- Next Page :user-invalid
- Go to the Previous Level CSS Pseudo-class Reference Manual