html - Apply a CSS style to a child span with a dynamic id on hover of a parent div with a dynamic id
问题描述
I have multiple parent divs that each contain multiple child spans. Only a select one of these spans do I want to hide upon hovering of the parent div. Currently, I am grabbing all of the parent divs like this:
div[id*=timeline_record_container]
Each of these parent divs contains the string timeline_record_container
followed by a unique and dynamic ID. Then I am doing something similar with it's children:
span[id*=timeline_record_default_icons]
Where they all have the string timeline_record_default_icons
followed by a unique/dynamic ID as well. Adding both of these selectors together and the hover event gives me something like this:
div[id*=timeline_record_container]:hover > span[id*=timeline_record_default_icons] {
display: none;
}
My thought here is on hover of timeline_record_container
divs, find the timeline_record_default_icons
one and set it to display: none
. However this isn't working, am I ordering these wrong?
Edit: I added the HTML. The highlighted span is what I want to hide inside of the top level div in the image.
解决方案
在您的屏幕截图中,span
您要隐藏的不是div[id*=timeline_record_container]
.
考虑以下代码段:
<div class="parent">
<div class="brat">
<span class="target">The target</span>
<div>
</div>
在上面的代码片段中,要访问目标,您可以编写:
.parent .target {
…
}
但不是:
.parent > .target {
…
}
您可以作为直接子级访问,因为它位于节点.brat
下方的第一个嵌套级别。.parent
.parent > .brat {
…
}
所以,回到你的例子。我认为在应该做的伎俩>
之前简单地删除符号。span
div[id*=timeline_record_container]:hover span[id*=timeline_record_default_icons] {
display: none;
}
推荐阅读
- python - 如何检查语句是否匹配(Zip 函数)
- javascript - 为什么用 puppeteer 抓取数据总是从第一页提供数据?
- awk - 如何使用 awk 过滤换行符作为记录分隔符和字段分隔符
- google-app-engine - 将路由设置为 dispatch.yaml 的锄头
- java - 编辑 HideBottomViewOnScrollBehavior 类 android
- ggplot2 - 如何移动图表的开头,使其以 0 以外的数字开头
- php - 如何更改其他 php.ini 文件的路径
- ios - 快速观察或跟踪每个功能的进度条
- c++ - std::array 的长度是否有大小限制?
- azure - 为 Azure 应用注册生成证书