James Kent James Kent - 4 months ago 13
CSS Question

Div and input not aligned properly in Safari

Got a problem with aligning a div and an input next to each other to create that classic input with icon. However, when I use Safari/Mac and Safari/iOS, it appears like this:

Broken in Safari

... and I just can't get my head around it! It's fine on Chrome and I've tried playing around with the floats, vertical align (don't know how relevant this is), but still nothing.

HTML:

<div class="input-with-icon">
<div class="icon">X</div>
<div class="input"><input type="text" placeholder="Start typing to find a customer..."></div>
</div>


CSS:

.input-with-icon .icon {
float: left;
background-color: #fff;
border-top: 1px solid #dcdcdc;
border-bottom: 1px solid #dcdcdc;
border-left: 1px solid #dcdcdc;
padding: 13px 0 14px 10px;
color: grey;
font-size: 14px;
border-radius: 5px 0 0 5px;
}

.input-with-icon .input {
overflow: hidden;
}

.input-with-icon input[type="text"]{
-webkit-appearance: none;
width: 100%;
outline: none;
font-size: 16px;
padding: 13px;
font-family: 'Roboto Light', sans-serif;
border-top: 1px solid #dcdcdc;
border-right: 1px solid #dcdcdc;
border-bottom: 1px solid #dcdcdc;
border-left: 0;
border-radius: 0 5px 5px 0;
}


Here's a fiddle if this helps you guys with my code - for some reason the right border doesn't want to work on the fiddle but not fussed about that bit as it's fine everywhere else.

https://jsfiddle.net/r08gxre3/1/

Any help would be much appreciated, thanks guys! :)

Answer

Just add margin: 0px; to your input element. It should be that!

Like:

.input-with-icon input[type="text"]{
    -webkit-appearance: none;
    width: 100%;
    outline: none;
    font-size: 16px;
    padding: 13px;
    font-family: 'Roboto Light', sans-serif;
    border-top: 1px solid #dcdcdc;
    border-right: 1px solid #dcdcdc;
    border-bottom: 1px solid #dcdcdc;
    border-left: 0;
    border-radius: 0 5px 5px 0;
    margin: 0px;
    /* or just margin-top: 0px; */
}

Fiddle: https://jsfiddle.net/bbdkzuyn/

Screenshot from safari