A Pen by JowayYoung on CodePen.
Created
November 3, 2019 12:13
-
-
Save mqxu/c2113cc7e37b8f000d99c2b5ab79da41 to your computer and use it in GitHub Desktop.
【iCSS:行为】使用:valid和:invalid校验表单
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="bruce flex-ct-x"> | |
<form class="form-validation"> | |
<div> | |
<label>名字</label> | |
<input type="text" placeholder="请输入你的名字(1到10个中文)" pattern="^[\u4e00-\u9fa5]{1,10}$" required> | |
</div> | |
<div> | |
<label>手机</label> | |
<input type="text" placeholder="请输入你的手机" pattern="^1[3456789]\d{9}$" required> | |
</div> | |
<div> | |
<label>简介</label> | |
<textarea required></textarea> | |
</div> | |
</form> | |
</div> |
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
.form-validation { | |
width: 500px; | |
div { | |
margin-top: 10px; | |
&:first-child { | |
margin-top: 0; | |
} | |
} | |
label { | |
display: block; | |
padding-bottom: 5px; | |
font-weight: bold; | |
font-size: 16px; | |
} | |
input, | |
textarea { | |
display: block; | |
padding: 0 20px; | |
outline: none; | |
border: 1px solid #ccc; | |
width: 100%; | |
height: 40px; | |
caret-color: #09f; | |
transition: all 300ms; | |
&:valid { | |
border-color: #3c9; | |
box-shadow: inset 5px 0 0#3c9; | |
} | |
&:invalid { | |
border-color: #f66; | |
box-shadow: inset 5px 0 0 #f66; | |
} | |
} | |
textarea { | |
height: 122px; | |
resize: none; | |
line-height: 30px; | |
font-size: 16px; | |
} | |
} |
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
<link href="https://yangzw.vip/static/css/reset.css" rel="stylesheet" /> | |
<link href="https://yangzw.vip/static/css/main.css" rel="stylesheet" /> | |
<link href="https://yangzw.vip/static/css/theme.scss" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment