【问题标题】:CSS Hover Affect Children Only Not The ParentCSS Hover 只影响孩子而不影响父母
【发布时间】:2019-09-25 22:25:13
【问题描述】:

我想在悬停时更改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>

我想更改&lt;div class="row collection-item"&gt; 的背景颜色,但是当我将鼠标悬停在其中时。孩子&lt;div class="col-8 collection-item-col"&gt;&lt;div class="col-4 collection-item-col" ng-if="c.Image"&gt; 改变了背景颜色,而父母没有。

这是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 之间的空格。您现在所拥有的意思是“.collection-item 中的所有悬停元素”而不是“悬停时的 .collection-item”。

标签: html css angularjs


【解决方案1】:

也许,您应该从以下位置添加更改代码:

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

.collectionIsFocus .row :hover {
    background-color: lightblue !important;
}

【讨论】:

  • 但是,我已经将此代码写入了一个简单的引导页面(没有 angularjs)。成功了
【解决方案2】:
.collection-item :hover {
    background-color: lightblue;
}

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

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

【讨论】:

    猜你喜欢
    • 2022-10-02
    • 2012-09-21
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2019-08-12
    • 2011-10-11
    相关资源
    最近更新 更多