[装飾系]セレクトボックス フォーカスで下線の色が真ん中から替わる

CSS HTML
 2018.02.05
 2018.03.22

フォーカスで下線の色が真ん中から替わる

フォーカスで下線の色が真ん中から替わるセレクトボックスです。

フォーカスの下線についての他の動きはこちら

copypet.jp

コピペでできる!cssとhtmlのみでフォームのテキストエリアをわかりやすくするデザイン15選 | copypet.jp

フォームはサイトにはかならず必要になってくるアイテムですが、わかりやすく間違えにくいものにしたいですよね。 テキストエリア[input type=”text”]のデザインにエフェクトを追加することで、 今までよりワンランク上のわかりやすさを手に入れましょう。…

copypet.jp

記事を見る

browser:  65 11 20 10 
ニャン易度 
<div class="cp_ipselect">
<select class="cp_sl06" required>
<option value="" hidden disabled selected></option>
<option value="1">cat</option>
<option value="2">dog</option>
<option value="3">rabbit</option>
<option value="4">squirrel</option>
</select>
<span class="cp_sl06_highlight"></span>
<span class="cp_sl06_selectbar"></span>
<label class="cp_sl06_selectlabel">Choose</label>
</div>
.cp_ipselect {
	position: relative;
	width: 90%;
	margin: 2em auto;
	text-align: center;
}
.cp_sl06 {
	position: relative;
	font-family: inherit;
	background-color: transparent;
	width: 100%;
	padding: 10px 10px 10px 0;
	font-size: 18px;
	border-radius: 0;
	border: none;
	border-bottom: 1px solid rgba(0,0,0, 0.3);
}
.cp_sl06:focus {
	outline: none;
	border-bottom: 1px solid rgba(0,0,0, 0);
}
.cp_ipselect .cp_sl06 {
	appearance: none;
	-webkit-appearance:none
}
.cp_ipselect select::-ms-expand {
	display: none;
}
.cp_ipselect:after {
	position: absolute;
	top: 18px;
	right: 10px;
	width: 0;
	height: 0;
	padding: 0;
	content: '';
	border-left: 6px solid transparent;
	border-right: 6px solid transparent;
	border-top: 6px solid rgba(0, 0, 0, 0.3);
	pointer-events: none;
}
.cp_sl06_selectlabel {
	color: rgba(0,0,0, 0.5);
	font-size: 18px;
	font-weight: normal;
	position: absolute;
	pointer-events: none;
	left: 0;
	top: 10px;
	transition: 0.2s ease all;
}
.cp_sl06:focus ~ .cp_sl06_selectlabel, .cp_sl06:valid ~ .cp_sl06_selectlabel {
	color: #da3c41;
	top: -20px;
	transition: 0.2s ease all;
	font-size: 14px;
}
.cp_sl06_selectbar {
	position: relative;
	display: block;
	width: 100%;
}
.cp_sl06_selectbar:before, .cp_sl06_selectbar:after {
	content: '';
	height: 2px;
	width: 0;
	bottom: 1px;
	position: absolute;
	background: #da3c41;
	transition: 0.2s ease all;
}
.cp_sl06_selectbar:before {
	left: 50%;
}
.cp_sl06_selectbar:after {
	right: 50%;
}
.cp_sl06:focus ~ .cp_sl06_selectbar:before, .cp_sl06:focus ~ .cp_sl06_selectbar:after {
	width: 50%;
}
.cp_sl06_highlight {
	position: absolute;
	top: 25%;
	left: 0;
	pointer-events: none;
	opacity: 0.5;
}

copypet.jp

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

More Info

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