我有一个跨标签内的图像.但问题是图像不适合跨标签.相反,图像的一部分不在span标签之外.

我想要在点击单词span时改变图像颜色,而当我点击该图像时,它会改变文本的颜色.我猜我的代码有问题.

我该如何实现?

我的HTML:

<div class="games-platform-item pt-item">
<ul class="games-sub-menu clearfix">
<li class="tab1 current">
    <!-- <img src="../images/abc11.jpg"/ class="topimgG1" "> -->
    <input type="radio" name="imgSwap" id="rdoImg1">
    <label class="topimgG1" for="rdoImg1"></label>
    <span>编辑精选</span>
</li>
<li class="tab2">
    <div>
        <!-- <img src="../images/abc2.jpg"/ class="topimgG2" "> -->
        <input type="radio" name="imgSwap" id="rdoImg2">
        <label class="topimgG2" for="rdoImg2"></label>
        <span>老虎机</span>
    </div>
</li>
<li class="tab3">
    <!-- <img src="../images/abc3.jpg"/ class="topimgG3" "> -->
    <input type="radio" name="imgSwap" id="rdoImg3">
    <label class="topimgG3" for="rdoImg3"></label>
    <span>桌面游戏</span>
</li>
<li class="tab4">
    <!-- <img src="../images/abc4.jpg"/ class="topimgG4" "> -->
    <input type="radio" name="imgSwap" id="rdoImg4">
    <label class="topimgG4" for="rdoImg4"></label>
    <span>累计大奖</span>
</li>
<li class="tab5">
    <!-- <img src="../images/abc5.jpg"/ class="topimgG5" "> -->
    <input type="radio" name="imgSwap" id="rdoImg5">
    <label class="topimgG5" for="rdoImg5"></label>
    <span>小游戏</span>
</li>
<li class="tab6">
    <!-- <img src="../images/abc6.jpg"/ class="topimgG6" ">   -->
    <input type="radio" name="imgSwap" id="rdoImg6">
    <label class="topimgG6" for="rdoImg6"></label>
    <span>视频扑克</span>
</li>
<li class="tab7">
    <!-- <img src="../images/abc7.jpg"/ class="topimgG7" "> -->
    <input type="radio" name="imgSwap" id="rdoImg7">
    <label class="topimgG7" for="rdoImg7"></label>
    <span>所有游戏</span>
</li>

我的CSS:

/*Hide the Radio Button*/

.games-sub-menu input[type=radio] {
    display: none
}
/*Set a Box for the label,this is what is clicked on*/

.games-sub-menu label {
    display: block;
    width: 150px;
    height: 100px;
}
/*Set Images...this would work better with sprites*/

.games-sub-menu label.topimgG1 {
    background-image: url("../images/abc1.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 820px;
    top: 0px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG1 {
    background-image: url("../images/abc1_onclick.jpg");
}
.games-sub-menu label.topimgG2 {
    background-image: url("../images/abc2.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 690px;
    top: 0px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG2 {
    background-image: url("../images/abc2_onclick.jpg");
}
.games-sub-menu label.topimgG3 {
    background-image: url("../images/abc3.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 560px;
    top: 0px;
    position: absolute;
    z-index: 999;
    clear: both;
}
.games-sub-menu input[type=radio]:checked + label.topimgG3 {
    background-image: url("../images/abc3_onclick.jpg");
}
.games-sub-menu label.topimgG4 {
    background-image: url("../images/abc4.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 430px;
    top: 0px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG4 {
    background-image: url("../images/abc4_onclick.jpg");
}
.games-sub-menu label.topimgG5 {
    background-image: url("../images/abc5.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 305px;
    top: 0px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG5 {
    background-image: url("../images/abc5_onclick.jpg");
}
.games-sub-menu label.topimgG6 {
    background-image: url("../images/abc6.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 18 5px;
    top: 0px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG6 {
    background-image: url("../images/abc6_onclick.jpg");
}
.games-sub-menu label.topimgG7 {
    background-image: url("../images/abc7.jpg");
    background-repeat: no-repeat;
    width: 80px;
    height: 40px;
    right: 43px;
    top: 5px;
    position: absolute;
    z-index: 999;
}
.games-sub-menu input[type=radio]:checked + label.topimgG7 {
    background-image: url("../images/abc7_onclick.jpg");
}

解决方法

I want to have when onclick on the word span it change the image color
while when i onclick on that image it will change the color of the
text.

如果正确解释问题,可以使用< input type =“checkBox”>两个< label>元素作为相邻兄弟姐妹,两者都用于引用前面的< input type =“checkBox”>元件

input {
  display: none;
}
label {
  width: 50px;
  height: 30px;
  background: blue;
  display: block;
}
:checked + label + label {
  background: red;
  color: white;
}
:checked + label {
  background: green;
}
<input type="checkBox" id="1">
<label for="1"></label>
<label for="1">text</label>

jquery – 当onclick时如何适应跨度标签中的图像?的更多相关文章

  1. HTML5自定义视频播放器源码

    这篇文章主要介绍了HTML5自定义视频播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  2. HTML5自定义mp3播放器源码

    这篇文章主要介绍了HTML5自定义mp3播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  3. html5自定义video标签的海报与播放按钮功能

    这篇文章主要介绍了html5自定义video标签的海报与播放按钮功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  4. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. CSS中实现动画效果-附案例

    这篇文章主要介绍了 CSS中实现动画效果并附上案例代码及实现效果,就是CSS动画样式处理,动画声明需要使用@keyframes name,后面的name是人为定义的动画名称,下面我们来看看文章的具体实现内容吧,需要的小伙伴可以参考一下

  6. h5页面背景图很长要有滚动条滑动效果的实现

    这篇文章主要介绍了h5页面背景图很长要有滚动条滑动效果的实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  7. html5借用repeating-linear-gradient实现一把刻度尺(ruler)

    这篇文章主要介绍了html5借用repeating-linear-gradient实现一把刻度尺,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  8. 如何在Canvas中添加事件的方法示例

    这篇文章主要介绍了如何在Canvas中添加事件的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. HTML5自定义元素播放焦点图动画的实现

    这篇文章主要介绍了HTML5自定义元素播放焦点图动画的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  10. 有关HTML5页面在iPhoneX适配问题

    这篇文章主要介绍了有关HTML5页面在iPhoneX适配问题,需要的朋友可以参考下

随机推荐

  1. jquery-plugins – 是否可以使用猫头鹰旋转木马实现循环/无限轮播?

    我正在使用猫头鹰旋转木马,它的工作完美,除了它不支持循环/无限滚动.我没有搜索google和stackoverflow的想法,没有运气.有没有人在猫头鹰旋转木马上实现圆形/无限滚动?

  2. jQuery动态输入字段焦点

    我想使用以下jQuery向我的页面动态添加一个输入字段:在这样做之后,我希望输入字段具有闪烁的文本光标的焦点,所以我想在创建后立即输入.有人可以告诉我我该怎么办?

  3. jquery – 为什么$(window).height()这样错了?

    我试图获取当前浏览器的视口高度,使用但我得到的价值观太低了.当视口高度高达850px时,我从height()获取大约350或400像素的值.这是怎么回事?

  4. jquery – 如果在此div之外和其他draggables内部(使用无效和有效的还原选项),则可拖动恢复

    例如这样但是由于明显的原因,这不行.我可以说这个吗?

  5. 创建一个jQueryUI 1.8按钮菜单

    现在jQueryUI1.8已经出来了,我正在浏览更新,并且遇到了新的Buttonwidget,特别是SplitButtonwithadropdown的演示之一.这个演示似乎表明Buttonwidget可以在这里创建一个下拉菜单.作为讨论的问题,我想知道使用这个新的Button小部件来创建一个下拉菜单有什么方法.干杯.解决方法您必须在按钮下方列出一个列表,方式类似于此处为自动完成提供的演示:http

  6. 灰色divs使用JQuery

    我试图使用这个代码:为了淡出一大堆名为MySelectorDiv的div,唯一的是,它只会淡出第一个而不是所有的div,为什么呢?

  7. 使用jQuery动态插入到列表中

    我有两个订单列表在彼此旁边.当我从一个列表中选出一个节点时,我想按照字母顺序插入到另一个列表中.抓住的是我想要把一个元素放在另一个列表中,而不刷新整个列表.奇怪的是,当我插入到右边的列表中,它工作正常,但是当我插入到左边的列表中时,顺序永远不会出来.我也尝试将所有内容读入数组,并将其排序在一起,以防止children()方法没有按照显示顺序返回任何东西,但是我仍然得到相同的结果.这是我的jQuer

  8. 没有回应MediaWiki API使用jQuery

    我试图从维基百科获取一些内容作为JSON:但我没有回应.如果我粘贴到浏览器的地址栏,就像我得到预期的内容.怎么了?解决方法您需要通过添加&callback=?来触发具有$.getJSON()的JSONP行为?在querystring上,像这样:Youcantestithere.没有使用JSONP,你正在击中same-originpolicy,阻止XmlHttpRequest获取任何数据.

  9. jQuery Ajax请求每30秒

    我有这段代码,但是有些人在我的网站上的值可能会改变.我需要每30秒钟更新一次#financediv.这可以做吗解决方法您可以将代码放在单独的函数中,如下所示:然后每30秒建立一个定时器调用该函数:祝你好运!总结以上是DEVMAX为你收集整理的jQueryAjax请求每30秒全部内容。如果觉得DEVMAX网站内容还不错,欢迎将DEVMAX网站推荐给好友。

  10. jquery – keypress事件在IE和Chrome中不工作,但在FF工作

    任何想法为什么会这样发生?我通常认为Chrome会更加宽容代码?这是我的按键键.我错过了什么吗?右图();和leftimage();是应该工作的功能,因为我在其他地方使用这些功能谢谢您的帮助!

返回
顶部