This article will introduce an interesting pseudo-element in CSS What is ::marker CSS pseudo-element Using it, we can add a pseudo-element to an element to generate a bullet or number. Normally, we have the following structure: <ul> <li>Contagious</li> <li>Stages</li> <li>Pages</li> <li>Courageous</li> <li>Shaymus</li> <li>Faceless</li> </ul> By default, no special styles are added, and its style is roughly like this: Using li { padding-left: 12px; cursor: pointer; color: #ff6000; } li::marker { content: '>'; } We can transform the small dots into anything we want: Some limitations of the ::marker pseudo-element First of all, the only element that can respond to Of course, it doesn’t mean that there is no way to use it on other elements. In addition to list items, we can use Secondly, not all style attributes can be used for the styles within pseudo-elements. Currently we can only use these:
::marker application exploration For example, we often see some decorations before the title: Alternatively, we can use emoji expressions: Both are very suitable for display using <h1>Lorem ipsum dolor sit amet</h1> <h1>Lorem ipsum dolor sit amet</h1> h1 { display: list-item; padding-left: 8px; } h1::marker { content: '▍'; } h1:nth-child(2)::marker { content: '😅'; } CodePen Demo -- ::marker example ::marker can change dynamically Interestingly, For example, this is the effect of being unhappy if not selected and happy if selected: li { color: #000; transition: .2s all; } li:hover { color: #ff6000; } li::marker { content: '😩'; } li:hover::marker { content: '😁'; } CodePen Demo -- ::marker example Use with counter It can be observed that In If you don't know much about Suppose we have the following HTML: <h3>Lorem ipsum dolor sit amet.</h3> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> <h3>It is very hard to grow a baby.</h3> <p>Does it seem fair to say that there is no such thing as a voluptatibus, a debtor?</p> <h3>I am so happy!</h3> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> We use body { counter-reset: h3; } h3 { counter-increment: h3; display: list-item; } h3::marker { display: list-item; content: "✔" counter(h3) " "; color: lightsalmon; font-weight: bold; } The effect is as follows, which realizes the effect of automatically adding serial numbers to CodePen Demo -- ::marker example at last This article introduces what Well, this article ends here, I hope it helps you😃 More wonderful CSS technical articles are collected in my Github -- iCSS. They are continuously updated. Welcome to click a star to subscribe and collect. If you have any questions or suggestions, please feel free to communicate with me. This is an original article, and my writing skills are limited. If there is anything wrong in the article, please let me know. This is the end of this article about CSS ::marker to make text numbers more interesting. For more relevant CSS ::marker content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: A brief summary of how to write paths when HTML files introduce external CSS files
>>: Implementation of HTML to PDF screenshot saving function
This article shares the specific code of js to ac...
Uninstall the old version of MySQL (skip this ste...
The previous article introduced the installation ...
Table of contents 1. Get a random Boolean value (...
HTML provides five space entities with different ...
1. Introduction to Middleware 1. Basic concepts E...
This article describes how to build a phalcon env...
This article shares the specific code of using ca...
Sometimes, we need to use the hyperlink <a> ...
Table of contents mapState mapGetters mapMutation...
This article uses an example to describe how to i...
Table of contents 1. Quick understanding of conce...
These two attributes are often used, but their di...
1. Docker Compose Overview Compose is a tool for ...
You can view the container logs through the docke...