如何使用css选择器来实现导航栏背景图的切换?

黄舟
Lepaskan: 2017-07-19 15:20:06
asal
2715 orang telah melayarinya

效果如图:

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>
Salin selepas log masuk

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;}
Salin selepas log masuk

我们点击span(class='ck_item')是通过对其父元素p(class="item ") 动态添加和删除类cur_item就可以实现上图效果。

Atas ialah kandungan terperinci 如何使用css选择器来实现导航栏背景图的切换?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!