html - CSS Hover 只影响 child 而不影响 parent

标签 html css angularjs

我想更改 div悬停时的背景颜色:

<div ng-show="collectionIsFocus">
    <div ng-if="collections" ng-repeat="c in collections">
        <div class="row collection-item">
            <div class="col-8 collection-item-col">
                <p>{{c.Name}}</p>
            </div>
            <div class="col-4 collection-item-col" ng-if="c.Image">
                <img src="{{c.Image.Url}}" />
            </div>
        </div>
    </div>
</div>

我想更改 <div class="row collection-item"> 的背景颜色,但是当我将鼠标悬停在其中时。 children <div class="col-8 collection-item-col"><div class="col-4 collection-item-col" ng-if="c.Image">改变了背景颜色,但父级没有。

这是CSS:

    .collection-item {
        cursor:pointer;
        height:50px;
        max-height:50px;
        overflow:hidden;
    }

    .collection-item :hover {
        background-color: lightblue;
    }

        .collection-item img {
            max-width: 100%;
            pointer-events: none !important;
        }

        .collection-item p {
            pointer-events: none !important;
            margin: 0;
            position: absolute;
            top: 50%;
            -ms-transform: translateY(-50%);
            transform: translateY(-50%);
        }

        .collection-item .collection-item-col {
            height: 50px;
            max-height: 50px;
        }

我的头好痛,这太奇怪了。请帮忙。

最佳答案

.collection-item :hover {
    background-color: lightblue;
}

将其更改为(删除 .collection-item 和 :hover 之间的空格)

.collection-item:hover {
    background-color: lightblue;
}

关于html - CSS Hover 只影响 child 而不影响 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56036452/

相关文章:

html - 在绝对定位的叠加层上方显示固定位置元素的子元素

javascript - 灯箱上带有 slider 的图库

javascript - Angular : Push item to list doesn't update the view

javascript - 在 Web Api 中设置 cookie 后,如何在 angularjs 中读取 cookie

javascript - Angular 1.3.0 支持 JSON 响应,如何在 Angular 之前覆盖此响应或预解析响应?

html - 有没有办法在完全加载之前告诉 .ogg 视频的文件大小?

html - 透明png不在背景中显示视频

javascript - Mailto 使用 Javascript?

html - 保持 float div 彼此相邻

css - 嵌入式字体样式 - 嵌入式字体样式与 CSS 样式