0

I want to style my input field but somehow I have to detect if this input has placeholder attribute and if is actually filled. I would like to avoid JS stuff to do it, so my question is: Is there any css trick so i can target this specific selector?

Currently i have:

<input type="text" placeholder="">

input[placeholder] {
 // my styles
}

but this applies styles anyway. Thanks for your help.

1 Answer 1

4

You can use the :not() selector like

[placeholder]:not([placeholder=""]) {
  background: green;
}
<input type="text" placeholder="">

<input type="text" placeholder="test">

Sign up to request clarification or add additional context in comments.

1 Comment

How the.. I didn't thought about :not() selector. Thank you sir :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.