Pseudo-elements: before,: After example

Source: Internet
Author: User
xhtml
<strong class="amount">700</strong>
css
. Amount: Before {content: "$ ";}
. Amount: After {content: "Yuan ";}
Originally, only 700But added CSS.What will happen afterwards?
$700 USD
Thinking- ::before, ::afterUse principles of pseudo-element selectors

::ForCSS3. The standard representation of the signature element mainly refers to:OfOthers(Pseudo-classes) Partition, not the original CSSThe two are used in the same way.:Indicates that (Firefox,Opera,Safari,...) All are supported.

::beforeMatchingcontnetFeature (Property) The characters indicated in the delimiter, which can be found inSelectorsAdd the string (including spaces) to the beginning of the specified element."$ "), CSSTherefore, this string is regarded as an element, so it can be written to various design cells of the string;::afterIn the same way, the difference is to add the last. We can think of the above example as an element that adds two real instances, for example:

xhtml
<Strong class = "amount"> <span >$ </span> 700 <span> RMB </span> </strong>

Add CSS.Let's see the changes,

css
.amount {color:red;}

This will be the whole$700 USDAll are changed to tokens, because::before, ::afterAdded stringShard Element, Still due.amountThe content of the element, so it depends on the performance,Shard Element $, RMBIt is also a token. Change CSS slightlyLet's see:

css
. Amount: Before {content: "$"; color: Blue ;}
. Amount: After {content: "Yuan"; color: Blue ;}

OnlyShard ElementThe result is as follows:$700 USDThe previously defined delimiter still exists.::before,::afterThere is no limit on the two at the same time, or you can specify only one before or after.

Note that::before, ::afterCooperationcontentGeneratedShard ElementString, which indicatesLine Content Encoding Element(Inline emements), That is, the text watermark (Text-level).

Tocontent The feature also has a more useful string addition method. Since most of the compiler's support during the writing is incomplete, I will discuss it later, if you have any interest, you can explain it to W3C the content property first.

Pseudo-elements: before,: After example

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.