在悬停另一个元素时更改元素样式 [英] Change element style on hover another element

查看:23
本文介绍了在悬停另一个元素时更改元素样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个元素,我需要通过将鼠标悬停在其他两个元素上来更改一个元素的样式.

I have a three elements and I need to change style of one element by hover on other two.

html

<div class="pagination">
        <span class="step-links">
            {% if page_obj.has_previous %}
                 <div class='not-current'><a href="?page={{ page_obj.previous_page_number }}">{{ page_obj.previous_page_number }}</a></div>
            {% endif %}

            <div id='current'>                
                {{ page_obj.number }}
            </div>


            {% if page_obj.has_next %}
                <div class='not-current' ><a href="?page={{ page_obj.next_page_number }}">{{ page_obj.next_page_number }}</a></div>
            {% endif %}              
        </span>
    </div>

css

#current, .not-current:hover {
    width: 30px;
    height: 30px;
    line-height: 30px;
    font-size: 20px;
    font-weight: bold;
    border: orange outset 3px;
    background-color: orange;
    margin: 0 auto 10px auto;
    box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, .5);
}

.not-current {
    width: 15px;
    height: 15px;
    line-height: 15px;
    background-color: #A29F9F;
    border: #A29F9F outset 2px;
    box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, .5);
}

.not-current:hover #current {
    display: none;
}

悬停元素 (.not-current) 的样式已更改,但 #current 元素的样式未更改.我哪里错了?(仅在 Chromium 12.0 中测试).

Styles of hovered element (.not-current) are changed but styles of #current element aren't changed. Where am I wrong in there? (Tested only in Chromium 12.0).

推荐答案

那是因为#current不在.not-current下.这种行为最好使用 JavaScript 实现.

That's because #current is not under .not-current. This behaviour is better implemented using JavaScript.

这篇关于在悬停另一个元素时更改元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆