Created
January 5, 2022 11:06
-
-
Save elfacht/558d56ea48f32d7d75aad2e452aaa464 to your computer and use it in GitHub Desktop.
Check empty inputs with CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
width: 100%; | |
font: inherit; | |
padding: 0.25em 0.5em; | |
border: 0.125em solid hsl(30, 76%, 10%); | |
outline: none; | |
} | |
/* Show red borders when filled, but invalid */ | |
input:not(:placeholder-shown) { | |
border-color: hsl(0, 76%, 50%);; | |
} | |
/* Show green borders when valid */ | |
input:valid { | |
border-color: hsl(120, 76%, 50%); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="input"> | |
<label for="input" >Label </label> | |
<input type="text" name="input" id="input" required placeholder="Type something in here" pattern=".*\S.*"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment