I have a design like below. Tried many things to customize input field but couldn’t make it.
Left side is fixed text and right side is input that user needs to enter.
How can I divide input as below and put a vertical line in it?
Should I combine 2 elements (I’m not sure if this is possible) or is there any way to customize input like this?
2
Answers
Thanks to comments I solved this as below.
Combining input with label worked. With right border for label created vertical line.
code is as below.
There is actually no way to have an element inside an input, because an input is a void element. The best solution here is to "combine" two elements.
here’s the solution:
Let’s take time to understand the magic:
There’s really nothing really hard except for the border. This comes from this website. you have a div element that contains the label and the input, and you want this element to use a linear gradient as a border. This could work with a
border-image
but you could not have aborder-radius
with it.Here you have a wrapper that has a
before
pseudo-class. this before element is placed right under the wrapper (z-index:-1
) So it takes exactly the same size, but is still contained inside the wrapper’s border. Adding a negative margin makes it overlap the wrapper’s transparent border, so you can actually only see a tiny part of the before element’s backgroundEdit: this isn’t flawless accessibility-wise, and you may want to adjust the input focused state to remove the outline. Be aware that input should have a visible difference between those states for accessibility purpose.