Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date inputs cannot be aligned right on iOS7

tl;dr, Here the test, iOS7 can't right-align date inputs: http://cdpn.io/dxjHy

Consider this HTML:

<input type="date" id="test">

And this CSS:

#test {
  -webkit-appearance:none;
  -moz-appearance:none;
  appearance:none;

  text-align:right;
  padding:30px;
  width:400px;
  font-size:20px;
}

Safari on iOS7 doesn't want to right-align the text in the date input. My opinion is that Chrome's interpretation is the correct one. Any ideas on how to make Safari cooperate?

Chrome 30:

Chrome

Safari Mobile on iOS7, iPad:

iOS7

like image 847
Rémi Breton Avatar asked Oct 11 '13 15:10

Rémi Breton


2 Answers

I've found a solution that works great. This seems to be the culprit, in Safari's stylesheet of input[type=date]

display: -webkit-inline-flex;

Add this to your CSS...

input[type=date] {
    display:block;
    -webkit-appearance:button;
    -moz-appearance:button;
    appearance:button;
}

...and now your input will be able to understand text-align:right; correctly.

like image 97
Rémi Breton Avatar answered Oct 22 '22 14:10

Rémi Breton


We had the same problem in my office, we made a workaround.

<div> 
    <input type="date" id="test">
</div>

and for the css

div{
    position:relative;
    width:100%
}
input[type="date"]{
    position:absolute;
    width:auto;
    right:0;
}

Hope, it can help you.

like image 44
Hoshibe Avatar answered Oct 22 '22 13:10

Hoshibe