【问题标题】:DIV:hover changes attributes of another DIVDIV:hover 改变另一个 DIV 的属性
【发布时间】:2013-01-10 11:02:46
【问题描述】:

我正在尝试将一个div 的属性从另一个div 的悬停中更改。两个 div 都有自己的唯一 ID,我想知道这是否可能。

这里是 jsfiddle 链接: http://jsfiddle.net/Ngx5D/

这里是示例代码:

body {
    background-color:lightgrey;
}

#div_one, #div_two{
    background-color:darkred;
    display:block;
    width:300px;
    text-align:center;
    padding:30px;
    margin:10px;
    color:white;
    -webkit-transition: 0.3s ease;
    -moz-transition: 0.3s ease;
    -ms-transition: 0.3s ease;
    -o-transition: 0.3s ease;
    transition: 0.3s ease;  
}

#div_one:hover {
    background-color:red;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    这样写:

    #div_one:hover + #div_two{
        background-color:red;
    }
    

    查看http://jsfiddle.net/Ngx5D/1/

    【讨论】:

    • 让我将其作为非工作的 3 元素示例发送,我想通过悬停 div_one 来修改 div_three:jsfiddle.net/37KuM
    • 哦,这是我刚刚发现的一个奇怪的情况:jsfiddle.net/6THpF 我应该打开另一个线程来获得这个问题的答案吗? (div one可以修改div2,反之不行!)
    • 你永远不能违背 CSS 中的流程。没有父选择器,没有先前的兄弟选择器。为此,您必须使用 JavaScript。
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多