Positioning text with absolute with responsiveness
Heyo, I got a card-title that I want to be placed at a certain spot on the page and it needs to be responsive. I thought of using position absolute, since it needs to be on top of a masked image. Here's a video how it's acting right now and the necessary code:
14 Replies
Perhaps position absolute isn't gonna save my life for this occasion. So any other solution that may work is ofcourse welcome! 😄
maybe try using a different unit than % for the right property 😉
As far as I can tell it looks OK in the video regarding positioning (though I agree with Mannix that % is possibly not the best unit for this).
The only thing that it might need is increasing the font-size. Clamp would be perfect for this.
this is an use case where making the images into svgs isnt a bad idea
svg can very easily scale the size of the text to fit within a width
my mask is a svg, but my project images are png as we speak
would changing the pngs to svgs help for this?
This is how I imagine it looking at let's say 768px which has a right of 2.5rem and a font-size of 2.5rem.
At 320px it looks good with a right of 1.5rem and a font-size of 1rem
Epic is referring to converting the text "Projecten" to an SVG so that it will scale according to the available space.
Ah I see
However personally I would try using clamp first, it should be fairly simple to play around with the values to get it to fit as this is a single word and within a limited space.
How would you clamp this? I can't really get the middle value to work
font-size: clamp(1rem, 2.5vw, 2.5rem);
nvm I got it to work
This works perfectly fine, just clamped the right and font-size and changed them inside some media querries for bigger screen sizes
Thanks!no, no, im talking about the whole thing
Like just get the image as 1 svg, don't bother about masking it and stuff?
ah, ok, sorry (again). I miss-understood.
yup, just one svg
for everything