CSS中content中的counter值分析_html/css_WEB-ITnose
有些CSS的特性,不经常使用.我认为CSS counters 也是其中之一,主要有两个原因:
1. 他们没有很多的例子
2. 代码可能稍微复杂一些.
CSS counters 允许动态的设置列表数字,类似一个排序列表.但是CSS counters是不一样的. 特色就是使用一个伪元素结合一些具体的counterCSS ,追加/前置一个动态的"count"到一个指定的元素集合.
这里一个代码例子
代码名称
.container { counter-reset: issues 0;}.issue:before { counter-increment: issues 1; content: "Issue " counter(issues, decimal); display: block;}
首先我们申明了计数的范围,在.container元素之内做自增.我们定义一个 "issues" 名称,其值从0开始.
其次,声明一个块状的伪元素:berfore ,设置 content属性的内容到前面.设置issues的自增量为1.
content属性值,我们使用counter()函数和一个字符串,有点类似JAVASCRIPT中使用函数,或者是其他编程语言.counter函数有两个参数: 之前申明的 "issues" 和 计数的方式,这样就形成了一个排序列表. 这个例子中,我们使用的是十进制(decimal)的数值.
如果你仍旧感到困惑,可以看看下面的解析图:
如果还不够,这里有其他的学习资源.
a) CSS Counters: counter-increment and Friends (Impressive Webs)http://www.impressivewebs.com/css-counter-increment/
b) How To Benefit From CSS Generated Content And Counters (Smashing Magazine)http://www.smashingmagazine.com/2013/04/12/css-generated-content-counters/
c) CSS Counter Styles Level 3 (W3C spec) http://dev.w3.org/csswg/css-counter-styles-3/
最后一个链接,是CSS的规范草案,里面还有很多的特性,当然得在支持的浏览器下进行学习.
counter还有其他的设置效果,其方式都是一样的,大家可以试试其他的显示模式.
本文属于吴统威的博客, 微信公众号:bianchengderen,QQ群:186659233 的原创文章,转载时请注明出处及相应链接:http://www.wutongwei.com/front/infor_showone.tweb?id=182 ,欢迎大家传播与分享.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...
