I have created a form with some text elements aligned vertically like so:
They are centered horizontally and vertically on the page using flexbox:
.my-class {
display: flex;
justify-content: center;
align-items: center;
flex-direction:column;
}
What I'm trying to do now is maintain this alignment (i.e. keep everything that's on the page already exactly where it is) while adding some elements on either side of the first text box. I tried wrapping everything in a div
but since the elements on either side of the text box are not the same width, the text box loses its alignment:
As you can see, the long text boxes are now out of alignment. How can I add elements before and after the first text box without moving where it is?
Assuming it is the url/pass/button that are the one's to be centered, and the https/path stick on each side, I would do it like this, where I use a flex row container and pseudo elements to break each group of item into lines of their own.
With this markup one also have full control to move around the items based on screen width's etc.
The 2 main things making this work is the pseudo elements, that, with their full width, force them into rows of their own, and at the same time push content down, together with the
order
property, enable to position them before the pass and auth respectively.Stack snippet
If the width of the url/pass should scale with parent's width, use percent combined with CSS Calc.
Stack snippet
Another option would be to keep the initial flex column direction, and with an extra wrapper use absolute positioning for the http(s)/path items.
Updated (based on another question with a similar need)
One can also keep the simpler markup, with no extra wrapper, and use
inline-flex
combine with making theflex
parent also a flex container.Stack snippet