用于非Chrome浏览器的输入[type=#39;date&39;]的CSS样式 [英] CSS styling for input[type='date'] for browsers other than Chrome

查看:32
本文介绍了用于非Chrome浏览器的输入[type=#39;date&39;]的CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与

相同的css代码
::-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

适用于Firefox和Microsoft Edge?到目前为止,我找不到任何关于<input type='date'>占位符样式的文档/资源。感谢您的任何建议/答复。

尝试了::placeholder::-ms-input-placeholder::-moz-placeholder,但当输入类型为Date时,它们不起作用。

或者,如果有人能告诉我如何隐藏默认占位符,我很乐意接受答案。

推荐答案

通过使用F12开发工具检查Html和css,我们可以看到Chrome浏览器使用了用户代理系统表和这些伪元素(::-WebKit)应用于Chrome浏览器,但在Microsoft Edge浏览器中,它没有使用用户代理系统表,并且这些伪元素不应用于输入日期文本框。因此,代码在Microsoft Edge中不起作用。

所以,我认为您可以尝试使用Microsoft Edge Dev版本(基于铬),代码在上面运行得很好。

否则,作为一种解决办法,我建议您参考以下代码来使用文本框和日期选择器插件来显示日期。

<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) {
                //display("Selected date: " + dateText + "; input's current value: " + this.value);
                var dataarray = dateText.split("/")
                $("#span_month").html(dataarray[0]);
                $("#span_day").html(dataarray[1]);
                $("#span_year").html(dataarray[2]);

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

结果如下(使用Microsoft Edge浏览器):

这篇关于用于非Chrome浏览器的输入[type=#39;date&39;]的CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆