Help with centering absolute positioned item
Hello! I am trying to position the form in the first picture to the one in the second picture while keeping things responsive.
transform: translateX(50%) works, but it is not responsive. Appreciate any help ^
Current Layout Code:
15 Replies
To use
position: absolute
and transform: translate
you need a few changes:
That sets the top-left of the centered element to the mid-point of the parent container (with position: relative;
) and then moves it left/up by half it's width/height.hey, thanks for the response! I have tried that before, and that centered the div in my hero section (it is positioned relative to the hero), while the one i want is centered at the bottom.
Is there a way I could do that?
I'm not sure what you're asking, sorry. Can you elaborate a bit?
Sure thing ^
So if do this
it becomes exactly what i want, however
iit doesn't stay at the center u see
so i'm trying to find a way to stick it there
Are you resizing the window?
yeah, but its the same in responsive mode
If you re-size the window it won't do a repaint on the absolute posititioned elements
For that you'd need to do some flexbox or grid instead
oh hm, so i hv to use grid to center it?
there's no other way?
If you want it to stay in the middle when the window is resized, yes
Both grid and flexbox are dynamic so as the viewport changes so does the grid/flex container
Absolute positioning is set once and done
alright i got it, thanks for the help ^