栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

css的content属性的具体使用

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

1、插入纯字符




    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
 position: relative;padding: 10px;
 border: 1px solid #666;margin: 10px;
    }
    .content.only-text::before{
 content: '插入纯字符';
    }



    1、插入纯字符
    

2、插入图片




    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
 position: relative;padding: 10px;
 border: 1px solid #666;margin: 10px;
    }
    .content.fill-image::before{
 content: url('https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_86d58ae1.png');
    }



    2、插入图片
    

3、插入元素属性




    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
 position: relative;padding: 10px;
 border: 1px solid #666;margin: 10px;
    }
    .content.fill-dom-attr::before{
 content: attr(data-title);
    }



    3、插入元素属性
    

4、插入当前元素编号(即当前元素索引)

这个特性可用于活动页面的规则介绍。




    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
 position: relative;padding: 10px;
 border: 1px solid #666;margin: 10px;
    }
    .fill-dom-index li{
 position: relative;
 
 counter-increment: my;
    }
    .fill-dom-index li div::before{
 
 content: counter(my)'- ';
 color: #f00;
 font-weight: 600;
    }



    4、插入当前元素编号(即当前元素索引)
    
 
  • 我是第1个li标签
  • 我是li标签中的第1个div标签
  • 我是第2个li标签
  • 我是第3个li标签
  • 我是li标签中的第2个div标签
  • 我是第4个li标签
  • 我是第5个li标签

5、插入当前元素编号(指定种类)




    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
 position: relative;padding: 10px;
 border: 1px solid #666;margin: 10px;
    }
    .fill-dom-index2 li{
 position: relative;
 counter-increment: my2;
    }
    .fill-dom-index2 li div::before{
 
 content: counter(my2,lower-latin)'- ';
 color: #f00;
 font-weight: 600;
    }



    5、插入当前元素编号(指定种类)
    
 
  • 我是第1个li标签
  • 我是li标签中的第1个div标签
  • 我是第2个li标签
  • 我是第3个li标签
  • 我是li标签中的第2个div标签
  • 我是第4个li标签
  • 我是第5个li标签

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/215126.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号