Can't transition padding

The base problem I'm trying to solve is I have an element that I want to be able to click on, and then a second element appears to side down from behind, all simple divs with text inside each. Best I can tell, the best way to do this to make things a grid and transition on the grid-template-rows. That part of the transition worked fine, but because I was using a negative top value + a padding top of the same value, padding would just appear, then the height transition. So I tried to transition on padding-top as well, but it didn't work. I created a JSFiddle showing my code: https://jsfiddle.net/ftgu7zc1/1/ Any suggestions on how to fix this bliping? Should I be using something other than negative top/positive padding top to make it look like it's coming down from behind?
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
104 Replies
ἔρως
ἔρως4d ago
have you considered using <details>?
GamersPlane
GamersPlaneOP4d ago
I was unfaimilar with it until now, and happy to give it a got. But won't I hit the same transition issues?
ἔρως
ἔρως4d ago
yes and no but mostly yes but it will work a lot better in many aspects for example, the div is still searchable when hidden
GamersPlane
GamersPlaneOP4d ago
Oh, nice. Not super useful to my current application, but nice none the less
ἔρως
ἔρως4d ago
the correct solution still has less-than-adequate support
GamersPlane
GamersPlaneOP4d ago
Is that transition behavior?
ἔρως
ἔρως4d ago
yup
GamersPlane
GamersPlaneOP4d ago
Yah, that's where I started
ἔρως
ἔρως4d ago
and transition from 0 to auto
GamersPlane
GamersPlaneOP4d ago
Yah Ok, I'm trying right now to update my fiddle and I'll respond once I do
ἔρως
ἔρως4d ago
you do have the option to use js to do all the transitioning too
GamersPlane
GamersPlaneOP4d ago
Do you mean clarifying on that? You mean not use css transitions? I havne't kept up with js as much
ἔρως
ἔρως4d ago
yeah, it is a solution
GamersPlane
GamersPlaneOP4d ago
But I can certain google it
ἔρως
ἔρως4d ago
it's a pain in the ass
GamersPlane
GamersPlaneOP4d ago
I don't mind JS, just trying to learn what I should be moving from JS to css
ἔρως
ἔρως4d ago
this is something that should be done in css, if you can live with no transitions for browsers that don't support it
GamersPlane
GamersPlaneOP4d ago
Unfortunately, I prefer firefox (this is for a personal project) and I can see transition behavior has limited support in firefox I'm relearning frontend right now, starting with react, so I'll have to figure out what JS tools/code will help with the transition part
ἔρως
ἔρως4d ago
one of them is "raf" - request animation frame you use it to calculate the animation yourself from js
GamersPlane
GamersPlaneOP4d ago
Thanks, I'll start there
ἔρως
ἔρως4d ago
i personally recommend that you keep this css-only
GamersPlane
GamersPlaneOP4d ago
I'll consider that. I'm trying to learn more for a larger site I run, and about 30% of the users there are firefox, so it wouldn't be a viable option for that one.
ἔρως
ἔρως4d ago
currently, it isn't
GamersPlane
GamersPlaneOP4d ago
Actually, would you mind helping me with the transition behavior? I'm trying it now on the fiddle on chrome, and the padding is still failing.
ἔρως
ἔρως4d ago
it's not it's the height that is changing
GamersPlane
GamersPlaneOP4d ago
Oh, right, I need to drop the grid technique
ἔρως
ἔρως4d ago
when you add/remove the grid-template-rows: 1fr;, you are changing the height you have to transition the height, otherwise it will always poke from under the parent or will look weird as hell
GamersPlane
GamersPlaneOP4d ago
Ok, let me try that out
ἔρως
ἔρως4d ago
transition from 0 to auto
GamersPlane
GamersPlaneOP4d ago
Sorry, I can't seem to get it working. I hope you don't mind taking a look? https://jsfiddle.net/ftgu7zc1/2/
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
13eck
13eck4d ago
Just have to jump in and say that GamersPlane is the best PbP site I’ve ever used. Haven’t used it in years but I have fond memories! Glad to see you’re still up and running!
GamersPlane
GamersPlaneOP4d ago
Oh, thanks! Depending on how far back, there'have been improvements thanks to a volunteer who added a bunch of customization to character sheets, and this whole "learning modern css" thing is so I can make better progress into a v2 site. Thus trying to learn transitions, and failing miserably at it 😛
13eck
13eck4d ago
Back then I was a member of the RPG Academy network. So that might tell you how far back lol
GamersPlane
GamersPlaneOP4d ago
Ah yah. Though RPGA is still going strong as well.
13eck
13eck4d ago
That’s good to hear! I was the co-host on SharkBone
GamersPlane
GamersPlaneOP4d ago
! Obviously not going to use RL names here, but of course! That was a bit ago 🙂
13eck
13eck4d ago
I think I went by EldritchFire back then. Have had a lot of handles, though, so maybe not lol
GamersPlane
GamersPlaneOP4d ago
Yup, I remember, I think it was a slight variation of that, but I could be wrong as well
13eck
13eck4d ago
Gotta go drive home, but I’ll take a look at your issue later if I have time!
GamersPlane
GamersPlaneOP4d ago
No worries, and thanks. I'm gonna rebuild it from the ground up in case I broke stuff midway Ok, this is the latest, https://jsfiddle.net/ftgu7zc1/3/, but still can't get allow-discrete working on chrome Is padding a transitionable property? I can't seem to get it working, even from absolute value to absolute value.
13eck
13eck4d ago
yes, you can transition padding
13eck
13eck4d ago
A few small changes to the CSS:
#wrapper {
position: relative;
top: -1.5em;
padding-top: 1.5em;
height: 0;
border: 1px solid #777;
border-top: none;
border-bottom-left-radius: 1em;
border-bottom-right-radius: 1em;
overflow: hidden;

&.open {
height: auto;
}
&.open > div {
padding: 0.3em 5em 0.5em;
}

& > div {
transition: padding 1s ease-in-out;
padding: 0.3em 1em 0.5em;
}
}
#wrapper {
position: relative;
top: -1.5em;
padding-top: 1.5em;
height: 0;
border: 1px solid #777;
border-top: none;
border-bottom-left-radius: 1em;
border-bottom-right-radius: 1em;
overflow: hidden;

&.open {
height: auto;
}
&.open > div {
padding: 0.3em 5em 0.5em;
}

& > div {
transition: padding 1s ease-in-out;
padding: 0.3em 1em 0.5em;
}
}
ἔρως
ἔρως4d ago
however, it won't be enough, as the element will poke under the other one because the height is too high
13eck
13eck4d ago
Here's a very rough draft using the details element and CSS transitions https://codepen.io/13eck/pen/xbbvNvG
13eck
13eck4d ago
It's kinda ugly right now as the border radii are not 100% in sync… Changed the border radius to px instead of em and it looks a lot better now >_>
GamersPlane
GamersPlaneOP4d ago
Hm... I'm on chrome 127, and it doesnt' animate... plus I was reading about how the max height trick requires you have an approximate value for what your height may be, or you get timing issues (since it'll continue animating even after you hit the content height. And I'll try animating padding again For some reason, I cant get that working I think I've gotten a good idea of the state of transitioning right now. I wish I could find any info on the state of transition behavior with FF, as the mdn docs say it supports it, but can i use says it doesn't? Or maybe that's only for allow-discrete So either it's grid hackiness or javascript for now
13eck
13eck4d ago
I'm using Chromium 135.0.7049.95 currently
GamersPlane
GamersPlaneOP4d ago
Oh, am I that far behind? Stupid Ubuntu
13eck
13eck4d ago
And the max-height trick is an issue when you try to animate both ways. But my code is animating only open, so when it closes it goes straight to height: 0;
GamersPlane
GamersPlaneOP4d ago
I got the grid vartiant working both ways (by putting the content in a div inside the cell div) So I may keep with that for now while I wait for FF to get with the times
13eck
13eck4d ago
lol /sigh FF
GamersPlane
GamersPlaneOP4d ago
Me personally wants to never use Chrome again... me developer knows I can't do that. I would just like more parity between Chrome and FF
13eck
13eck4d ago
I'm so anti-chrome I use Ungoogled Chromium for my dev browser and Orion (macOS/iOS only currently) as my daily driver I also have FF just 'cuz :p
GamersPlane
GamersPlaneOP4d ago
I've seen orion, but as I'm a linux user, it's not an option atm. Never heard of ungoogled Chromeium, but I'll take a look
13eck
13eck4d ago
If it works it works. Just don't use a button where you should use an a and vice-versa and it's all kosher It's Chrome with all the Google Tracking ripped out
GamersPlane
GamersPlaneOP4d ago
Yah, lets see it's state on ubuntu
13eck
13eck4d ago
Which does cause some problems occasionally when a link relies on Google tracking for something But I can watch YouTube, view GoogleDrive folders, etc with no issue
GamersPlane
GamersPlaneOP4d ago
Makes sense
13eck
13eck4d ago
Is the animation you're working on for the spoiler tag inside a post?
b1mind
b1mind4d ago
I would use grid for this and transition the grid-template the support will be better, until calc-size() is
13eck
13eck4d ago
Of course you'd use grid 🙄 Where's the codepen, b1? I wanna see the magic of grid! -# also, notice how I didn't suggest using flexbox? 🤣
b1mind
b1mind4d ago
because flexbox cant do this 😉 or you would have
13eck
13eck4d ago
I'm sure I could make it happen lolol
b1mind
b1mind4d ago
here is a pen I made for someone else that needed a table
13eck
13eck4d ago
What? No. Semantic HTML, my dude. If it quacks like a details element it's a details element :p
b1mind
b1mind4d ago
I'll simplify it if I need to but can't atm.
13eck
13eck4d ago
Ok, that is pretty cool
b1mind
b1mind4d ago
custom props with fallbacks is ❤️
b1mind
b1mind4d ago
Oh here was another I did in the past lol
GamersPlane
GamersPlaneOP4d ago
This is where I got it working: https://jsfiddle.net/ftgu7zc1/4/
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
GamersPlane
GamersPlaneOP4d ago
I would prefer to use details or something more semantically correct, but for this use case, doesn't quite fit I'd prefer for FF to get their act together (interestingly, I recently applied to a job at Mozilla :D) and use correct sematnics
b1mind
b1mind4d ago
Mozilla don't give a f about making a good browser anymore marketshare of 2% does not help they lost so many users
GamersPlane
GamersPlaneOP4d ago
Yah...
b1mind
b1mind4d ago
Long as its not unreadable unfunctional on FF its fine
GamersPlane
GamersPlaneOP4d ago
Agreed
b1mind
b1mind4d ago
progressively enhance the 98% of your users
GamersPlane
GamersPlaneOP4d ago
But as a backend who can't always keep up with what's going on in FE-land, I end up relyin on JS for a lot 😛
13eck
13eck4d ago
Sometimes you just gotta JS it up
b1mind
b1mind4d ago
not wrong but also cursed
13eck
13eck4d ago
And it’s not like your users will have JS disabled
GamersPlane
GamersPlaneOP4d ago
Oh, totally agreed
b1mind
b1mind4d ago
It has far less to do with being disabled but not loading
13eck
13eck4d ago
Fair
b1mind
b1mind4d ago
mr I still put links in ul should understand this 🥲 "what if css don't load" >.>;;
GamersPlane
GamersPlaneOP4d ago
FE's just not my focus, so I do what I can 🙂 And should I ever get a project going far enough, I'll look to find/hire a FE to make my stupid FE more modern friendly
13eck
13eck4d ago
Something something style element :p
GamersPlane
GamersPlaneOP4d ago
SPANS EVERYWHERE! Do browsers still support marquee or blink? I remember those being popular
b1mind
b1mind4d ago
depricated
13eck
13eck4d ago
but only one letter at a time -# link to Kevin's video on Figma Sites and how the last letter of all divs are in a span for some reason
GamersPlane
GamersPlaneOP4d ago
Haha, now we're back to the days of dreamweaver, huh?
13eck
13eck4d ago
Pretty much, yeah
GamersPlane
GamersPlaneOP4d ago
Man, the HTML those wrote...
13eck
13eck4d ago
You think you're bad at front-end? Those people are "professionals" and your HTML is better than theirs!
GamersPlane
GamersPlaneOP4d ago
Oh, I'm not bad at FE, I'm just not up to date on FE. Joking aside, my problem is just not knowing what features are viable vs what features are coming up. I need a caniuse but from the functional level rather than spec level canimake? I saw Kevin's catchup video I think he said he's going to do quarterly? I need that but in searchable form
13eck
13eck4d ago
All you need to do is know what you don't know then look it up on MDN. Easy peasy! lol
GamersPlane
GamersPlaneOP4d ago
Other than things like mdn saying it supports transition behavior (which technically it does), but not allow discrete, which is the entire point!
b1mind
b1mind4d ago
you can still use semtantics btw just make your details a grid 🥲
GamersPlane
GamersPlaneOP4d ago
That... that hurts
GamersPlane
GamersPlaneOP4d ago
Ok, time for me to learn pygame... I need to make a video game where you walk into a development office and defeat engineers with bad development takes, doing various amounts of psychic damage as you tell them things like "Just make your span a block level element"
b1mind
b1mind4d ago
You wouldn't need JS at all in that case? damn now I need to make a codepen
GamersPlane
GamersPlaneOP4d ago
Yah, no js needed 😄 I tried it yesterday, it just didn't style the way I wanted. It would work great for other usecases though

Did you find this page helpful?