前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS3 currentColor

CSS3 currentColor

作者头像
javascript.shop
发布2019-09-04 15:34:31
3500
发布2019-09-04 15:34:31
举报
文章被收录于专栏:杰的记事本杰的记事本

CSS variables are always a hot topic when “the future of CSS” is discussed. They are actually comingnatively, but using them in production (without a CSS preprocessor framework) is a long way off. However there is a feature that actually has some browser support now that has a CSS variable feel to it, and that’s the currentColor value.

It works like this:

代码语言:javascript
复制
div { 
  color: red; 
  border: 5px solid currentColor;
  box-shadow: 0 0 5px solid currentColor;
}

I learned about this from a panel at SXSW 2011 on CSS3 with Stephanie & Greg Rewis, Estelle Weyl, and Christopher Schmitt. Googling it turned up Divya Manian’s article who says:

…you can use this value to indicate you want to use the value of color for other properties that accept a color value: borders, box shadows, outlines, or backgrounds. This value was first supported by Opera in 2009, since then, Firefox 3.5+, Chrome 1+, and Safari 4+.

Here’s the spec and the Can I Use information.

#It will follow the cascade

代码语言:javascript
复制
body { color: red; }
div { border: 5px solid currentColor; }

#You can’t trick it.

Let’s say you wanted to exploit the variable quality to it, but then reset the color for the actual text… this won’t work:

代码语言:javascript
复制
div {

   color: red;
      
   border: 5px solid currentColor;
   box-shadow: 0 0 5px currentColor; 
    
   color: black;
   
 }

Everything will be black.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014年9月2日20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • #It will follow the cascade
  • #You can’t trick it.
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档