CSS properties of attr ()

Source: Internet
Author: User
attr () Exactly, should not be a property, but a function of CSS, let us first look at the introduction of the MDN:

Summary

The attr () CSS function is used to retrieve the value of a attribute of the selected element and use it in the style Shee T. It can used on pseudo-elements too and, the value of the attribute on the Pseudo-element ' s originated Element is returned.

The attr () function can be used with any CSS property, but the support for properties and than content is experimental.

Simple translation, English proficiency is limited, mainly to the English than I have poor friends for reference, Master can ignore:

The CSS function attr () is used to get the property value of the selected element and is used in the style file. It can also be used in pseudo-class elements, in pseudo-class elements, and it gets the value of the original element of the pseudo-element.

The attr () function can be used with any CSS property, but in addition to the content, the rest is experimental (simply, unstable, not necessarily supported by the browser).

That specific how to use it, give everyone to raise a chestnut, a period of time just used, to the button to implement the prompt function, is the mouse put up, come out a little hint:

<p class= "wrap" >  <a href= "#" class= "BTN" data-tip= "click to answer" > a button </a></p>

. btn {  display:inline-block;  padding:5px 20px;  border-radius:4px;  Background-color: #6495ed;  Color: #fff;  font-size:14px;  Text-decoration:none;  Text-align:center;  Position:relative;}. Btn::before {  content:attr (data-tip);  width:80px;  padding:5px 10px;  border-radius:4px;  Background-color: #000;  Color: #ccc;  Position:absolute;  Top: -30px;  left:50%;  Transform:translate ( -50%);  Text-align:center;  opacity:0;  Transition:all. 3s;}. Btn::after {  content: ';  border:8px solid transparent;  border-top:8px solid #000;  Position:absolute;  Top: -3px;  left:50%;  Transform:translate ( -50%);   opacity:0;  Transition:all. 3s;}. Btn:hover::before {  top: -40px;  Opacity:1;}. Btn:hover::after {  top: -13px;  Opacity:1;}

Of course, attr () can also get more other properties, such as the href attribute in a tag, and so on, let's try it on our own.

More about CSS Properties attr () related articles please follow topic.alibabacloud.com!

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