search
HomeWeb Front-endCSS TutorialIntroduction to how to modify placeholder style with CSS (code example)

The content of this article is an introduction to the method of modifying the placeholder style with CSS. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Project users often encounter the need to modify the color of the input placeholder. Here is a look at how to set the placeholder with css:

First, let’s take a look at the default input style of chrome

<input>

(placeholder)

Introduction to how to modify placeholder style with CSS (code example)

(input style)

Introduction to how to modify placeholder style with CSS (code example)

##It can be found that

placeholder and The default color of input is a little different. Now let's modify the color of input

<input>
(placeholder)

Introduction to how to modify placeholder style with CSS (code example)

(input)

Introduction to how to modify placeholder style with CSS (code example)

It is not difficult to find that the

color attribute can only change the color of the input value, but the color of placeholder does not change at all. So, how to change the color of placeholder.

To change the color of

placeholder, you need to use the pseudo class ::placeholder


<input>
(placeholder)

Introduction to how to modify placeholder style with CSS (code example)

(input)

Introduction to how to modify placeholder style with CSS (code example)

It should be noted that the compatibility of

::placeholder pseudo-class, the above is in the chrome browser The running result, the same code becomes like this in IE11

(placeholder - ie11)

Introduction to how to modify placeholder style with CSS (code example)

(input - ie11)

Introduction to how to modify placeholder style with CSS (code example)

IE solution:

First of all, IE9 and below do not support placeholder. IE10 needs to use

:-ms-input-placeholder, and the attribute needs to be added with !important to increase the priority.


<input>
(placeholder ie11)

Introduction to how to modify placeholder style with CSS (code example)

(input ie11)

Introduction to how to modify placeholder style with CSS (code example)

Give other views after Device adaptation scheme

/* - Chrome ≤56,
   - Safari 5-10.0
   - iOS Safari 4.2-10.2
   - Opera 15-43
   - Opera Mobile >12
   - Android Browser 2.1-4.4.4
   - Samsung Internet
   - UC Browser for Android
   - QQ Browser */
::-webkit-input-placeholder {
    color: #ccc;
    font-weight: 400;
}

/* Firefox 4-18 */
:-moz-placeholder {
    color: #ccc;
    font-weight: 400;
}

/* Firefox 19-50 */
::-moz-placeholder {
    color: #ccc;
    font-weight: 400;
}

/* - Internet Explorer 10–11
   - Internet Explorer Mobile 10-11 */
:-ms-input-placeholder {
    color: #ccc !important;
    font-weight: 400 !important;
}

/* Edge (also supports ::-webkit-input-placeholder) */
::-ms-input-placeholder {
    color: #ccc;
    font-weight: 400;
}

/* CSS Working Draft */
::placeholder {
    color: #ccc;
    font-weight: 400;
}
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

The above is the detailed content of Introduction to how to modify placeholder style with CSS (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault 思否. If there is any infringement, please contact admin@php.cn delete
What does margin: 40px 100px 120px 80px signify?What does margin: 40px 100px 120px 80px signify?Apr 28, 2025 pm 05:31 PM

Article discusses CSS margin property, specifically "margin: 40px 100px 120px 80px", its application, and effects on webpage layout.

What are the different CSS border properties?What are the different CSS border properties?Apr 28, 2025 pm 05:30 PM

The article discusses CSS border properties, focusing on customization, best practices, and responsiveness. Main argument: border-radius is most effective for responsive designs.

What are CSS backgrounds, list the properties?What are CSS backgrounds, list the properties?Apr 28, 2025 pm 05:29 PM

The article discusses CSS background properties, their uses in enhancing website design, and common mistakes to avoid. Key focus is on responsive design using background-size.

What are CSS HSL Colors?What are CSS HSL Colors?Apr 28, 2025 pm 05:28 PM

Article discusses CSS HSL colors, their use in web design, and advantages over RGB. Main focus is on enhancing design and accessibility through intuitive color manipulation.

How can we add comments in CSS?How can we add comments in CSS?Apr 28, 2025 pm 05:27 PM

The article discusses the use of comments in CSS, detailing single-line and multi-line comment syntaxes. It argues that comments enhance code readability, maintainability, and collaboration, but may impact website performance if not managed properly.

What are CSS Selectors?What are CSS Selectors?Apr 28, 2025 pm 05:26 PM

The article discusses CSS Selectors, their types, and usage for styling HTML elements. It compares ID and class selectors and addresses performance issues with complex selectors.

Which type of CSS holds the highest priority?Which type of CSS holds the highest priority?Apr 28, 2025 pm 05:25 PM

The article discusses CSS priority, focusing on inline styles having the highest specificity. It explains specificity levels, overriding methods, and debugging tools for managing CSS conflicts.

What is the syntax for CSS?What is the syntax for CSS?Apr 28, 2025 pm 05:23 PM

Article discusses CSS syntax, learning strategies, common mistakes, and validation tools. Main focus is on mastering CSS through practice and understanding.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor