this post was submitted on 20 Jun 2024
6 points (100.0% liked)
CSS
77 readers
1 users here now
A place within Lemmy where one can discuss CSS, ask for help, et-al. Please remember the human.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Okay, I jumped onto a computer to view it. The issue is that you're trying to mix fixed widths with percentages, and you're trying to make responsive layouts with fixed widths, which isn't possible. Well, it's possible if you use max-width and account for height differences, but it can get wonky.
What I was seeing on the phone was completely different than what you're seeing on your desktop. I tried to fork your project so that I can show you the few adjustments that need to be made, but there's no anonymous way to do that. I'd have to sign in, and my codepen account uses my real name. So, I'll just paste the below.
This works great, for all viewports until you get down into mobile sizes, because 50% isn't wide enough at that point. What you should do is change everything that I set to 50% too 100% instead, and then use a min-width mobile media query at about 768px to change it to 75%, and then again to 50% at 1920px. That'll give you nice smooth transitions between breakpoints that look good on all devices. Keep in mind that if you're using images inside these slides, then they're going to skew if you set a defined height like you're doing. You need to change the height of the slide wrapper to auto, and the img tags to auto, otherwise you're going to skewing. Of course that'll make the slider shorter on smaller viewports. So, you can either use SRC set to display different images per viewport to accomodate the different aspect ratios, or you can use background images instead, and set them to background-size: cover and background-position: center center. That will allow the picture container to just kind of grow outward from the center of the image, showing more of it as the viewport size increases. SRCset is probably the better solution unless you're showing images where it doesn't matter if you cut part of the content out. Or, you can just let the slider get shorter as the viewport gets skinnier. That's not really uncommon.
Anyways, here's the full code I copied. I only changed a few things, but I copied the whole thing for ease. You can just copy, select all in the codepen window, and paste, rather than trying to figure out where everything goes. After you do that then evaluate what has changed and you'll understand what's going on.
Thank you so much for this. You went to a lot of effort.
Thanks for the explanation too. It works really well at all kinds of resolutions and window sizes. I'll experiment with the values you mentioned. ๐
You're welcome. It only took a couple minutes. I've been doing this a long time. :)