radioボタンを今風にするデザインに変えていきたいと思います。11月24日記事

イメージ



目次





コード

HTML

<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="style.css">
	<title>ラジオボタンデザイン</title>
</head>

<body>
	<div class="sportschk">
		<input name="sports" id="select1" value="1" type="radio" checked>
		<label for="select1">サッカー</label>
		<input name="sports" id="select2" value="2" type="radio">
		<label for="select2">野球</label>
		<input name="sports" id="select3" value="3" type="radio">
		<label for="select3">ラグビー</label>
	</div>
</body>
</html>

CSS

@charset "utf-8";
/* CSS Document */

* {
	font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif;
}
.sportschk input {
	display: none;
}
.sportschk label {
	display: block;
	float: left;
	cursor: pointer;
	margin: 0;
	padding: 12px 5px;
	text-align: center;
	line-height: 1;
	transition: .2s;
	width: 80px;
	font-size: 14px;
	border-right: 1px solid #abb2b7;
	color: #999;
	/*押されてないその他*/
	
	background: #FFFFFF;
	filter: progid: DXImageTransform.Microsoft.gradient(startColorstr '#ffffff', endColorstr '#CCCCCC');
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ffffff', endColorstr = '#CCCCCC')";
	background: linear-gradient(top, #ffffff, #CCCCCC);
	background: -o-linear-gradient(top, #ffffff, #CCCCCC);
	background: -ms-linear-gradient(top, #ffffff, #CCCCCC);
	background: -moz-linear-gradient(top, #ffffff, #CCCCCC);
	background: -webkit-linear-gradient(top, #ffffff, #CCCCCC);
	background: -webkit-gradient(linear, center top, center bottom, from(#ffffff), to(#CCCCCC));
}
.sportschk label:first-of-type {
	border-radius: 3px 0 0 3px;
}
.sportschk label:last-of-type {
	border-right: 0px;
	border-radius: 0 3px 3px 0;
}
.sportschk input[type="radio"]:checked + label {
	/*押されてるとき*/
	
	color: #fff;
	background: #DB9400;
	filter: progid: DXImageTransform.Microsoft.gradient(startColorstr '#DB9400', endColorstr '#FFAA00');
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr = '#DB9400', endColorstr = '#FFAA00')";
	background: linear-gradient(top, #DB9400, #FFAA00);
	background: -o-linear-gradient(top, #DB9400, #FFAA00);
	background: -ms-linear-gradient(top, #DB9400, #FFAA00);
	background: -moz-linear-gradient(top, #DB9400, #FFAA00);
	background: -webkit-linear-gradient(top, #DB9400, #FFAA00);
	background: -webkit-gradient(linear, center top, center bottom, from(#DB9400), to(#FFAA00));
}



まとめ

影の付け方ですが、押された場合は上側は暗めに、下側は明るめに、押されている以外のものは上側は明るめに、下側は暗めにすると雰囲気がでてきます。

最終更新:2015年11月24日 22:16
添付ファイル