使用CSS而不是jQuery切换类 [英] Toggle class with css not jquery

查看:66
本文介绍了使用CSS而不是jQuery切换类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用CSS切换类?

Is is possible to toggle a class with only css?

说我有以下内容:

<div class="parent">
   <div class="child collapsed">
        Boring Text
   </div>
</div>

是否可能,仅使用CSS ,当您单击parent时,可以将collapsed类切换为expanded,反之亦然吗?

Is is possible, just with css, that when you click on the parent, you can switch the collapsed class to expanded and vice versa?

推荐答案

是否可以仅使用CSS切换类?

Is is possible to toggle a class with only css?

否.

您可以使用伪类(例如:hover:active:checked :target ,但这与更改DOM的类属性的状态不同.

You can have state handled by using pseudo-classes such as :hover, :active, :checked, and :target but this is not the same as changing the state of class attributes the DOM.

这篇关于使用CSS而不是jQuery切换类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆