How do I maintain space between sibling elements when scaling them up on mouse enter / hover ?
This is the specific issue that I am having:
"When a card is hovered on or marked as active, the scrolling animation stops, the card expands pushing the neighboring cards aside to maintain a consistent gap, and information is displayed over the cards background."
I have all of that covered except: "maintain a consistent gap", I've tried both transform: scale() and scale: value and the expanding card doesn't push out the others. Pictures below in comments.
If you would like the full brief, it's a pretty challenging test project (Let's see you tackle this without any packages Kevin!) :
Behaviour – Desktop
The carousel contains a series of cards, that auto-scroll and reset back to the start when the ending is reached. Each card has it’s own background image with no text (the text/logo shown is baked into the image). When a card is hovered on or marked as active, the scrolling animation stops, the card expands pushing the neighboring cards aside to maintain a consistent gap, and information is displayed over the cards background. Each card has it’s own unique title and description, but the button text stays consistent. The card’s background also changes to a video that plays when hovered and is unique to each card. The carousel can be dragged by the user by clicking + dragging or hold swiping an active card in a given direction. Clicking the arrows will slide the carousel over by one card in the respective direction.
Design – Mobile
Behaviour – Mobile
The carousel contains a series of cards, with the next/previous card poking into view from outside of the viewport. Swiping in either direction will move the carousel to the next card. As the cards move, the dost indicator below the card will reflect the change by having the corresponding dot grow. When the dot grows, the other dots should move aside, maintaining a consistent gap between all dots. Each card will have it’s own image, title, and description but the button text will remain the same.
16 Replies
Best to provide a minimal example of what you are doing, that wall of text does not really cut it.
Also though you should be able to use scale without it changing position in the dom.
Are you masking wanting others to do your work for you as a challenge?
At least provide an image of what you want
yea confused on this as well the title is like a direct question but the wall o text does not really explain the issue just the functions 🤔 ? So please clearify, examples are best #how-to-ask-good-questions
It's too much text for me to read, so I've only actually read the first line, to see how the rest is formatted like
no of course not
hopefully this image helps, notice how that expanded card scales up, but doesn't push out the other cards?
Here's my on mouse enter code
here is the the css on the card container:
And here's my CSS on the track:
My apologies for presenting that poorly before, the important sentence is:
"When a card is hovered on or marked as active, the scrolling animation stops, the card expands pushing the neighboring cards aside to maintain a consistent gap, and information is displayed over the cards background."
Is display flex screwing things up?
because I take it off of flex and I get this (with inline block cards):
I have tried both transform: scale() and scale: value
Also thank you for taking the time to read this and help me out!
yeah, it looks like I just have to do height and width
yep, just adjusting the width/height should work.
if you use transform functions (such as scale) it will visualy change, but the actual size/position of the element stays the same, so surrounding content will not adjust.
@BrianC i just whipped this up, does this help you? https://codepen.io/deerCabin/pen/OJrrEKG
Thanks snxxwyy! I looks great. The issue was maintaining the margins when scaling up the element. The trick in there was that they wanted to use baked in text in the cards, so that allows you to just do a basic height width adjustment, which works so long as you have object fit on there
thank you for taking the time to look into it, and whip that up!
no worries, glad it helped!
@BrianC i edited it so the overlap and gap values are more maintainable, it doesn't have random numbers everywhere, all you have to do is edit the overlap variable and it automatically changes the gap size for you.
I'm just off to a family get together, but I'm jazzed to have a closer look when I'm back!
alrighty sounds good!