[装飾系]リストデザイン リストそれぞれ色を変えHOVERで背景が変わる

CSS HTML
 2018.01.15
 2018.03.23

リストそれぞれ色を変えHOVERで背景が変わる

リストそれぞれの色を変えたデザインです。
HOVERで背景が変わります。

:nth-child(n)を使うことで、n番目の設定が可能です。
browser:  65 11 20 10 
ニャン易度 
  1. css
  2. html
  3. copy
  4. easy
<ol class="cp_clist">
	<li>css</li>
	<li>html</li>
	<li>copy</li>
	<li>easy</li>
</ol>
ol.cp_clist {
	counter-reset:cp_clist;
	list-style: none;
	padding:0.5em;
}
ol.cp_clist li {
	position: relative;
	line-height: 28px;
	margin: 10px 0;
	padding-left: 40px;
	transition: 0.3s;
}
ol.cp_clist li:nth-child(4n+1){
	border: 1px dotted #f1c6c6;
}
ol.cp_clist li:nth-child(4n+2){
	border: 1px dotted #8cd9bc;
}
ol.cp_clist li:nth-child(4n+3){
	border: 1px dotted #9575CD;
}
ol.cp_clist li:nth-child(4n+4){
	border: 1px dotted #f8e5ab;
}
ol.cp_clist li:before {
	position: absolute;
	top: 50%;
	left: -1px;
	counter-increment: cp_clist;
	content: counter(cp_clist);
	padding: 0 0.2em 0 0.2em;
	font-weight: bold;
	color: #fff;
	text-align: center;
	line-height: 30px;
	width: 30px;
	height: 30px;
	transform: translateY(-50%);
}
ol.cp_clist li:nth-child(4n+1):before{
	background: #F06292;
}
ol.cp_clist li:nth-child(4n+2):before{
	background: #4DB6AC;
}
ol.cp_clist li:nth-child(4n+3):before{
	background: #9575CD;
}
ol.cp_clist li:nth-child(4n+4):before{
	background: #FFB74D;
}
ol.cp_clist li:hover {
	color:#fff;
	overflow: hidden;
	z-index: 1;
}
ol.cp_clist li:nth-child(4n+1):hover{
	background: #F06292;
}
ol.cp_clist li:nth-child(4n+1):hover:before{
	background: #fff;
	color: #F06292;
}
ol.cp_clist li:nth-child(4n+2):hover{
	background: #4DB6AC;
}
ol.cp_clist li:nth-child(4n+2):hover:before{
	background: #fff;
	color: #4DB6AC;
}
ol.cp_clist li:nth-child(4n+3):hover{
	background: #9575CD;
}
ol.cp_clist li:nth-child(4n+3):hover:before{
	background: #fff;
	color: #9575CD;
}
ol.cp_clist li:nth-child(4n+4):hover{
	background: #FFB74D;
}
ol.cp_clist li:nth-child(4n+4):hover:before{
	background: #fff;
	color: #FFB74D;
}

copypet.jp

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

More Info

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