使用:hover修改另一个类的CSS? [英] Use :hover to modify the css of another class?
问题描述
有一种方法可以修改一个类的css,当鼠标悬停在另一个类的元素只使用css?
像:
.item:hover .wrapper {/ * some css * /}
只有'wrapper'不在'item'里面,而在其他地方。
我真的不想使用javascript对于这么简单的东西,但如果我有,我该怎么办呢?这是我的失败尝试:
document.getElementsByClassName('item')[0] .onmouseover =document.getElementsByClassName ')[0] .style.background =url('some url');;
每个类只有一个元素。不知道为什么他们没有使用ID,当他们做的模板,但这是它是如何,我不能改变它。
/ p>
这是一个菜单。每个菜单元素都有一个不同的类。当你在元素上悬停时,子菜单会弹出到右边。这就像一个叠加,当我使用检查元素工具,我可以看到整个网站的html变化时,子菜单是活动的(意味着除了子菜单)。我称之为wrapper的类具有控制子菜单背景的css。
我使用javascript结束...是的,它是现在不可能在CSS中。
我不敢相信,它会在css中占一行,几个字。但是不,我不得不制作脚本,使用jQuery和复杂的一切。
你会认为这个简单的东西将包含在当前的css。
Is there a way to modify the css for one class when hovering on an element from another class using only css ?
Something like:
.item:hover .wrapper { /*some css*/ }
Only 'wrapper' is not inside 'item', it's somewhere else.
I really don't want to use javascript for something this simple, but if I have to, how would I do it ? Here's my failed attempt:
document.getElementsByClassName('item')[0].onmouseover="document.getElementsByClassName('wrapper')[0].style.background="url('some url')";";
There's only one element of each class. Don't know why they didn't use IDs when they made the template, but that's just how it is and I can't change it.
[Edit]
It's a menu. Each menu element has a distinct class. When you hover on the element a submenu pops up to the right. It's like an overlay, when I use the 'Inspect Element' tool I can see that the whole website html changes when the submenu is active(meaning there's nothing but the submenu). The class I call 'wrapper' has the css that controls the background for the submenu. There's really no connection that I can see between the two classes.
I used javascript in the end... Yes, It's NOT possible in CSS at the moment.
I can't believe it, it would have taken 1 line in css, a few words. But no, I had to make scripts, use jQuery and complicate everything.
You'd think something this simple would be included in the current css.
这篇关于使用:hover修改另一个类的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!