将鼠标悬停在div标签中的所有元素上不起作用

时间:2018-09-27 07:56:33

标签: html css hover

下午好,

我正在努力将鼠标悬停在框上,以更改<a>标签的颜色并更改<img>标签。

但是,当我将鼠标悬停在<p>标签上时,它确实发生了变化。

我已将所有这些插入到一个父div标签下。

有没有办法使这项工作成功?

干杯, Anrich Vigus

3 个答案:

答案 0 :(得分:0)

尝试

.divClassOrId:hover{
  background-color: red;
}

答案 1 :(得分:0)

如果我不理解,则想为标签定义功能。为此,您需要从CSS执行操作。我将向您提供一个示例代码。

<html>
<head>
<style>
div:hover {
    background-color: yellow;
}
div{
    background-color: green;
    width : 500px;
    height: 500px;
}
</style>
</head>
<body>
    <div>
        <h1>Hello World</h1>
        <h2>Hello World</h2>
        <h3>Hello World</h3>

    </div>
</body>
</html>

答案 2 :(得分:0)

如果您尝试将div悬停并仅突出显示另一个:

HTML:

<div class="class">
    <div class="childClass">Test</div>
</div>

CSS:

.class:hover + .childClass {
    background-color: blue;
}

.childClass {
    background-color: red;
}

如果父母悬停,这将修改孩子

或者,您可以使用:

.class:hover ~ childClass {
    backgroud-color: blue;
}