Table of Contents
How does it work?
:placeholder-showdMust have placeholder
##:placeholder-shown vs ::placeholder Therefore, We can use
:placeholder-shown vs :empty although
Okay, so the only way we can check if the input is empty is to use
So, we can target input elements that display placeholder text, which is cool . In other words, if placeholder text is displayed, it must mean that the element is empty. Using this knowledge, we can combine this pseudo-class with other selectors and do some really neat things! let's see.
:placeholder-shown For :not we can use
浮动标签
浏览器支持
Home Web Front-end CSS Tutorial What is :placeholder-shown in CSS? how to work? What is the use?

What is :placeholder-shown in CSS? how to work? What is the use?

Jul 06, 2021 am 10:44 AM
css3

CSS :placeholder-shown pseudo-class is an object specifically used to determine whether an element displays a placeholder. It is mainly used to check whether the input content is empty. This article will take you through: placeholder-shown pseudo-class and introduce in detail how it works.

What is :placeholder-shown in CSS? how to work? What is the use?

Use this pseudo-class to style an input that is currently displaying placeholder text, in other words, the user is not typing anything in the text box

It would be nice to apply some dynamic styling depending on whether your input is empty or not

input:placeholder-shown {
  border-color: pink;
}
Copy after login
Copy after login
Copy after login

What is :placeholder-shown in CSS? how to work? What is the use?

How does it work?

:placeholder-show is a CSS pseudo-class that allows you to apply styles to <input> or ## that have placeholder text #