如何设置输入类型“时间”的样式

Kar*_*son 5 html css

我试图找到一个解释如何完全设置输入类型“时间”的来源。我找不到解释所有样式属性的单个示例!

我发现的只有一个是:

input[type="time"]{
    /**style goes here **/
}
Run Code Online (Sandbox Code Playgroud)

这没有多大帮助..

试过这个:

input[type="time"]::-webkit-inner-spin-button { 
    -webkit-appearance: none;
    cursor:pointer;
    display: block;
    width:20px;
    color: red;
    text-align:center;
    position:relative;
} 
Run Code Online (Sandbox Code Playgroud)

例如,微调器不会变成红色。

小智 11

我在 Chrome/webkit 中设置输入样式取得了一些进展,但我不知道如何在 Firefox 中设置任何样式。这是我放在 Codepen 上的一个演示

input[type=time] {
  border: none;
  color: #2a2c2d;
  font-size: 14px;
  font-family: helvetica;
  width: 180px;
}

/* Wrapper around the hour, minute, second, and am/pm fields as well as 
the up and down buttons and the 'X' button */
input[type=time]::-webkit-datetime-edit-fields-wrapper {
  display: flex;
}

/* The space between the fields - between hour and minute, the minute and 
second, second and am/pm */
input[type=time]::-webkit-datetime-edit-text {
  padding: 19px 4px;
}

/* The naming convention for the hour, minute, second, and am/pm field is
`-webkit-datetime-edit-{field}-field` */

/* Hour */
input[type=time]::-webkit-datetime-edit-hour-field {
  background-color: #f2f4f5;
  border-radius: 15%;
  padding: 19px 13px;
}

/* Minute */
input[type=time]::-webkit-datetime-edit-minute-field {
  background-color: #f2f4f5;
  border-radius: 15%;
  padding: 19px 13px;
}

/* AM/PM */
input[type=time]::-webkit-datetime-edit-ampm-field {
  background-color: #7155d3;
  border-radius: 15%;
  color: #fff;
  padding: 19px 13px;
}

/* 'X' button for resetting/clearing time */
input[type=time]::-webkit-clear-button {
  display: none;
}

/* Up/Down arrows for incrementing/decrementing the value */
input[type=time]::-webkit-inner-spin-button {
  display: none;
}
Run Code Online (Sandbox Code Playgroud)
<input type="time" value="13:30"/>
Run Code Online (Sandbox Code Playgroud)

我无法在任何地方找到文档。我通过检查输入的内部 DOM,将鼠标悬停在 devTools 中的每个元素上以查看它对应于 UI 的哪个部分,然后获取其pseudo属性。

如果您当前看不到内部 DOM,则必须通过进入 Chrome 的 DevTools 设置、首选项、元素并确保启用“显示用户代理影子 DOM”选项来公开它。


ier*_*dna 5

还有另一个伪元素:-webkit-calendar-picker-indicator- 在 chrome 中显示的时钟,允许您使用鼠标选择时间。

input[type="time"]::-webkit-calendar-picker-indicator {
   filter: invert(0.5) sepia(1) saturate(5) hue-rotate(175deg);
}
Run Code Online (Sandbox Code Playgroud)
<input type="time">
Run Code Online (Sandbox Code Playgroud)