简体   繁体   English

将鼠标悬停在除第一个元素之外的所有元素上

[英]Apply hover on all elements except the first

I have various elements and when I hover them, I want all of them to have a background with the exception of the first child. 我有各种各样的元素,当我将它们悬停时,除了第一个孩子以外,我都希望它们都有背景。

Here's my CSS selector: 这是我的CSS选择器:

#OfficeUI .iconHolder img:hover:not(:first-child) { background-color: #CDE6F7; }

What's wrong with this? 这怎么了

Relevant HTML 相关HTML

        <div class="officeui-position-absolute iconHolder">
            <!-- Provides the images on the top left of the ribbon. -->
            <top-Images-Container>
                <span ng-repeat="icon in icons">
                    <img src="{{icon.Icon}}" />
                </span>
            </top-Images-Container>    
        </div>

 p:not(:first-child):hover {background-color: red;} 
 <p>first</p> <p>second</p> <p>third</p> 

You can use the nth-child selector. 您可以使用第nth-child选择器。 n+2 makes it select all but the 1st element. n+2使其选择除第一个元素以外的所有元素。

 li:nth-child(n+2):hover { color:red; } 
 <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> 

或者,您可以使用:

    #OfficeUI .iconHolder img:nth-child(n + 2):hover

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

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