2015-07-12 66 views
0

我有表,如下图所示:更改悬停时的表格内容?

<table border="1px" width= "900px" ; height="100px"> 
       <tr> 
        <td width="200px" height="100px" align="center" > 
        <p><img src="images/home.png"/></p> 
        <p>Room<p></td> 
       </tr> 
</table> 

它看起来像:

http://imgur.com/0NmtzWM

我想要做的是,当鼠标悬停在“TD”的内容,以下发生变化。

  1. 内容从“房间”更改为3个重定向到不同页面的不同链接。

  2. 图像保持中间不透明度较高。

,如:

http://imgur.com/tRke0up

+0

我注意到你有没有''表? – user4419336

回答

2

如果你想改变的元素上悬停的内容,你需要使用JavaScript来做到这一点。但是,如果您希望显示其他内容(如我在图片上看到的内容),则可以隐藏3 links并在悬停时显示它们。例如:

table { 
 
    width: 200px; 
 
    height: 200px; 
 
    border: 1px solid #ddd; 
 
    text-align: center; 
 
} 
 

 
td { 
 
    position: relative; 
 
    vertical-align: middle; 
 
} 
 

 
.default { 
 
    position: relative; 
 
    z-index: 0; 
 
} 
 

 
.show-hover { 
 
    background: rgba(255,255,255, 0.8); 
 
    width: 100%; 
 
    height: 100%; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    visibility: hidden; 
 
    opacity: 0; 
 
    transition: all .3s ease-in-out; 
 
} 
 

 
.wrap { 
 
    position: absolute; 
 
    top: 50%; 
 
    left: 50%; 
 
    transform: translate(-50%,-50%); 
 
} 
 

 
a { 
 
    display: block; 
 
} 
 

 
td:hover .show-hover { 
 
    visibility: visible; 
 
    opacity: 1; 
 
}
<table> 
 
    <tr> 
 
    <td> 
 
     <div class="default"> 
 
     <img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTUDQgbT9PFaERFaLbqP8sFsyq2r3sSYu6BtCj63z90tLEpALgo" /> 
 
     <p>Rooms</p> 
 
     </div> 
 
     <div class="show-hover"> 
 
     <div class="wrap"> 
 
      <a href="">Lorem</a> 
 
      <a href="">Ipsum</a> 
 
      <a href="">Dolor</a> 
 
     </div> 
 
     </div> 
 
    </td> 
 
    </tr> 
 
</table>