在悬停另一个元素时更改元素样式元素、样式

2023-09-07 22:38:00 作者:懂爱旳孤独

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

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.

 
精彩推荐