Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input date, how to decrease space between date and icon?

Tags:

html

css

I need to compress an input type date, so i've tried setting the width to 120px.
The problem is that there's a space between the date numbers and the input date icon.

I need to decrease or remove that space:

enter image description here

Is there a way to do that?

My code (I'm using bootstrap 4 btw):

<input type="date">
like image 780
Roberto Sepúlveda Avatar asked Dec 22 '20 13:12

Roberto Sepúlveda


People also ask

How do I style a date icon in CSS?

Add input[type="date"] before selectors. Just copy-paste this CSS and add it to your own CSS code.

How do I limit the date selection in HTML?

You can add a min or max attribute to the input type=date . The date must be in ISO format (yyyy-mm-dd). This is supported in many mobile browsers and current versions of Chrome, although users can manually enter an invalid date without using the datepicker.

How do you set a date range in HTML?

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. If min and max values are not set then default min value is set to “01-01-1920” and default max value is set to “01-01-2120”.

How do I change the input date format in HTML?

Users can type a date value into the text field of an input[type=date] with the date format shown in the box as gray text. This format is obtained from the operating system's setting. Web authors have no way to change the date format because there currently is no standards to specify the format.


2 Answers

You can use:

::-webkit-calendar-picker-indicator{
    margin-left: 0px;
}

If this is not enough, and you want even less space, just put a negative margin, like in this snippet:

    ::-webkit-calendar-picker-indicator{
        margin-left: -15px;
    }
<input type="date" >

Note: This works in Chrome. Firefox (and possibly other browsers) may not show the icon by default.

like image 152
clod9353 Avatar answered Sep 21 '22 07:09

clod9353


You can target the icon by using the following css selector: ::-webkit-calendar-picker-indicator

To increase the margin, use:

input[type=date]::-webkit-calendar-picker-indicator {
  margin-left: 100px;
}
<input type="date">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

To decrease the space, use a negative margin, or any other option.

like image 35
0stone0 Avatar answered Sep 19 '22 07:09

0stone0