About pseudo-classes: target

Source: Internet
Author: User

What is the target pseudo-class? Let's take a look at the explanation:

  The URL is followed by the anchor #, which points to a specific element within the document. The linked element is the target element, which is used to select the target element for the current activity .

As an example:

 <  html     >  <  a  href  = "#target"  >  point I </ a     >  <  div  id  = "Target"  ><  div  >  </ html  >  

Normally, a tag will follow a URL, but here we add not a URL, but an anchor point, when we click a, the URL of this page will be added "#target", and the ID target div block is in the current active state


So what is the use of this?

In fact, this is more useful, you can use this feature, do not use JS to achieve some interactive effect

Or the above code, add CSS to it

{    : none;  }  {    : block;    : 100px;    : 100px ; : 1px solid red;}           

If we do not click the a element, the DIV element does not show, if we click on the a element, the div is displayed as a 100*100, and has a red border of the block;

If we understand this simple usage, we can use it to implement something slightly more complicated, such as the ability to implement a free-switching tab bar, or a navigation bar that can be entered and exited.

Reasonable use of target pseudo-class can reduce the use of JS, not only to achieve page optimization, but also to make the code structure clearer

About pseudo-classes: target

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.