Whisper | Webの忘備録 > CSS > ロールオーバーで変化をするボタンを作る
#nav li {
list-style-type: none;
}
#nav li a {
display: block;
height: 19px;
width: 125px;
text-decoration: none;
font-size: 12px;
color: #333;
font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif;
text-align: center;
padding-top: 8px;
background-image: url(img/button01.jpg); ←画像1枚目
background-repeat: no-repeat;
background-position: left top;
}
#nav li a:hover {
background-image: url(img/button02.jpg); ←画像2枚目
background-repeat: no-repeat;
background-position: left top;
}
<ul id="nav">
<li><a href="#">テキスト</a></li>
</ul>
#nav li {
list-style-type: none;
}
#nav li a {
display: block;
height: 19px;
width: 125px;
text-decoration: none;
font-size: 12px;
color: #333;
font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif;
text-align: center;
padding-top: 8px;
background-image: url(img/button03.jpg);
background-repeat: no-repeat;
background-position: left top; ←画像の配置を左上
}
#nav li a:hover {
background-image: url(img/button03.jpg);
background-repeat: no-repeat;
background-position: left bottom; ←画像の配置を左下
}
<ul id="nav">
<li><a href="#">テキスト</a></li>
</ul>
#nav li {
list-style-type: none;
}
#nav li a {
display: block;
height: 19px;
width: 125px;
text-decoration: none;
font-size: 12px;
color: #333;
font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif;
text-align: center;
padding-top: 8px;
background-image: url(img/button04.jpg); ←画像一枚目
background-repeat: no-repeat;
background-position: left top;
text-indent: -9999px; ←テキストをー9999とし、枠外に隠す
}
#nav li a:hover {
background-image: url(img/button05.jpg); ←画像二枚目
background-repeat: no-repeat;
background-position: left top;
}
<ul id="nav">
<li><a href="#">テキスト</a></li>
</ul>
#nav li {
list-style-type: none;
background-image: url(img/button02.jpg); ←li要素にマウスオーバー時の画像を指定
background-repeat: no-repeat;
background-position: left top;
}
#nav li a {
display: block;
height: 19px;
width: 125px;
text-decoration: none;
font-size: 12px;
color: #333;
font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif;
text-align: center;
padding-top: 8px;
background-image: url(img/button01.jpg); ←一枚目の画像
}
#nav li a:hover {
background-image: none; ←一枚目の画像を非表示
}
<ul id="nav">
<li><a href="#">テキスト</a></li>
</ul>
#nav li {
list-style-type: none;
}
<script src="js/rollover.js" type="text/javascript"></script> ←image rollover codeのJavaScriptを設置
-HTML-<ul id="nav">
<li><a href="#"><img src="img/button06.jpg" alt="ボタン" border="0" class="imgover" /></a></li> ←image rollover code専用のクラスを指定
</ul>