简体   繁体   English

在相邻的兄弟元素悬停时显示元素

[英]Show element when an adjacent sibling element is hovered

Here is my code. 这是我的代码。

<tr id="optShow">
<td><strong>Optimized for</strong></td>
<td style="text-align:center;">500K visitors /mo</td>
<td style="text-align:center;">100K visitors /mo</td>
<td style="text-align:center;">10K visitors /mo</td>
<td style="text-align:center;">5K visitors /mo</td>
</tr>
<tr id="optHidden"> //this one is hidden with css
<td>&nbsp;</td>
<td colspan="4" style="text-align:center;">This is not a limit. This is just a way for you to decide which plan is best for you. If you know your monthly view count this makes it easy. Remember, you can always start at Small and upgrade as you grow.</td>
</tr>

My goal is that when a user hovers over the #optShow tr, the #optHidden will show, and this will happen with different trs on the page as well. 我的目标是,当用户将鼠标悬停在#optShow tr上时,将显示#optHidden,并且页面上的不同tr也会发生这种情况。

I would like to do it with CSS, but I can't figure it out. 我想用CSS来做,但是我想不通。

I can do jQuery if I have to. 如果需要,我可以使用jQuery。

Use the adjacent sibling selector: 使用相邻的兄弟选择器:

http://www.w3.org/TR/selectors/ http://www.w3.org/TR/selectors/

#optHidden {display: none}
#optShow:hover + #optHidden {display: table-row}

This selects the #optHidden element that comes directly after the hovered #optShow element. 这将选择#optHidden#optHidden元素之后的#optShow元素。

Based on JK's comment... to show any <tr> 's adjacent sibling on hover: 基于JK的注释...以显示悬停时任何 <tr>的相邻兄弟姐妹:

<tr class="row-hover"><td>Hover to show the next row</td></tr>
<tr class="row-hide"><td>I'm the next row</td></tr>

.row-hide {display:none}
.row-hover:hover + .row-hide {display: table-row}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM