Change Background Color of Component Instance

Is there a way to change color properties of component instances? If not, are there any workarounds?

1 Like

hi @asgsdf all these informations are well documented in WF documentation.

link is pointing to the exact part that will give you an answer but it will be for you beneficial always search first there to find answers to your questions you can also finish all WFU video courses to learn and get familiar with this platform.

Hi @Stan,

Thanks for the infoā€¦ but the anchor you sent is for unlinking a component, which is what shows up when doing a quick search, but does not answer the question.

I think itā€™s obvious unlinking the component is an option, but also defeats the purpose of using a component in the first place in most scenarios. Thatā€™s why I was asking here to see what kind of workarounds folks had, if any. Thanks again for providing yours.

hi @asgsdf answer

The workaround for setting the component background is very simple. Wrap the component in div element and add another absolutely positioned div element called eg. background and give it the color you need. Because all elements are transparent your background will be visible. Donā€™t forget to set correctly relative and absolute positioning together with z-indexes

hope this will help to solve your request

THE EXAMPLE of the above description

You have to keep in mind that WF offers only very basic, simple, and limited tools but this is the price for no-code.

1 Like

Thatā€™s a fairly simple and clever way to handle background colors (as long as your components arenā€™t Sections). Thanks for taking the time to explain.

Yep, but if you read through the documentation it looks like theyā€™re already working on it, so fingers crossed!

I like your newcomer enthusiasm and optimism @asgsdf. Hope this will say for a long time. Donā€™t lose it. :wink:

2021

2023

If you do not have further questions related to your topic feel free to close it as solved.

Hi,
there is actually a really easy solution.

You can set up a pageload animation and change the background color on load.

That way you donā€™t need any additional div blocks and can use your default component.

You can see the setup here:
https://preview.webflow.com/preview/julians-dandy-site-0952f8?utm_medium=preview_link&utm_source=designer&utm_content=julians-dandy-site-0952f8&preview=07ec3de6cc0bdc2fdff75f5fc9a5c636&workflow=preview

3 Likes

Ah nice! Looks like that would work for text color too. Never would have thought of that, thanks!

1 Like

Hello! Iā€™m in a similar situation. I have different pages, and actually i want to establish a colour palette for each one (I want a page with some title colors in Blue, but i want them green in another page). I think this is done easily in react by passing the color as a component prop and setting the color as a style. Butā€¦ can this be done in webflow? As you guys, I want to maintain the layout and size of the text, for example. But in this particular case, I donā€™t find useful unlinking the components, or linking them ha!
Can you guys help me?

Iā€™m so glad Iā€™m not the only one that has weird things that happen in webflow for no logical reason

Hey guys I thought Iā€™d add another solution here that feels a bit more elegant than using Webflow interactions or absolutely positioned elements.

We can use the combination of a component text property and some custom CSS.

  1. After creating our component we can go into the settings of the element we want to change the background for - in my case itā€™s my section element

  2. Letā€™s add a new attribute called ā€œdata-bg-colorā€ and hook the value up to a component property

  3. Create a new property and call it ā€œBackground Colorā€. Set the default value to whichever color youā€™d like - in my case Iā€™ll use ā€˜whiteā€™ (the word doesnā€™t matter, just as long as it matches the CSS weā€™re about to write)

    image

  4. After clicking ā€˜Createā€™ you should have something that looks like this - time for our CSS

    image

  5. Create a new code embed and paste the following code into it

    <style>
    /* change ".section_fractional-bdm" to the class name of your element */
    /* change "blue" to the color you want */
    /* change "var(--background-color--background-secondary) to the CSS color you want"  */
    .section_fractional-bdm[data-bg-color="blue"] { 
    	background-color: var(--background-color--background-secondary);
    }
    </style>
    

  6. Letā€™s talk about this code

    • The yellow part is the class name of our section weā€™re changing the background color of
    • The part immediately following it wrapped in ā€œā€ - is saying if an element of this class also has this attribute ā€˜data-bg-colorā€™ and its value is ā€˜blueā€™ then do this style to it
    • ā€œbackground-color: var(ā€“background-colorā€“background-secondary);ā€ is setting the background color to one of my color variables - in this case itā€™s a nice light blue (#EEF5FC). We could remove the var part and simply write something like ā€˜blueā€™ and it will work but it will be a yucky default blue :wink:. Any valid CSS color works here (hex, rgb etc.)
    • You can copy this code in between the style tags as many times as youā€™d like to create as many different background colors as youā€™d like
  7. Now letā€™s go back out of the component and change its property from the default to ā€˜blueā€™ and watch the magic unfold

1 Like

Hi ! can someone please review this :pray: https://discourse.webflow.com/t/nested-cms-and-hover-interaction/295099?u=paula_cortes