伪元素::before和::after
来源:互联网 发布:美工设计经理岗位职责 编辑:程序博客网 时间:2024/04/30 00:40
2.10.3 伪元素::before和::after
对于“::before”和“::after”来说,大家并不多见,但“:before”和“:after”,或许不会陌生,因为清除浮动就使用这两个伪类。
“::before”和“::after”不是指存在于标记中的内容,而是可以插入额外内容的位置。尽管生成的内容不会成为DOM的一部分,但它同样可以设置样式。
要为伪元素生成内容,还需要配合content属性。例如,假设在页面上所有外部链接之后的括号中附加它们所指向的URL,无须将URL硬编码到标记中,可以结合使用一个属性选择器和“::after”伪元素。
- a[herf^=http]::after {
- content:"(" attr(herf) ")";
- }
如今在CSS3中使用“::before”和“::after”越来越多见,例如给链接添加ICON的效果。Font Awesome站点制作的ICON就使用伪元素“::before”和“::after”,下面截取部分代码。
- /* Font Awesome styles
- ------------------------------------------------------- */
- [class^="icon-"]:before,
- [class*=" icon-"]:before {
- font-family: FontAwesome;
- font-weight: normal;
- font-style: normal;
- display: inline-block;
- text-decoration: inherit;
- }
- a [class^="icon-"],
- a [class*=" icon-"] {
- display: inline-block;
- text-decoration: inherit;
- }
- /* makes the font 33% larger relative to the icon container */
- .icon-large:before {
- vertical-align: middle;
- font-size: 1.3333333333333333em;
- }
- .btn [class^="icon-"],
- .nav-tabs [class^="icon-"],
- .btn [class*=" icon-"],
- .nav-tabs [class*=" icon-"] {
- /* keeps button heights with and without icons the same */
- line-height: .9em;
- }
- li [class^="icon-"],
- li [class*=" icon-"] {
- display: inline-block;
- width: 1.25em;
- text-align: center;
- }
- li .icon-large:before,
- li .icon-large:before {
- /* 1.5 increased font size for icon-large * 1.25 width */
- width: 1.875em;
- }
- ul.icons {
- list-style-type: none;
- margin-left: 2em;
- text-indent: -0.8em;
- }
- ul.icons li [class^="icon-"],
- ul.icons li [class*=" icon-"] {
- width: .8em;
- }
- ul.icons li .icon-large:before,
- ul.icons li .icon-large:before {
- /* 1.5 increased font size for icon-large * 1.25 width */
- vertical-align: initial;
- }
- .icon-bullhorn::before {
- content: "\f0a1";
- }
- .icon-beaker::before {
- content: "\f0c3";
- }
效果如图2-50所示。
0 0
- 伪元素:after和:before
- 伪元素::after和::before
- 伪元素::after和::before
- 伪元素::before和::after
- 伪元素::after和::before
- 伪元素::after和::before
- Before和:After伪元素
- 伪元素:before和:after
- 伪类元素:before 和 :after
- 关于伪类元素:before和:after
- 理解:Before和:After伪元素
- 学习使用:before和:after伪元素
- 学习使用:before和:after伪元素
- 理解伪元素:Before和:After
- 学习使用:before和:after伪元素
- 学习使用:before和:after伪元素
- 关于伪类元素:before和:after
- 关于伪类元素:before和:after
- 史上最全的Linux系统 ISO下载
- weblogic 修改开发模式为生产模式
- 解决Visual Studio “无法导入以下密钥文件” 错误
- Mysql 常见问题
- JAVA多线程和并发基础面试问答
- 伪元素::before和::after
- android自带图片资源图标一览,android.R.drawable
- 前台与后台
- 关于su 、su - 及 sudo的区别
- UIAlertController详解及用法
- CC2541设置外部时钟为32Mhz
- Android性能优化典范
- Linux基础 第二部分 文件、目录与磁盘格式
- 使用JAVA反射机制将简单JAVA been对象、数组转化为对应的Json串