トップページ > コンテンツ > コンピュータ関連その他 > CSS編 > CSSだけで動きをつける > チェックボックスボタンでスタイル変更

input[type="checkbox"]:checked ~ #ID名 {}と書くと、左の要素がチェックされた時に<input>より下に書いた弟要素の#ID名のスタイルが変更される。
chekedの代わりにhoverにして連携させる等応用技が多いので大いに活用すべし。

<!DOCTYPE html>
<html>
<head>
<style>
input[type="checkbox"] {
	display: none;
}

input[type="checkbox"]:checked ~ #test {
	text-shadow:1px 1px 3px #000;
}
</style>
</head>
<body>
<input type="checkbox" id="sample">
<div id="test">testです。</div><br><br>

<label for="sample"><strong>ここ</strong></label>を押してみて。
</body>
</html>
最終更新:2013年08月17日 11:36