Home > Web Front-end > CSS Tutorial > How to Customize the Webkit Input[type=color] Color Picker Box?

How to Customize the Webkit Input[type=color] Color Picker Box?

Mary-Kate Olsen
Release: 2024-11-19 13:22:02
Original
777 people have browsed it

How to Customize the Webkit Input[type=color] Color Picker Box?

Customizing Webkit Input[type=color] Color Picker Box

With the introduction of a color picker in Chrome, users have encountered a grey box issue when setting both the color and background color of the input to the same value. To address this, Webkit provides specific CSS selectors to customize form controls.

Note: These selectors are not official and may break in future Webkit updates. Use them cautiously for personal projects only.

Method 1: Hiding Non-Colored Part

This method utilizes webkit-specific selectors to hide the non-colored portion of the input:

input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
}
Copy after login

This ensures that the input background color fully covers the color picker box.

Example HTML:

<input type=color value="#ff0000">
Copy after login

The above is the detailed content of How to Customize the Webkit Input[type=color] Color Picker Box?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template