I’m wondering if anyone can help me with a button hover transform. I would like to scale the button background but not the text in the button. I can only seem to transform the entire button.
Yeah so how the button currently works, when you hover over the button (on desktop) the button scales in size using transform. The problem is the text also scales, but I want just the blue pill background to scale.
I ended up getting it to work correctly using border, but I could see that becoming an issue down the road is you wanted the same scale effect but with something like the background image of a div. Do you happen to another a different way to achieve this? Also, if you check out the updated link, when you mouse out of the button it snaps back to the original size instead of animating back down. Do you know how to animated mouse out effects of the button? Thanks for your help.
The difference is the nesting of objects. In your case, the text is nested within the blue button, so it’s a child of it. When you affect the parent, you affect the child as well. To keep the two independent, you make them sibling to one another, and I used flex positioning to make the text center on top of the button bg. Then I wrapped both in another div and applied an interaction to the wrapper, and had the animation target the background only. This would cause the bg to animate independently from the text.
I also added a padding on the wrapper so that the text would keep still while the bg grew. Without it, when the button bg grew, it would cause the text to shift around unintentionally as the wrapper box expanded to accommodate for the growing button bg.
So would I be wrong to say that the downfall of this method is that the button background can no longer be dynamically sized by the text? Could you use this method for a site wide reusable button without having to adjust each button’s width manually to accommodate different lengths of text?
I’ve adjusted the button designs to accommodate for the size of the text within. Check the webflow site I published to see the change.
This solution has a padding on the wrapper and the bg goes to 100% width/height to fill the wrapper + the width/height of the text element within. The interaction and the buttons can be replicated with nothing breaking - unless you want unique styling on the bg of the button. Adding a combo style would break the link to the interaction, as I’ve experienced and outlined extensively in another forum thread today:
As long as you keep things the same between all buttons, OR you don’t mind making new animations for unique buttons, you should be fine.
@lorentracy I think I found a glitchy workaround to unique styling!
The three buttons were working and I decided to try to break the interaction to one of the buttons by adding an extra combo class to one of the buttons to make it black instead:
And I tried the animation and it WORKS.
So my theory behind this loophole is that you can add customization after you have set up the interaction, because the animations will refer to all instances of [blue button bg][flexi], regardless if it has additional combos added to it.
This might solve my other problem that I have on the other thread so I’m really excited now