首頁  >  文章  >  web前端  >  如何使用css選擇器來實現導覽列背景圖的切換?

如何使用css選擇器來實現導覽列背景圖的切換?

黄舟
黄舟原創
2017-07-19 15:20:062727瀏覽

效果如圖:

html 程式碼:

<p class="banner_area">
<p class="item">
<span class="ck_item one" itemType=&#39;jjjz&#39;></span>
</p>
<p class="item">
<span class="ck_item two" itemType=&#39;jdbg&#39;></span>
</p>
<p class="item">
<span class="ck_item three" itemType=&#39;spbj&#39;></span>
</p>
<p class="item  cur_item">
<span class="ck_item four" itemType=&#39;ssnz&#39;></span>
</p>
<p class="item ">
<span class="ck_item fiv" itemType=&#39;jpnz&#39;></span>
</p>
<p class="item six">
<span class="ck_item six" itemType=&#39;hfcz&#39;></span>
</p>
<p class="item" style="margin-right: 0px;">
<span class="ck_item seven" itemType=&#39;xbsp&#39;></span>
</p>
</p>

css:

.one{background: url(http://img.jiangcdn.com/home/insider/jujz_one.jpg) no-repeat;}
.two{background: url(http://img.jiangcdn.com/home/insider/jdbg_one.jpg) no-repeat;}
.three{background: url(http://img.jiangcdn.com/home/insider/spbj_one.jpg) no-repeat;}
.four{background: url(http://img.jiangcdn.com/home/insider/ssnz_one.jpg) no-repeat;}
.fiv{background: url(http://img.jiangcdn.com/home/insider/jpnz_one.jpg) no-repeat;}
.six{background: url(http://img.jiangcdn.com/home/insider/hfqz_one.jpg) no-repeat;}
.seven{background: url(http://img.jiangcdn.com/home/insider/xbsp_one.jpg) no-repeat;}
.cur_item{width: 218px;height: 53px;}
.cur_item span.one{background: url(http://img.jiangcdn.com/home/insider/jjjz_two.jpg) no-repeat;}
.cur_item span.two{background: url(http://img.jiangcdn.com/home/insider/jdbg_two.png) no-repeat;}
.cur_item span.three{background: url(http://img.jiangcdn.com/home/insider/spbj_two.jpg) no-repeat;}
.cur_item span.four{background: url(http://img.jiangcdn.com/home/insider/ssnz_two.jpg) no-repeat;}
.cur_item span.fiv{background: url(http://img.jiangcdn.com/home/insider/jpnz_two.jpg) no-repeat;}
.cur_item span.six{background: url(http://img.jiangcdn.com/home/insider/hfqz_two.jpg) no-repeat;}
.cur_item span.seven{background: url(http://img.jiangcdn.com/home/insider/xbsp_two.jpg) no-repeat;}

我們點擊span(class='ck_item')是透過對其父元素p(class="item ") 動態新增和刪除類別cur_item就可以實現上圖效果。

以上是如何使用css選擇器來實現導覽列背景圖的切換?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn