JoshA Posted January 24 Posted January 24 Hi Community! I'm wondering whether it's possible to assign a unique colour to the background colour of the "card" based on a tag/category - see https://www.urbanhealthcouncil.com/living-encyclopedia. In this case I've been able to set them all to one colour via CSS but is there something I can do to have the background colour set based on the tag, meaning there would be around 6 colours in total? Thanks! :-)
Solution jpeter Posted January 25 Solution Posted January 25 @JoshA You can use the following CSS below. This adds CSS variables to the blog-item container and then uses them in the category-* classes that is set on each "card". CSS .blog-item { --pamphlet: red; --report: blue; --definition: green; --imagination-lab: pink; --declaration: black; --article: gray; --data-study: tomato; } .category-pamphlet { background-color: var(--pamphlet) !important; } .category-report { background-color: var(--report) !important; } .category-definition { background-color: var(--definition) !important; } .category-imagination-lab { background-color: var(--imagination-lab) !important; } .category-declaration { background-color: var(--declaration) !important; } .category-article { background-color: var(--article) !important; } .category-data-study { background-color: var(--data-study) !important; } Screenshot Here's a screenshot of Chrome dev tools open. You'll notice that each card has a class set based on the category in with the following format, "category-*" . tuanphan 1 Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!
JoshA Posted January 25 Author Posted January 25 (edited) OH WOW, Thank you so much @jpeter, that's SO helpful 🤩 Just "bought you a coffee" as a thanks. Edited January 25 by JoshA Needed to add some info
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment