[装飾系]Input Text フォーカスで下線の色が両端から替わる

CSS HTML
 2018.02.01
 2018.03.22

フォーカで下線の色が両端から替わる

よりシンプルな下線のみのInput Textデザインですが、フォーカス下線の色が両端から切り替わります。
さらにエリアにあった名前が上に上がります。

browser:  65 11 20 10 
ニャン易度 
<div class="cp_iptxt">
	<input class="ef" type="text" placeholder="">
	<label>お名前</label>
	<span class="focus_line"></span>
</div>
.cp_iptxt {
	position: relative;
	width: 80%;
	margin: 40px 3%;
}
.cp_iptxt input[type='text'] {
	font: 15px/24px sans-serif;
	box-sizing: border-box;
	width: 100%;
	letter-spacing: 1px;
	padding-left: 4em;
}
.cp_iptxt input[type='text']:focus {
	outline: none;
}
.ef {
	padding: 4px 0;
	border: 0;
	border-bottom: 1px solid #1b2538;
	background-color: transparent;
}
.ef ~ .focus_line {
	position: absolute;
	z-index: 99;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 2px;
}
.ef ~ .focus_line:before,
.ef ~ .focus_line:after {
	position: absolute;
	bottom: 0;
	left: 0;
	width: 0;
	height: 100%;
	content: '';
	transition: 0.4s;
	background-color: #da3c41;
}
.ef ~ .focus_line:after {
	right: 0;
	left: auto;
}
.ef:focus ~ .focus_line:before,
.ef:focus ~ .focus_line:after,
.cp_iptxt.ef ~ .focus_line:before,
.cp_iptxt.ef ~ .focus_line:after {
	width: 50%;
	transition: 0.4s;
}
.ef ~ label {
	position: absolute;
	z-index: -1;
	top: 4px;
	left: 0;
	width: 100%;
	transition: 0.3s;
	letter-spacing: 0.5px;
	color: #aaaaaa;
}
.ef:focus ~ label,
.cp_iptxt.ef ~ label {
	font-size: 12px;
	top: -16px;
	transition: 0.3s;
	color: #da3c41;
}

copypet.jp

CSS3などで新たに追加された要素・装飾方法など、日々コードを書いていないと忘れてしまったり、ささっとプロトタイプを作る時などちょっとしたことに時間をかけている暇はない。そんな時に「あ〜、あれストックしときゃよかったなぁ」って困った自分用のストックブログです。カスタマイズなどがしやすいよう、昨今のweb制作に取り入れられる一般的なコードを中心に掲載しています。

More Info

こんな記事はいかがですか?