admin管理员组文章数量:1405601
I have a table that contains a column with an icon. I want the icons to be hidden by default, and only appear on hover.
HTML code:
<table class="table table-hover">
<tr>
<th>From</th>
<th>To</th>
<th>Connecting Airport</th>
<th>Comment</th>
<th>Report</th>
</tr>
<tr>
<td>JFK</td>
<td>CPH</td>
<td>ARN</td>
<td>N/A</td>
<td><i class="fa fa-exclamation-triangle" title="Report outdated information" style="color:#da5450;"></i></td>
</tr>
<tr>
<td>SFO</td>
<td>EWR</td>
<td>ORD</td>
<td>N/A</td>
<td><i class="fa fa-exclamation-triangle" title="Report outdated information" style="color:#da5450;"></i></td>
</tr>
</table>
Minimal Working Example:
/
I have a table that contains a column with an icon. I want the icons to be hidden by default, and only appear on hover.
HTML code:
<table class="table table-hover">
<tr>
<th>From</th>
<th>To</th>
<th>Connecting Airport</th>
<th>Comment</th>
<th>Report</th>
</tr>
<tr>
<td>JFK</td>
<td>CPH</td>
<td>ARN</td>
<td>N/A</td>
<td><i class="fa fa-exclamation-triangle" title="Report outdated information" style="color:#da5450;"></i></td>
</tr>
<tr>
<td>SFO</td>
<td>EWR</td>
<td>ORD</td>
<td>N/A</td>
<td><i class="fa fa-exclamation-triangle" title="Report outdated information" style="color:#da5450;"></i></td>
</tr>
</table>
Minimal Working Example:
https://jsfiddle/bce9a257/1/
Share Improve this question edited May 14, 2016 at 20:53 Pevara 14.3k1 gold badge36 silver badges48 bronze badges asked May 14, 2016 at 20:30 kexxcreamkexxcream 5,9538 gold badges46 silver badges62 bronze badges1 Answer
Reset to default 7There is no need to use javascript for this. Just a few lines of css will do:
i.fa {
display: none;
}
td:hover i.fa {
display: inline-block;
}
And the updated fiddle: https://jsfiddle/bce9a257/3/
If you want the icons to show on hover of a row in stead of a cell, you could do that like this:
i.fa {
display: none;
}
tr:hover i.fa {
display: inline-block;
}
update:
Obviously you'll need to make that selector a bit more specific to only target the icons in your table. You could for example add an id to your table like flights
and change those selectors to #flights i.fa
(and #flights tr:hover i.fa
)
本文标签: javascriptShow icon only on hoverStack Overflow
版权声明:本文标题:javascript - Show icon only on hover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744271085a2598187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论