Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set width of native html5 date and time pickers on iOS devices

Tags:

I'm using the native date and time pickers with type=date and type=time for the mobile version of a website I'm working on. The input fields are not respecting the css I have, though.

Desktop:

Desktop

iOS devices: enter image description here

Essentially I need the two date and time inputs to fill ~50% of the width. This is the html and css I'm using:

<div class="arriveWrapper">             <div class="arriveDateWrapper fieldWrapper">                 <input class="arriveDate" name="arriveDate" type="date" placeholder="What date?" />             </div>             <div class="arriveTimeWrapper fieldWrapper">                 <input class="arriveTime" name="arriveTime" type="time" placeholder="What time?" />             </div>             <div class="clear"></div>         </div>   .arriveDateWrapper {     width: 49%;     margin-right: 2%;     float: left;     position: relative; }          .arriveDate {             width: 100%;             height: 28px;             -moz-box-sizing: border-box;             -webkit-box-sizing: border-box;             box-sizing: border-box;         }  .arriveTimeWrapper {     width: 49%;     float: left; }      .arriveTime {         width: 100%;         height: 28px;         -moz-box-sizing: border-box;         -webkit-box-sizing: border-box;         box-sizing: border-box;     } 

If anyone can tell me how to get the placeholders to show up when using the native date/time pickers that would be great, as well.

Thanks!

like image 528
jdehlin Avatar asked Apr 06 '13 23:04

jdehlin


People also ask

How do I change the date picker format in HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

Are there any style options for the html5 date picker?

Currently, there is no cross browser, script-free way of styling a native date picker. As for what's going on inside WHATWG/W3C... If this functionality does emerge, it will likely be under the CSS-UI standard or some Shadow DOM-related standard.

What is date picker in HTML?

The <input type="date"> defines a date picker. The resulting value includes the year, month, and day. Tip: Always add the <label> tag for best accessibility practices!


2 Answers

Just add this to your styles

.arriveDate, .arriveTime  {   -webkit-appearance: none;   -moz-appearance: none; } 

The reason behind this is that IOS device render by default the inputs using the IOS buttons

like image 181
wandarkaf Avatar answered Sep 20 '22 07:09

wandarkaf


To avoid losing any style elements applied to other input boxes, use textfield instead of none.

.arriveDate, .arriveTime  {   -webkit-appearance: textfield;   -moz-appearance: textfield; } 

Also, if you just want to make all the date fields appear like textboxes but still work like date fields...

input[type="date"] {     display:block;     -webkit-appearance: textfield;     -moz-appearance: textfield;     min-height: 1.2em; } 
like image 32
Carter Medlin Avatar answered Sep 20 '22 07:09

Carter Medlin