Jump to content

Colour coding blog post "card"

Go to solution Solved by jpeter,

Recommended Posts

Posted

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
Posted

@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-*" .

image.thumb.png.9ebf9eb53ff83e4119e5edc2e420e747.png

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Posted (edited)

OH WOW, Thank you so much @jpeter, that's SO helpful 🤩

Just "bought you a coffee" as a thanks.

Edited by JoshA
Needed to add some info

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.