: 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 the anchor chain to connect, for example, a chestnut:
<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
: 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. (PS: About content Attribute usage: CSS3 's content attribute)
It should be roughly understood: Target's meaning is, if you don't know, look at this article: using The:target Selector
: What can target do
The simplest use: Target implementation tab switching.
Html:
<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:
. 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;
}
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.