The CSS pseudo-class selector "Before" is used today to understand how it is used and how it is used.

Source: Internet
Author: User

I don't know if there are any small partners, like me, when I want to add a small icon or something inside an element,

Add your own <span> tags directly to the HTML document, or something else. or append an element to the element with JavaScript.

For example, we add the b element to the following Div ;

<div></div>

<div></div>

<div></div>

<div></div>

$ (function) {

  

$("div").append("<b>Hello</b>");

}

results:<div> <b>Hello</b> </div>

<div> <b>Hello</b> </div>

<div> <b>Hello</b> </div>

<div> <b>Hello</b> </div>

and CSS pseudo-class:before;

Div:before{content: ""; width:5px;height:5px;left:169px;top:2px;}

Note: Content: is an attribute with a value of information. (Can be a symbol, text);

Instance:

Html:

<div class= "left" >
<ul>
<li><a href= "#" > Brand profile </a></li>
<li><a href= "#" > Brand structure </a></li>
<li><a href= "#" > Brand definition </a></li>
<li><a href= "#" > Brand culture </a></li>
<li><a href= "#" > News </a></li>
<li><a href= "#" > Contact </a></li>
<li><a href= "#" > Memorabilia </a></li>
</ul>
</div>

Css:

. left{width:175px;}
. Left ul{padding-top:20px;border-right:1px dashed #333;}
. Left UL li>a{position:relative;display:block;width:175px;text-align:center;font-size:16px;line-height:45px;}
. Left ul li>a:hover:before{position:absolute;content: ""; width:5px;height:5px;left:169px;top:2px;}
. Left UL li>a:hover{color:red;}

Results:

after appearing small dots, and like text, set the color directly!

The CSS pseudo-class selector "Before" is used today to understand how it is used and how it is used.

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.