: What is Target?
MDN is described in this way: target
The:target Pseudo-class represents the unique element, if any, with an ID matching the fragment identifier of the URI of The document.
In document, you can set up anchor chains, for example:
CSS code copy content to clipboard
- <a href= "#tab" >Test:target</a>
- <a href= "#tab2" >test 2:target</a>
- <div id= "tab" >this is a tab.</div>
- <div id= "TaB2" >this is another tab.</div>
There are two anchor chain connection: #tab和t #ab2. When you click on the anchor link, you will jump to the corresponding DIV:: Target is for these div. Add CSS
CSS code copy content to clipboard
- : target{
- color:red;
- }
- #tab: target::after{
- Content: "Tab1"
- }
Click on the anchor link, the text of the corresponding Div is changed to red, in addition, insert a text behind the #tab.
Effect jab: https://jsfiddle.net/dwqs/cL8rawov/
It should be understood roughly: Target's meaning.
: What can target do
The simplest use: Target implementation tab switching.
Html:
xml/html code to copy content to clipboard
- <div class= "Tab-control" >
- <a href= "#tab1" >tab1</a>
- <a href= "#tab2" >tab2</a>
- <a href= "#tab3" >tab3</a>
- </div>
- <div class= "Tabs" >
- <div id= "tab1" class= "tab" >this is a tab1</div>
- <div id= "tab2" class= "tab" >this is a tab2</div>
- <div id= "tab3" class= "tab" >this is a tab3</div>
- </div>
Css:
CSS code copy content to clipboard
- . Tab-control a{
- Display:inline-block;
- Text-decoration:none;
- Color: #FFF;
- height:20px;
- width:40px;
- Text-align:center;
- line-height:20px;
- Background:rgba (70,121,189,0.75);
- }
- . Tab-control a:hover{
- Background:rgba (70,121,189,1);
- }
- . tabs{
- position:relative;
- border:1px solid red;
- height:200px;
- width:135px;
- Overflow:hidden;
- }
- . tab{
- height:100%;
- width:100%;
- }
- : target{
- Display:block;
- }
Look at the effect: Demo
Of course: Target's functionality is not limited to this. Hide elements, create lightbox, and so on. MDN gave a lot of Demo:more demo.
You can also open the brain hole, haha.
Browser support
For: Target pseudo class, browser support is still good.