Change element style on hover another element(在悬停另一个元素时更改元素样式)
问题描述
我有三个元素,我需要通过将鼠标悬停在其他两个元素上来更改一个元素的样式.
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.
这篇关于在悬停另一个元素时更改元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在悬停另一个元素时更改元素样式


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01