Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Line-through input value, but not placeholder

I got a html input, and want to add a

text-decoration: line-through;

to the value (if validation fails, which sets a specific css class).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t want that to appear on the placeholder though, which I tried to fix by adding a

input::placeholder {
   text-decoration: none; 
}

Unfortunately that doesn’t work.
Is there any way to achieve this?

>Solution :

Use :not(:placeholder-shown) to exclude the case when you have the placeholder

input.error:not(:placeholder-shown) {
  text-decoration: line-through;
}
<input type="text" placeholder="example" class="error">

<input type="text" placeholder="example">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading