La variable CSS currentColor

9/Feb/2016 139

Estos días se anunció que Google Chrome incluye soporte para CSS Variables, lo que finalmente abre las puertas a que los nuevos features de CSS sean finalmente adquirido por los browsers. Pero una variable poco conocida y con buen soporte crossbrowsing ha existido por años: currentColor. Esta capacidad tiene muchas aplicaciones las que veremos en este artículo.

Uno de las características menos conocidas de CSS es que si defines color en una declaración junto al border (por ejemplo) sin especificar el color, este border va a adquirir el color del texto por defecto, por ejemplo:

p { 
   color: #f00;
   border-bottom: 4px solid; 
}

JS Bin on jsbin.com

Así si cambias el color de texto el color del borde también heredará el cambio del color (y además funciona con propiedades como outline y box-shadow):

JS Bin on jsbin.com

Creo que se entendió el concepto. Veamos ahora un ejemplo práctico: dado un párrafo, es usual que los enlaces <a> se les entregue el mismo color que el texto:

p {
   color: #666;
}
p a {
   color: currentColor;
   font-weight: bold;
}

JS Bin on jsbin.com

Con el valor currentColor podremos reducir las declaraciones de colores de nuestro código CSS, e inclusive podremos construir un conjunto de interfaces (componentes) que dependan y hereden el color automágicamente:

p {
  color: #34495e;
}
p a {
  color: currentColor;
  font-weight: bold;
}
p .btn {
  display: inline-block;
  border-radius: 10px;
  border: 1px solid;
  text-decoration: none;
  padding: .1em 1em;
  line-height: 1.5;
}

JS Bin on jsbin.com

Links:

Comentarios

  1. lebron james shoes [#]

    I wish to show thanks to this writer just for bailing me out of this instance. As a result of browsing throughout the online world and meeting proposals which were not pleasant, I believed my entire life was well over. Existing without the strategies to the problems you’ve solved by way of the guideline is a critical case, as well as the kind that could have badly affected my career if I hadn’t come across your web blog. That ability and kindness in dealing with all the pieces was crucial. I don’t know what I would’ve done if I had not come across such a step like this. I can also at this moment relish my future. Thanks for your time very much for this specialized and amazing help. I will not hesitate to recommend the blog to anyone who requires support on this issue.

  2. supreme hoodie [#]

    I wanted to send you this very small word in order to thank you very much as before over the beautiful pointers you have contributed on this page. It is quite incredibly generous with people like you to convey extensively what exactly many individuals could possibly have marketed as an e book in making some bucks for their own end, most importantly since you might have done it if you desired. Those ideas in addition served as the great way to realize that someone else have the identical dream really like my personal own to figure out a little more in regard to this issue. I am sure there are several more fun sessions up front for many who see your blog.

  3. golden goose outlet [#]

    I truly wanted to send a small word to be able to appreciate you for these superb secrets you are placing at this site. My long internet search has at the end of the day been compensated with sensible insight to exchange with my classmates and friends. I ‘d point out that many of us visitors actually are undeniably fortunate to dwell in a fantastic place with so many wonderful individuals with valuable solutions. I feel really happy to have come across your entire web pages and look forward to plenty of more exciting minutes reading here. Thanks once again for everything.

  4. curry shoes [#]

    Thanks so much for giving everyone an extraordinarily superb possiblity to discover important secrets from this blog. It is often so ideal and also jam-packed with a good time for me and my office co-workers to visit your blog at minimum thrice weekly to study the new secrets you will have. Of course, I’m at all times astounded concerning the fabulous inspiring ideas you give. Some 2 ideas in this article are essentially the most beneficial I have had.

  5. www.iherb.com [#]

    Thank you for the good writeup. It in fact was a amusement account
    it. Look advanced to more added agreeable from you!
    However, how could we communicate? quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

  6. bit.ly [#]

    Hello are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and
    set up my own. Do you require any coding expertise to make
    your own blog? Any help would be greatly appreciated! scoliosis surgery
    https://0401mm.tumblr.com/ scoliosis surgery

  7. http://tinyurl.com [#]

    Hey! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve
    worked hard on. Any recommendations? ps4 https://bitly.com/3z5HwTp ps4 games

  8. Mobile recharge [#]

    What a beautiful blog

  9. coub.com [#]

    It is appropriate time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I want to suggest you few interesting things
    or tips. Maybe you could write next articles referring to
    this article. I desire to read even more things about it! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  10. yeezy shoes [#]

    I simply had to appreciate you all over again. I’m not certain what I could possibly have undertaken without these solutions documented by you on such industry. Completely was an absolute fearsome dilemma for me, but being able to view a specialized way you processed it forced me to leap over joy. I will be thankful for your assistance and then expect you really know what a great job your are getting into training people today with the aid of a site. I know that you’ve never encountered all of us.

  11. off white hoodie [#]

    I am commenting to let you be aware of what a great experience my cousin’s daughter found going through your site. She noticed some issues, including how it is like to possess an awesome helping mindset to let other folks just fully understand specific hard to do issues. You undoubtedly did more than people’s expected results. Many thanks for giving such warm and helpful, dependable, edifying and even easy thoughts on the topic to Jane.

  12. a bathing ape [#]

    My spouse and i have been really delighted that Louis managed to conclude his analysis while using the precious recommendations he was given while using the site. It is now and again perplexing to just continually be giving away steps that the rest may have been selling. We really already know we need you to appreciate for this. All the explanations you’ve made, the straightforward blog menu, the friendships your site make it easier to foster – it’s got everything powerful, and it’s really making our son in addition to our family consider that the subject is exciting, and that is very serious. Many thanks for everything!

  13. a bathing ape [#]

    I wanted to put you that bit of word in order to say thank you again with your great strategies you’ve documented at this time. It’s simply seriously generous of people like you to deliver without restraint what numerous people could possibly have advertised as an electronic book to generate some bucks for their own end, notably seeing that you might well have done it if you ever desired. The good tips likewise served to become a great way to fully grasp other individuals have a similar dream much like my very own to know the truth somewhat more in regard to this problem. I think there are many more enjoyable moments up front for folks who examine your blog.

  14. bape clothing [#]

    My spouse and i got now relieved when Louis managed to complete his web research via the precious recommendations he got through the weblog. It is now and again perplexing to just happen to be offering points some others may have been selling. And we realize we need the blog owner to thank for this. These explanations you made, the straightforward website navigation, the friendships you make it possible to engender – it is everything amazing, and it’s really helping our son and us reckon that that issue is amusing, and that is extraordinarily fundamental. Thank you for all!

  15. curry shoes [#]

    I am just commenting to make you understand what a amazing encounter my friend’s girl undergone reading the blog. She figured out a lot of issues, which included what it is like to have an ideal helping style to let the mediocre ones completely know specified multifaceted issues. You really did more than my expectations. Many thanks for providing such priceless, trusted, explanatory and also easy tips on that topic to Emily.

  16. periactin [#]

    cetirizine 10mg vs loratadine 10mg – http://allergyd.com

  17. stromectolforte.com [#]

    ivermectin 3 mg for humans https://stromectolforte.com/ buy ivermectin online india cecair stromektol

  18. chrome hearts online store [#]

    I wanted to put you this very small word to finally say thanks yet again for all the extraordinary methods you have provided above. It is certainly shockingly open-handed of people like you to present extensively all a lot of people would have offered for sale for an electronic book to help make some bucks for their own end, specifically given that you might well have done it if you wanted. The creative ideas as well served to be a good way to fully grasp some people have similar fervor just like my own to understand more when it comes to this problem. I am sure there are thousands of more pleasant times in the future for individuals who find out your blog.

  19. supreme clothing [#]

    I needed to create you one very little word so as to thank you so much again relating to the remarkable solutions you have provided in this case. It’s quite wonderfully open-handed of people like you giving unhampered what exactly a number of us would’ve made available as an e-book in order to make some bucks for themselves, and in particular given that you might well have tried it in the event you decided. Those inspiring ideas additionally worked like a easy way to understand that other individuals have a similar eagerness similar to my very own to learn a lot more with respect to this condition. I am certain there are many more pleasant sessions ahead for folks who read carefully your site.

  20. yeezy supply [#]

    I am also writing to make you be aware of of the extraordinary experience my wife’s daughter found viewing your web site. She mastered such a lot of issues, not to mention how it is like to have an amazing helping nature to get other people very easily grasp a number of specialized issues. You truly exceeded my expectations. Thank you for imparting such invaluable, safe, revealing not to mention easy tips about the topic to Janet.

  21. birkin bag [#]

    I want to express some thanks to the writer just for bailing me out of such a incident. Because of exploring throughout the online world and coming across things that were not beneficial, I believed my life was gone. Living devoid of the solutions to the issues you have sorted out through your good report is a crucial case, as well as the ones that could have in a wrong way damaged my entire career if I had not discovered your web site. Your good know-how and kindness in dealing with all the details was valuable. I am not sure what I would’ve done if I hadn’t encountered such a step like this. I am able to at this time look forward to my future. Thanks for your time very much for this specialized and sensible help. I won’t hesitate to recommend your web blog to any person who needs to have guidance about this area.

  22. stone island jacket [#]

    I am writing to let you be aware of of the awesome experience my wife’s girl encountered checking your blog. She picked up plenty of issues, with the inclusion of how it is like to possess a wonderful coaching character to get the rest without problems know a number of very confusing things. You truly exceeded my desires. Thank you for churning out the good, dependable, revealing as well as easy tips about your topic to Sandra.

  23. westbrook shoes [#]

    I am only writing to make you understand of the brilliant encounter my child found browsing your site. She discovered some things, including how it is like to have an excellent giving heart to make the rest without difficulty know just exactly certain specialized topics. You undoubtedly exceeded our own expected results. Many thanks for providing the warm and friendly, dependable, educational as well as unique thoughts on this topic to Julie.

  24. supreme clothing [#]

    I simply wished to appreciate you all over again. I do not know the things I might have done without the type of aspects provided by you about this field. This was an absolute alarming difficulty for me personally, nevertheless finding out the very professional manner you processed the issue forced me to cry with contentment. Now i am thankful for this support and as well , pray you are aware of an amazing job you were getting into teaching people by way of your blog. I am sure you haven’t got to know any of us.

  25. lebron 18 [#]

    I have to show appreciation to the writer for rescuing me from this particular matter. After surfing around through the online world and seeing proposals that were not beneficial, I believed my entire life was gone. Being alive minus the answers to the issues you’ve solved through the blog post is a critical case, as well as ones which may have adversely affected my career if I had not come across your web site. Your actual mastery and kindness in touching the whole thing was valuable. I’m not sure what I would have done if I hadn’t discovered such a step like this. I’m able to at this moment look forward to my future. Thanks very much for this specialized and effective help. I will not hesitate to suggest your web blog to anybody who would need care about this situation.

  26. lebron 17 [#]

    I wanted to type a word to be able to express gratitude to you for some of the stunning guidelines you are posting here. My extensive internet research has at the end of the day been rewarded with good quality tips to exchange with my family and friends. I ‘d claim that many of us readers actually are unequivocally endowed to exist in a decent website with so many brilliant people with helpful tactics. I feel really happy to have used the weblog and look forward to so many more entertaining minutes reading here. Thanks a lot once more for a lot of things.

  27. moncler outlet [#]

    Needed to send you a little remark in order to say thanks over again just for the exceptional suggestions you have shown in this case. It has been certainly pretty generous of people like you in giving easily precisely what many people would’ve sold as an ebook to get some profit for themselves, chiefly seeing that you might have tried it if you ever decided. These points additionally acted to provide a easy way to fully grasp that someone else have the same fervor really like my own to grasp a whole lot more pertaining to this condition. I’m sure there are several more pleasurable moments in the future for those who read through your website.

  28. jordan 1 off white [#]

    I enjoy you because of all of your hard work on this blog. Debby takes pleasure in conducting investigation and it’s obvious why. We all hear all about the lively method you render very useful information on this blog and even foster contribution from the others on the content and our daughter is becoming educated so much. Enjoy the rest of the new year. You’re the one carrying out a pretty cool job.

  29. lebron james shoes [#]

    I precisely wished to thank you very much yet again. I am not sure the things I could possibly have implemented in the absence of the tactics documented by you concerning this concern. It became a scary condition in my position, nevertheless understanding the well-written tactic you treated it took me to weep with happiness. I’m just happier for the information and even hope that you are aware of an amazing job you have been carrying out training others through the use of your websites. I know that you have never encountered any of us.

  30. russell westbrook shoes [#]

    Thanks a lot for giving everyone such a superb opportunity to read critical reviews from this website. It’s always very terrific plus stuffed with fun for me personally and my office mates to search your blog at the very least three times in a week to read the newest issues you have. And indeed, I’m certainly contented concerning the fabulous ideas you give. Certain 1 areas on this page are truly the most beneficial I’ve ever had.

  31. yeezy 380 [#]

    I want to show my passion for your kindness supporting people who have the need for guidance on this situation. Your personal commitment to passing the message around appears to be pretty invaluable and have truly empowered workers just like me to realize their objectives. Your entire important instruction signifies much a person like me and further more to my peers. Regards; from each one of us.

  32. kobe shoes [#]

    I simply wanted to type a small remark to be able to say thanks to you for the lovely guidelines you are showing on this site. My time-consuming internet lookup has at the end been rewarded with beneficial suggestions to write about with my guests. I would repeat that most of us website visitors are unequivocally endowed to exist in a decent community with so many marvellous individuals with valuable principles. I feel somewhat grateful to have seen your entire website page and look forward to some more excellent moments reading here. Thank you once again for a lot of things.

  33. off white [#]

    I precisely had to thank you so much once more. I do not know what I could possibly have carried out without the methods discussed by you concerning that question. It truly was a real depressing issue in my position, but taking a look at the professional technique you dealt with that made me to leap with gladness. I will be grateful for this guidance and even hope that you comprehend what a powerful job you were putting in teaching many others through your web site. I am certain you’ve never got to know all of us.

  34. yeezy [#]

    I really wanted to send a message to thank you for these fabulous recommendations you are showing here. My incredibly long internet research has at the end been paid with excellent facts and techniques to go over with my friends and family. I ‘d believe that most of us site visitors actually are undoubtedly endowed to dwell in a superb place with very many special people with insightful tips and hints. I feel very blessed to have encountered your weblog and look forward to really more fun times reading here. Thanks a lot once again for a lot of things.

  35. jordan shoes [#]

    I simply needed to appreciate you once more. I am not sure the things that I would’ve taken care of without those creative concepts shared by you over such topic. Previously it was a real traumatic circumstance in my view, nevertheless looking at your skilled technique you managed the issue forced me to weep over happiness. Now i’m happier for your support and in addition wish you know what a powerful job you are doing educating many people thru your website. I am sure you’ve never met all of us.

  36. golden goose [#]

    I would like to show some appreciation to the writer for bailing me out of this type of incident. Because of searching through the search engines and coming across views which are not pleasant, I figured my life was well over. Existing without the answers to the problems you’ve resolved all through your main blog post is a crucial case, as well as the ones that would have negatively affected my entire career if I had not come across your web blog. Your main mastery and kindness in dealing with all the pieces was vital. I don’t know what I would have done if I hadn’t come across such a step like this. I am able to at this time relish my future. Thanks for your time very much for the skilled and results-oriented help. I won’t think twice to endorse your blog post to any individual who needs to have tips about this matter.

  37. curry 7 shoes [#]

    I enjoy you because of all your efforts on this web site. My niece enjoys participating in investigation and it’s really easy to understand why. Most people hear all of the dynamic medium you provide very important guides through your website and therefore strongly encourage contribution from people on that issue then our simple princess is truly understanding a lot. Take advantage of the rest of the new year. You have been doing a good job.

  38. lebron 17 [#]

    My husband and i got now lucky when Albert managed to complete his analysis while using the ideas he obtained out of the site. It’s not at all simplistic just to choose to be giving for free secrets and techniques some other people may have been making money from. And we figure out we need the blog owner to give thanks to because of that. All of the explanations you’ve made, the simple blog navigation, the friendships you aid to instill – it’s most terrific, and it is facilitating our son in addition to the family know that that content is enjoyable, and that’s truly indispensable. Thank you for the whole lot!

  39. stephen curry shoes [#]

    I have to show thanks to this writer for rescuing me from this particular matter. Right after looking out throughout the world-wide-web and obtaining basics that were not pleasant, I assumed my entire life was well over. Living without the presence of solutions to the problems you have resolved as a result of your blog post is a crucial case, as well as ones which might have in a wrong way affected my career if I had not discovered your web page. Your personal capability and kindness in dealing with all the things was priceless. I’m not sure what I would’ve done if I hadn’t encountered such a thing like this. I can at this time look ahead to my future. Thank you very much for your professional and sensible help. I will not be reluctant to endorse the sites to any person who desires guide about this subject.

CSSLab