Change color of Chrome's calendar icon in HTML Date Input

后端 未结 3 1172
北恋
北恋 2021-01-11 11:36

I am having some difficulty styling the HTML 5 Date input in Chrome.

Using mark up such as

相关标签:
3条回答
  • 2021-01-11 11:51

    You can actually get rather creative using the filter property.

    • invert(100%) turns the icon white
    • brightness(50%) makes it gray
    • sepia(100%) saturates it and makes it... sepia
    • saturate(10000%) pumps the saturation up and turns it bright red

    After that you can play around with hue-rotate to change the hue. hue-rotate(240deg) turns it blue, hue-rotate(120deg) turns it green etc. If you want to get a really specific color you should check out this question on how to transform black into any given color using only CSS filters.

    0 讨论(0)
  • 2021-01-11 11:55

    Another example is;

    input[type="date"]::-webkit-calendar-picker-indicator {
      cursor: pointer;
      border-radius: 4px;
      margin-right: 2px;
      opacity: 0.6;
      filter: invert(0.8);
    }
    
    input[type="date"]::-webkit-calendar-picker-indicator:hover {
      opacity: 1
    }
    
    0 讨论(0)
  • 2021-01-11 11:57

    I've managed to work around it for now using a CSS filter to invert the black color to white

    ::-webkit-calendar-picker-indicator {
        filter: invert(1);
    }
    

    However this feels quite fragile and far from ideal.

    0 讨论(0)
提交回复
热议问题