当父项处于活动状态时,CSS会更改子跨度的颜色(CSS change color of child span when parent is active)

编程入门 行业动态 更新时间:2024-10-14 08:22:58
当父项处于活动状态时,CSS会更改子跨度的颜色(CSS change color of child span when parent is active)

我在Jquery mobile工作,我有一个这样的页脚:

<div data-role="footer" data-position="fixed" data-id="footer" data-tap-toggle="false"> <div class="footer" data-role="navbar"> <ul> <li> <a href="#dashboard" data-icon="dashboard" class="footer-icons" id="icon-dashboard"> <span class="navbar-text">Dashboard</span> </a> </li> <li> <a href="#notifications" data-icon="progress" id="icon-progress" class="footer-icons"> <span class="navbar-text">Voortgang</span> </a> </li> <li> <a href="#map" data-icon="security" id="icon-security" class="ui-btn-active footer-icons"> <span class="navbar-text">Plattegrond</span> </a> </li> <li> <a href="#" data-icon="security" id="icon-security" class="footer-icons"> <span class="navbar-text">Securitycheck</span> </a> </li> </ul> </div> </div>

我希望在其父级设置为活动时更改<span class="navbar-text"></span>的颜色我想到这样的事情:

.footer > .ui-btn-active > .navbar-text { color: red!important; }

但这不起作用也许有人可以帮我解决这个问题?

Iam working in Jquery mobileI have an footer like this:

<div data-role="footer" data-position="fixed" data-id="footer" data-tap-toggle="false"> <div class="footer" data-role="navbar"> <ul> <li> <a href="#dashboard" data-icon="dashboard" class="footer-icons" id="icon-dashboard"> <span class="navbar-text">Dashboard</span> </a> </li> <li> <a href="#notifications" data-icon="progress" id="icon-progress" class="footer-icons"> <span class="navbar-text">Voortgang</span> </a> </li> <li> <a href="#map" data-icon="security" id="icon-security" class="ui-btn-active footer-icons"> <span class="navbar-text">Plattegrond</span> </a> </li> <li> <a href="#" data-icon="security" id="icon-security" class="footer-icons"> <span class="navbar-text">Securitycheck</span> </a> </li> </ul> </div> </div>

I want to change the color of <span class="navbar-text"></span> when its parent is set to active I thought something like this:

.footer > .ui-btn-active > .navbar-text { color: red!important; }

But this is not working maybe someon could help me out on this?

最满意答案

问题是因为.ui-btn-active不是.footer的孩子,因为>要求 - 它是孙子。 删除该运算符:

.footer .ui-btn-active > .navbar-text { color: red !important; }

工作实例

或者,如果要使用子选择器,则需要明确设置选择器中的完整层次结构:

.footer > ul > li > .ui-btn-active > .navbar-text { color: red !important; }

另请注意,应该不惜一切代价避免使用!important 。 如果需要覆盖设置,请使选择器更具体。

The issue is because .ui-btn-active is not a child of .footer as the > requires - it's a grandchild. Remove that operator:

.footer .ui-btn-active > .navbar-text { color: red !important; }

Working example

Alternatively if you want to use the child selector, you need to explicity set the full hierarchy in the selector:

.footer > ul > li > .ui-btn-active > .navbar-text { color: red !important; }

Also note that the use of !important should be avoided at all costs. If you need to override a setting, make the selector more specific.

更多推荐

class,footer,navbar-text,<span,电脑培训,计算机培训,IT培训"/> <meta name=&

本文发布于:2023-08-01 01:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1350632.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跨度   颜色   状态   CSS   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!