3 Cards 1 row where the center card is 1.5 times the size of the 1st and 3rd card.

Like the image, I want 3 divs stacked horizontally. 1st and 3rd div should be the same size but the 2nd (center) div should be a little bigger than the 1st and 3rd div. I tried using scale(1.5) on the 2nd div but then it over laps with the 1st and 3rd div. I thought about manually setting height on all three cards and giving the middle one a greater value that the corner cards but AFAIK it's not recommended to set height on things. I am using tailwind with react, if it matters.
No description
15 Replies
Chris Bolson
Chris Bolson7mo ago
You could scale down the side ones to 0.75 an set the middle one to 1.25. (Sorry of my math is off, it is early)
o_O
o_OOP7mo ago
The issue is that it shrinks the entire thing along the text and the content that's within the card. I don't want the content shrining
Chris Bolson
Chris Bolson7mo ago
So the content of the three cards should be the same size and just the containing box should be bigger? You could use a pseudo element to define the boxes area. That won’t affect the content itself. .
MarkBoots
MarkBoots7mo ago
are the aspect-ratios the same. if yes, you could use grid https://codepen.io/MarkBoots/pen/pomerQm
o_O
o_OOP7mo ago
isn't setting aspect ratio on the grid children the same as setting height implicitly? basically your height will be the function of your width. yes. the content should be the same size. I just want to put emphasis on the center card. can you elaborate on how I can use pseudo elements for this? I have no clue what you're talking about here.
Chris Bolson
Chris Bolson7mo ago
Basically a pseudo element on each card would define the background color or border (for example). The cards themselves would be exactly the same size. https://codepen.io/cbolson/pen/zYQZMYp
MarkBoots
MarkBoots7mo ago
nice solution. maybe even use a couple of vars to make it easier to adjust. something like this
.cards{
--larger: 2rem;
--gap: 2rem;
gap: calc(var(--gap) + var(--larger))
}
.card:nth-child(2)::before{
inset: calc(var(--larger) * -1);
}
.cards{
--larger: 2rem;
--gap: 2rem;
gap: calc(var(--gap) + var(--larger))
}
.card:nth-child(2)::before{
inset: calc(var(--larger) * -1);
}
o_O
o_OOP7mo ago
that's a really neat solution. so it basically takes advandage of insest to create more room inside the middle child. thanks @MarkBoots @Chris appreciate it. Mark I didn't get to fork your codepen and I think you took it down. can you bring it back up for a day so I can fork it? Or maybe post the code here.
Chris Bolson
Chris Bolson7mo ago
Bear in mind that inset is just short-hand for top, right, bottom, left. So inset: 0; would be the same as
top: 0;
right: 0;
bottom: 0;
left: 0;
top: 0;
right: 0;
bottom: 0;
left: 0;
As these can have negative values, inset: -1.5rem; is the same as setting:
top: -1.5rem;
right: -1.5rem;
bottom: -1.5rem;
left: -1.5rem;
top: -1.5rem;
right: -1.5rem;
bottom: -1.5rem;
left: -1.5rem;
As Mark says, you could use custom properties to make the calculations automatic, I just didn't want to distract from the solution itself. The pseudo element isn't actually creating more room, it is just making the background area look bigger. The cards themselves are exactly the same size.
Wonderbear
Wonderbear7mo ago
Why such a complex solution that is hard to read and understand?
Wonderbear
Wonderbear7mo ago
@Chris Why not like this? https://jsfiddle.net/Lpondxw6/
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Wonderbear
Wonderbear7mo ago
I think its a bad idea using pseudo elements for major styles of the element
Chris Bolson
Chris Bolson7mo ago
Just because you find it complex and hard to understand doesn't mean that it is. Pseudo elements are an excellent solution for this type of thing as, if the are positioned absolutely, they don't affect the rest of the DOM. With your solution the extra padding on the second element changes the whole layout. For this very reason, pseudo elements are perfect for styling elements.
Wonderbear
Wonderbear7mo ago
Most of the time it is no problem when it changes the layout imho. Even if your solution doesnt seem more complex to you, it is objectively definitely more complex than the solution with the padding
Chris Bolson
Chris Bolson7mo ago
Anyway, it is great to give multiple solutions so that the OP can find one that suits their specific needs. The OP specifically stated that the content should be the same size on all of the cards. Adding padding does not meet this requirement.
Want results from more Discord servers?
Add your server