javascript - Show icon only on hover - Stack Overflow

I have a table that contains a column with an icon. I want the icons to be hidden by default, and only

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7

There 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744271085a4566105.html

相关推荐

  • javascript - Show icon only on hover - Stack Overflow

    I have a table that contains a column with an icon. I want the icons to be hidden by default, and only

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信