元素的content属性

content这个css属性被用于before和after这两个伪元素去产生放在元素内的内容。而所有元素都可以用content这个属性的url()值和其他的图片值用于替换元素本身的内容。用content属性被插入的对象是匿名的替换对象。

content有如下几种值:

1、content: normal;

2、content: none;

以上这两种值不能和其他的值一起用。其他的值可以同时混用,如:content: open-quote counter_name;

3、content: url("http://www.example.com/test.png");

这种url值可以替换所有元素本身已经有的内容。

eg: <div class="example">hahaha</div>

.example {

  content: url("http://www.baidu.com/test.png");

}

原本的内容hahaha被替换成了链接上的图片。(个人感觉只是content的内容把原来的内容覆盖了)

4、content: linear-gradient(#e66465, #9198e5);

这种图片属性的值和url值一样可以替换所有元素本身已经有的内容。

eg: <div class="example">hahaha</div>

.example {

  content: linear-gradient(#e66465, #9198e5);

}

原本的内容hahaha被渐变色充满整个元素。

以下这些属性值只适用于before和after伪元素:

5、content: "放任意的字符串";

eg: content: "hello";

6、content: counter(counter_name);

7、content: attr(HTML attribute name);

eg: <div class="example" test="123">hahaha</div>

.example:before {

  content: attr(test);

}

原本的内容hahaha被属性test的值123覆盖。

8、content: open-quote; 前影号

  content: close-quote;后影号

  content: no-open-quote;不要前影号

  content: no-close-quote;不要后影号

(emmm,个人还不太明白这个不要前后影号是要干啥。。。)

9、一些全局值,也不太明白是用来干啥的

content: inherit;

content: initial;

content: usnet;

 

转载于:https://www.cnblogs.com/coconutGirl/p/9554663.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值