Styling input[type='date'] for non-Chrome browsers with CSS

Looking for the css equivalent of:

::-webkit-datetime-edit
::-webkit-datetime-edit-fields-wrapper
::-webkit-datetime-edit-text
::-webkit-datetime-edit-month-field
::-webkit-datetime-edit-day-field
::-webkit-datetime-edit-year-field
::-webkit-inner-spin-button
::-webkit-calendar-picker-indicator

in Firefox and Microsoft Edge. I have not been able to find any resources or documentation on styling placeholders for <input type='date'>. Any suggestions or solutions would be greatly appreciated.

I have tried using ::placeholder, ::-ms-input-placeholder, and ::-moz-placeholder, but none seem to work when the input type is date.

Alternatively, I would appreciate if someone could provide a way to hide the default placeholder text.

Answer №1

After inspecting the HTML and CSS with F12 developer tools, it becomes evident that Chrome browser utilizes a user agent stylesheet which applies pseudo-elements (::webkit) specific to Chrome. However, in Microsoft Edge browser, there is no usage of a user agent stylesheet, resulting in the pseudo-elements not being applied to the input date textbox. As a consequence, the code does not function correctly in Microsoft Edge.

To address this issue, one potential solution is to utilize the Microsoft Edge Dev version (chromium based), where the code performs effectively.

Alternatively, as a workaround, you can consider using the provided code snippet below, which implements a text box and datepicker plugin for displaying the date:

<style>
    .input-field {
        position: relative;
        display: inline-block;
    }

        .input-field > label {
            position: absolute;
            left: 0.5em;
            top: 50%;
            margin-top: -0.5em;
            opacity: 0.5;
        }

        .input-field > input[type=text]:focus + label {
            display: none;
        }

        .input-field > label > span {
            letter-spacing: -2px;
        }

    .month {
        color: cornflowerblue;
    }

    .day {
        color: aqua;
    }

    .year {
        color: darkmagenta
    }

    .separate-letter {
        color: red
    }
</style>
<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<div class="input-field">
    <input id="input-text-field" type="text" class="date" data-selecteddate="" value="" />
    <label for="input-text-field">
        <span id="span_month" class="month">MM</span>
        <span class="separate-letter">/</span>
        <span  id="span_day" class="day">DD</span>
        <span class="separate-letter">/</span>
        <span id="span_year" class="year">YYYY</span>
    </label>
</div>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
    $(function ($) {
        $(".date").datepicker({
            onSelect: function (dateText) {
                var dataarray = dateText.split("/")
                $("#span_month").html(dataarray[0]);
                $("#span_day").html(dataarray[1]);
                $("#span_year").html(dataarray[2]);

                this.value = "";
                $("#input-text-field").attr("data-selecteddate", dateText);
            }
        })            
    });
</script>

The expected result when using Microsoft Edge browser can be viewed in the following gif: https://i.sstatic.net/Ow7Q0.gif

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for distinguishing the beginning and ending points of wrapped text in the Firefox browser

Within my work, I am utilizing a contentEditable span where I aim to position an element with position: absolute on the same line as the cursor. However, issues arise when text wrapping occurs - causing abnormal behavior at the start and end of wrapped lin ...

Looking to authenticate a CSS span class within an XML document using Oxygen Program?

This is in connection with my initial query. The XML does not recognize the CSS span class. <l rend="indent"> <span class="face_dropcap_ ">C</span><hi rend="initial_roman">E</hi>stoit alors que le prefent des <span class= ...

CSS Accordion Collapse Widget

I currently have a CSS collapse accordion created using pure CSS, and it is functioning perfectly. However, I am facing one issue: When the user clicks on any label - Label One, Label Two, or Label Three, they are unable to close it by clicking on the sam ...

Angular 6 and Bootstrap 4 Collaborate for a Dynamic Multi-Level NavBar

(UPDATE: Issue Resolved - I discovered that I needed to include the JavaScript within $(document).ready(function()), which was previously missing. The example below worked perfectly for me.) I am attempting to implement a Multi-Level Navbar with Angular 6 ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Why does the styling of the inner Span adhere to the style of the outer Span?

How can I adjust the opacity of the color "blue" to 1 in the code snippet below? <!DOCTYPE html> <html> <body> <p>My mom's eyes are <span style="color:blue;font-weight:bold;opacity:0"> <span style="color:blue;fo ...

Updating text inputs in Angular can be done more efficiently using Angular Update

I need to make adjustments to an Angular application so that it can run smoothly on older machines. Is there a more efficient method for updating a text input field without using (keyup) to update after each keystroke? I haven't been able to find any ...

Craft a Unique Responsive Background Design

I'm eager to create a background like this, but I'm struggling to figure out the best approach. My attempt with transform: skewY(-6deg) ended up skewing my entire page instead of just the background. Could someone please assist me in finding th ...

Adjust the baseline of the text within the <li> element by moving it 2 pixels upwards

My webpage menu is set up with inline lis within a ul. Each li has a colored border and contains an a element. I want to change the color of the text inside the a element and move it 2 pixels up when hovering over it without affecting the li border. How ...

Sorting through a table based on the name of the element

I am currently working on filtering an HTML table using a search form. It's working great, but I'm facing an issue where the filtered elements are trying to fill the entire width of the table instead of maintaining their original width (which is ...

Adhesive Navigation Bar

Check out this link: JSFIDDLE $('.main-menu').addClass('fixed'); Why does the fixed element flicker when the fixed class is applied? ...

Show Struts2 error message on an HTML webpage

I have included error and message handling in my Struts2 action class using the addActionMessage and addActionError methods. I am now looking for code that will allow me to display these messages and errors on the HTML page. Is it feasible to do so? ...

Difficulty in managing vertical overflow in a dynamically sized table using Bootstrap

I am facing an issue with the table-responsive class that is causing a scroll on the y-axis even though it is not specified in the CSS. Shown below is a screenshot of the problem, and I have also managed to replicate the bug: <div id="app"> <d ...

Hide the Bootstrap slide menu with jQuery by clicking anywhere on the screen

Here is a Fiddle link: https://jsfiddle.net/r94dq2e4/ I have incorporated a slide-in menu from the left in my website using Twitter Bootstrap version 3. The menu appears when the navbar toggle button is clicked. This is the jQuery code responsible for ...

Check if already logged in using Python's Selenium module

Currently, I am working on automating certain tasks and occasionally the program requires logging in. I am looking for a way to verify if the system is already logged in and to automatically log in if it is not. The website I am dealing with is the admin ...

The TouchableOpacity function is triggered every time I press on the Textinput

Every time I press on a text input field, the login function is called This is the touchable statement: <TouchableOpacity style={InputFieldStyle.submitButton} onPress={this.login(this.state.email, this.state.password)}> <Text ...

Adjusting the image width to a set height requirement

When working with images, it can be tricky to maintain the aspect ratio. For example, if you have an image set to a specific height like 500px within a div that is 960px wide, the image may stretch to fill the width. This can distort the image and give ver ...

Employing bootstrap to include oversized images within a compact, fixed div

I am facing an issue with image responsiveness in the middle row of my layout. Despite using Bootstrap 4 and applying classes like img-fluid, the images in my #fullColumn area do not resize properly. The images are dragged into this area by users and are ...

What is the best way to emphasize this specific section of text?

Looking for help with my tumblr template. I have the following block of code: {block:IfNotEndlessScroll}{block:Pagination}{block:PreviousPage}Previous Page{/block:PreviousPage} {block:NextPage}Next Page{/block:NextPage}{/block:Pagination}{/block:IfN ...

Encircle a circle within the Progress Tracker

Is there a way to create a ring around the circle in this progress tracker, similar to the image shown here? The progress tracker is based on You can view an example here. The CSS approach used was: .progress-step.is-active .progress-marker { backgrou ...