In using the left property in CSS, the element is positioned by the left edge. How do I position using the
In here, setting left to zero positions using the left edge in the square.
I want it to be like this
Setting the property to 0 positions the square to the center.
@OmegaOrbitals2 You could use this css:
/* and possibly */ transform: translateX(-50%);
Or for something simpler:
No, that’s not what I meant. I don’t need to position an element in the center. I need to position it
by the center.
For example, left positions using the left edge of the element. Right positions using the right edge of the element. Is there any CSS property to position it using the center of the element?
March 3, 2023, 2:22pm
something along the lines of this, maybe?
left: calc(50% + x);
Do what MrVoo said and use calc.
left: calc(50% + 20px);
Maybe add padding on the left side
I was confused on which one to choose as solution, but I decided with yours. You were more accurate by transforming it by 50%. Though transform doesn’t work well sometimes, so I did calc(50% - elemsizedividedby2).
March 12, 2023, 6:53am
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.