简体   繁体   English

悬停时的常规同级选择器

[英]General sibling selectors on hover

I am using General sibling selectors to show a hidden div when i hover on another div the hover works fine when i tested it to change font color, but after i added the "~ .cat3" to modify the class ".cat3" styles it doesn't work, i also tried using Adjacent sibling selectors as shown in this question but it is also not working. 当我将鼠标悬停在另一个div上时,我正在使用“通用同级”选择器显示隐藏的div,当我测试它以更改字体颜色时,该悬停效果很好,但是在我添加“〜.cat3”以修改类“ .cat3”样式后,不起作用,我也尝试过使用Adjacent兄弟姐妹选择器,如该问题所示,但它也不起作用。 Here is the code: 这是代码:

HTML: HTML:

<div class="row subcat" > 
    <div class="col-md-6 subcatitem">
        <a href="link.html">category name</a>
    </div>
    <div class="col-md-6 cat3">
    Category Items
    </div>

The CSS: CSS:

.cat3{
display: none;
}

.subcatitem a:hover ~ .cat3{    
display: block;
}

Thank You 谢谢

This 这个

.subcatitem a:hover ~ .cat3{    
display: block;
}

won't work because the link is not a sibling of the next div 无效,因为该链接不是下一个div的兄弟

You could try this though 你可以尝试一下

 .cat3 { display: none; } /* doesn't work .subcatitem a:hover ~ .cat3{ display: block; } */ .subcatitem:hover ~ .cat3 { display: block; } 
 <div class="row subcat"> <div class="col-md-6 subcatitem"> <a href="link.html">category name</a> </div> <div class="col-md-6 cat3"> Category Items </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM