简体   繁体   English

悬停元素,显示父元素兄弟姐妹的悬停效果

[英]Hover element, show hover effect on parent elements siblings child

Let's see now, not sure if I have the logic down 100%. 现在让我们看看,不确定我是否有100%的逻辑。

This is what I'm working with (bootply demo here ) 这就是我正在使用的( 这里的 bootply演示)

<ul>
    <li class="row">
        <span class="category col-sm-2 highlight">Architecture</span> 
        <span class="title col-sm-4"><a href="#">Hello world!</a></span>
        <span class="publication col-sm-2 hidden-xs">Magazine</span>
        <span class="year col-sm-2 hidden-xs">2007</span>  
    </li>
    <li class="row">
        <span class="category col-sm-2 invisible">Architecture</span> 
        <span class="title col-sm-4"><a href="#">Keep them coming</a></span>
        <span class="publication col-sm-2 hidden-xs">Magazine</span>
        <span class="year col-sm-2 hidden-xs">2007</span>  
    </li>
    <li class="row">
        <span class="category col-sm-2 invisible">Architecture</span> 
        <span class="title col-sm-4"><a href="#">The other posts</a></span>
        <span class="publication col-sm-2 hidden-xs">Magazine</span>
        <span class="year col-sm-2 hidden-xs">2007</span>  
    </li>
    <li class="row">
        <span class="category col-sm-2">Cities</span> 
        <span class="title col-sm-4"><a href="#">Tezt</a></span>
        <span class="publication col-sm-2 hidden-xs">Magazine</span>
        <span class="year col-sm-2 hidden-xs">2007</span>  
    </li>
</ul>

The idea is that, when hovering the a element in span.title , the color of the text in publication and year is changed. 这个想法是,当将一个元素悬停在span.title ,发布和年份中文本的颜色会发生变化。 I'm also looking for a way to change the color of the first span.category of the same kind (ie hovering "The other post" should change the color of span.category in the first .row ). 我也在寻找一种方法来改变同类的第一个span.category的颜色(即悬停“另一个帖子”应该改变第一个.rowspan.category的颜色)。 Is this achievable with pure CSS? 这是用纯CSS实现的吗?

I got your point what you are trying to do here, in this case, you can use the selector below.. so that when the li is hovered, it will also apply the color to the first span 我明白你在这里要做的是什么,在这种情况下,你可以使用下面的选择器..这样当li悬停时,它也会将颜色应用到第一个span

.row:hover span:nth-of-type(1) {
   color: red;
}

I just inspected the DOM in your fiddle and I would like to alter some things in that.. 我只是在你的小提琴中检查了DOM,我想改变一些东西。

Demo ( hover an of the hello and see the very first span color will be changed) 演示hover一个你好,并看到第一个span颜色将被更改)

Demo 2 (DOM Altered) - This is just a general idea, I've provided you the selector but this will need the DOM alteration anyways.. 演示2 (DOM改变) - 这只是一个大概的想法,我已经为你提供了选择器,但无论如何这将需要DOM改变..


Altered Demo in your Code 在您的代码中更改演示


Again as per your comment, now you can highlight all span along with their titles 再次根据您的评论,现在您可以突出显示所有span及其标题

ul li div.row:hover > span {
   color: red;
}

Final Demo 最终演示

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

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