Any method I use to center the element does not work because the element on the right has a width to it, so the center element is always off center. I attached a picture to hopefully give a better idea of what I’m trying to accomplish.
The element I’m trying to center is an input field, here is the link to my project as well to give a more complete picture: https://weathervc.netlify.app/
I have tried countless variations of flexbox and grid to achieve this but the input element remains off center. I have also tried to take the element on the right out of flow, which kind of works, but it does not look good as the element stays stationary and will overlap the center element if the screen width is too small. Of course I could add media queries to constantly change the position but it looks ugly. I would like it to appear nice and responsive.
Perhaps this is not possible without taking an element out of flow? Any help is appreciated.
2
Answers
Repeat the element that you have on the right on the left side as well, and make it invisible. That will give you the balance you are looking for.
Here is another implementation that relies on flexbox to accomplish the desired result. There is still the use of a ‘spacer’ on the left side to ensure that the space is divided properly. It also wont wrap but I’m not sure if you want it to wrap when the screen get’s too small or not so I just left it as is.