小编典典

如何在输入日期字段上模拟占位符功能?

html

在日期字段上不能使用占位符,但我确实需要它。

我想要两个日期输入,每个文本上都有文本“ From”和“ To”作为占位符。


阅读 470

收藏
2020-05-10

共1个答案

小编典典

我正在使用以下CSS绝招:

  input[type="date"]:before {

    content: attr(placeholder) !important;

    color: #aaa;

    margin-right: 0.5em;

  }

  input[type="date"]:focus:before,

  input[type="date"]:valid:before {

    content: "";

  }


<input type="date" placeholder="Choose a Date" />
2020-05-10