css3如何利用选择器在页面中插入所需内容 (附代码)

您所在的位置:网站首页 h1快捷键 css3如何利用选择器在页面中插入所需内容 (附代码)

css3如何利用选择器在页面中插入所需内容 (附代码)

2023-05-25 09:34| 来源: 网络整理| 查看: 265

本篇文章给大家带来的内容是关于css3如何利用选择器在页面中插入所需内容 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1 使用选择器来插入内容

使用after或before选择器,在选择器的content属性中定义要插入的内容,当插入内容为文字的时候,必须要在插入文字的两旁加上单引号或者双引号。

h2:before{ content:‘COLUMN’;} 登录后复制2 指定个别元素不进行插入

使用content属性的none属性值

h2.sample:before{ content:none;} 登录后复制3 插入图像文件 h2:before{ content:url(mark.png);} 登录后复制4 将alt属性的值作为图像的标题来显示

在content属性中通过指定“attr(属性名)”的形式 ,可以将某个属性的属性值显示出来。

img:after{ content:attr(alt); display:block; text-align:center; }登录后复制5 使用content属性来插入项目编号 (1)在多个标题前加上连续编号

1、在content属性中使用counter属性值来针对多个项目追加连续编号

:before{ content:counter(计数器名);}(使用计数器来计算编号,计数器可任意命名)

2、还需要在元素的样式中追加对元素的counter-increment属性的指定,为了使用连续编号,需要将counter-increment属性的属性值值设定为before选择器或after选择器的counter属性值中所指定的计数器名。

{ counter-increment:before选择器或after选择器中指定的计数器名 }

h1:before{content:counter(mycounter);} h1{counter-increment:mycounter;}//1、2、3.......登录后复制(2)在项目编号中追加文字h1:before{content:‘第’counter(mycounter)‘章’;}//第1章大标题、第2章大标题.........登录后复制(3)指定编号的种类

1.用before选择器或after选择器的content属性,不仅可以追加数字编号,还可以追加字母编号或罗马数字编号。

content:counter(计数器名,编号种类)

2.可以使用list-style-type属性的值来指定编号的种类,如大写字母编号时,使用 “upper-alpha”属性,指定大写罗马字母时用“upper-roman”属性。

h1:before{content:counter(mycounter,upper-alpha)‘.’;}// A.、B.、C.、登录后复制(4)编号嵌套h1:before{content:counter(mycounter);}//1(1、2、3...)、2(1、2、3...)、........ h1{counter-increment:mycounter;counter-reset:subcounter;}(将中编号进行重置) h2:before{content:counter(subcounter);} h2{counter-increment:subcounter;margin-left:40px}登录后复制(5)中编号中嵌入大编号h2:before{content:counter(mycounter)‘-’ counter(subcounter)‘.’;}//1-1、1-2登录后复制(6)在字符串两边添加嵌套文字符号

1、可以使用content属性的open-quote属性值与close-quote属性值在字符串两边添加诸如括号、单引号、双引号之类的嵌套文字符号。

2、open-quote属性值用于添加开始的嵌套文字符号,close-quote属性值用于添加结尾的嵌套文字符号。

3、在元素的样式中使用quotes属性来指定使用什么嵌套文字符号

h1:before{ content:open-quote; } h1:after { content:close-quote; } h1{ quotes:"(" ")" }//形如: (标题)登录后复制

相关推荐:

CSS3系列一(概述、选择器、使用选择器插入内容)_html/css_WEB-ITnose

怎么在css3在页面中插入内容

以上就是css3如何利用选择器在页面中插入所需内容 (附代码)的详细内容,更多请关注php中文网其它相关文章!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3