Target Implementation tab switching effect in CSS3

Source: Internet
Author: User

: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.