代码之家  ›  专栏  ›  技术社区  ›  basickarl

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

  •  2
  • basickarl  · 技术社区  · 7 年前

    我正试图找到一个解释如何完全格式化输入类型“time”的来源。我找不到一个例子来解释所有的样式属性!

    我只找到一个:

    input[type="time"]{
        /**style goes here **/
    }
    

    这没什么帮助。

    试过这个:

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

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

    0 回复  |  直到 7 年前
        1
  •  2
  •   tryenc    7 年前

    我在chrome/webkit中的输入样式化方面取得了一些进展,但是我不知道如何在firefox中设置任何样式。这是一个 demo 我把它放在密码笔上。

    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;
    }
    <input type="time" value="13:30"/>

    我在任何地方都找不到文件。通过检查输入的内部dom,将鼠标悬停在devtools中的每个元素上,查看它对应的ui的哪个部分,然后获取它的 pseudo 属性。

    如果当前无法看到内部dom,则必须进入chrome的devtools设置、首选项、元素,并确保启用了“show user agent shadow dom”选项来公开它。

    推荐文章