CSS中的Content属性用于动态生成内容(在运行时);该属性可以与伪元素::before或::after一起使用,用于插入生成内容。下面本篇文章就来给大家介绍一下,希望对大家有所帮助。

CSS content属性的使用

content属性与 :before 及 :after 伪元素配合使用,用于定义元素之前或之后放置的生成内容。默认地,这往往是行内内容,不过该内容创建的框类型可以用属性 display 控制。

语法:

content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;

属性值:

● normal:设置默认值。如果内容属性正常,则设置内容。

Element::before|after { content: normal;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>p::before {content: "Welcome ";}a::before {content: normal;}</style></head><body><p id="a">you</p><p>you</p></body>
</html>

输出:

Welcome you
Welcome you

● none:不设置伪元素::before或::after的内容。

Element::before|after { content: none;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>p::before {  content: "Hello "; } p#a::before {  content: none; }</style></head><body><p>world!</p><p id="a"> world!</p></body>
</html>

输出:

Hello world!
world!

● initial:它将属性设置为其默认值。

Element::before|after {content: initial;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>p::before {  content: "Welcome "; } a::before {  content: initial; }</style></head><body><p>world!</p><p id="a">you!</p></body>
</html>

输出:

Welcome world!
Welcome you!

● attr:设置包含指定值的属性值。

Element::before|after { content:attr(href);
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>a::after { content: attr(href); } </style></head><body><a href="https://www.html.cn">点击这里! </a></body>
</html>

输出:

● String:用于在HTML元素之前和之后生成任何字符串。

Element::before|after { content: string;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style> /* 使用的字符串值 */ p::before {  content: "Hello "; } </style>
</head> <body> <p>World!</p>
</body>
</html>

输出:

Hello World!

● open-quote:它在元素前后生成左引号。

Element::before|after { content: open-quote;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style> p::before { content: open-quote; } </style>
</head> <body> <p>Hello World!</p>
</body>
</html>

输出:

"Hello World!

● close-quote:在元素前后生成右引号。

Element::before|after { content: close-quote;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style> p::after { content: close-quote; }p::before { content: open-quote; }</style>
</head> <body> <p>Hello World!</p>
</body>
</html>

输出:

"Hello World!"

● no-open-quote:如果指定左引号,它将从内容中删除左引号。

Element::before|after { content: no-open-quote;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>p::before { content: open-quote; }p::before { content: no-open-quote; }</style>
</head> <body> <p>Hello World!</p>
</body>
</html>

输出:

Hello World!

● no-close-quote:如果指定右引号,它将从内容中删除右引号。

Element::before|after { content: no-close-quote;
}

示例:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><style>p::before { content: close-quote; }p::before { content: no-close-quote; }</style>
</head> <body> <p>Hello World!</p>
</body>
</html>

输出:

Hello World!

● inherit:继承自其父元素。

Element::before|after { content: inherit;
}

浏览器支持

content属性支持的浏览器如下所示:

● Google Chrome 1.0

● Internet Explorer 8.0

● Firefox 1.0

● Safari 1.0

● Opera 4.0

推荐阅读:

php服务器

php5下载

layui框架

CSS的content属性怎么用?相关推荐

  1. 网页使用Font Awesome图标字体时,css定义 content 属性

    网页使用Font Awesome图标字体时,css定义 content 属性必不可少,如下所示: .icon:before {     content: '\f005';     font-famil ...

  2. css的content属性,以及如何通过css content属性实现css计数器?

    <!DOCTYPE html> <html> <head><meta charset="UTF-8"><title>cs ...

  3. CSS中content属性的妙用

    前言 本文讲解CSS中使用频率并不高的content属性,通过多个实用的案例,带你由浅入深的掌握content的用法,让代码变得更加简洁.高效. 定义 W3school中这样定义: content 属 ...

  4. css的content属性

    content属性一般用于::before.::after伪元素中,用于呈现伪元素的内容.平时content属性值我们用的最多的就是给个纯字符,其实它还有很多值可供选择. 1.插入纯字符 <st ...

  5. [css] CSS content属性特殊字符有哪些?

    [css] CSS content属性特殊字符有哪些? 今天在做开发的时候,需要用到CSS的content属性,加入一些特殊字符来实现网页效果.但是特殊字符那么多,怎么可能记得住,所以谷歌百度搜索之后 ...

  6. 常用的HTML和CSS content属性特殊字符归纳

    今天在做开发的时候,需要用到CSS的content属性,加入一些特殊字符来实现网页效果.但是特殊字符那么多,怎么可能记得住,所以谷歌百度搜索之后找到了一个比较全的,在这里进行归纳备忘,为了和我有相同需 ...

  7. 【CSS系列】被忽略的content属性

    CSS的 content属性,大家应该都不陌生,很多时候我们都使用过,一般情况下你看到最多的用法无外乎这样两种:一种用于清除浮动,一种用于我们经常使用的字体图标. .clear:after {cont ...

  8. css4个伪元素,CSS_CSS3中的content属性使用示例,CSS中主要的伪元素有四个:befo - phpStudy...

    CSS3中的content属性使用示例 CSS中主要的伪元素有四个:before/after/first-letter/first-line,在before/after伪元素选择器中,有一个conte ...

  9. css:before和after中的content属性

    css有一个属性叫做content.content只能使用在:after和:before之中.它用于在元素之前或者元素之后加上一些内容 就像这样: .email-address:before { co ...

最新文章

  1. 发布Web应用程序时发生的“xx.aspx.cs文件不存在”错误
  2. static 关键字作用
  3. 语言专升本必背代码_2020年【山西省专升本】,专升本专业与考试科目,专升本招生院校,专升本报名流程大全!...
  4. 电气期刊论文实现:热电联产经济调度【有代码】
  5. CSS控制所有浏览器水平居中和控制链接不换行的效果
  6. 如何在centos中找到安装mysql_centos上如何安装mysql
  7. 三星s4 android 6.0吗,快了 三星手机适配Android 6.0时间公布
  8. 初始JavaScript,世界上最流行的语言之一!
  9. 在线编程 - PyPool小站启动记
  10. adobe reader XI打开大约十几秒就闪退问题解决方法大全
  11. 商学院计算机系篮球策划书,篮球训练营策划书.doc
  12. Windows 10 安装 Maven
  13. 在Windows下搭建WAMP环境
  14. 基于阿里云盘的文件分享系统
  15. PHP获取MP3时长类
  16. js制作走马灯和选项卡
  17. GB_T28181-2016.pdf
  18. 2018-2019 ACM-ICPC沈阳(C,J)
  19. 什么是模块化 ? 模块化的好处
  20. Watir vs. SilkTest

热门文章

  1. 黑客是如何攻击目标电脑的
  2. 标注工具——VGG Image Annotator (VIA)
  3. c#程序连接oracle失败问题
  4. matlab中0.1见方,square,square怎么读?
  5. qs大学计算机专业排名,2015年QS世界大学计算机专业排名
  6. matlab nctool使用,感知器和BP网络设计及应用技术总结.doc
  7. 如何使用Facebook进行选品使用
  8. [HNOI2011] 卡农 题解
  9. wince5+2440的睡眠和唤醒
  10. html语言怎么让字横过来,css怎么让文字竖着排列?