To ensure consistency, it is important to apply the same CSS properties to both the input element and the span element.
input,span{
float: left; /* Helps remove any gaps */
line-height: 15px; /* Centers by matching the height value */
height: 15px; /* Ensures equal height for both elements */
}
span{
border: 1px solid transparent;
border-left-width: 0px; /* Removes left border to reduce spacing */
}
The reason for styling the span element with a border is because the input element already has a default border in place.
See the working example here
Alternatively
You can also utilize display: table-cell
to achieve similar results:
input, span {
display: table-cell;
vertical-align: middle;
}
input {
outline: none;
padding: 0px;
margin: 0px;
}
body { /* or parent element */
display: table;
}
See the alternative example here