You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅显示带有current-category类的categoryname类div元素?

你只需要把原来选中.categoryname:first-child的逻辑,替换为选中同时携带current-category类的.categoryname元素即可,调整后的CSS代码如下:

.categoryname{
    display:none;
}
/* 匹配同时带有categoryname和current-category两个类的元素 */
.categoryname.current-category{
    display:block;
}

这种写法不依赖元素的排列顺序,无论current-category类绑定到哪个.categoryname div上,都能正确显示对应块、隐藏其他同类别块,完全适配你提到的两种HTML结构场景。

内容的提问来源于stack exchange,提问作者Jacob Stuard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 15:09:03