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:
Is there a way to do that?
My code (I'm using bootstrap 4 btw):
<input type="date">
Add input[type="date"] before selectors. Just copy-paste this CSS and add it to your own CSS code.
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.
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”.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With