简体   繁体   English

如何使整个表格单元格可点击但其中的文本垂直对齐-CSS

[英]How to make whole table cell clickable but vertical align text inside it - CSS

How to make whole table cell clickable but vertical align text inside it. 如何使整个表格单元格可单击,但使其中的文本垂直对齐。

Alright it is achievable by making link display:block and setting line height. 好的,可以通过显示链接:块和设置行高来实现。

But the problem is text may get 2 lines some times. 但是问题是文本有时可能会出现2行。 So this way is not solution. 因此,这种方法不是解决方案。 Are there any other solution ? 还有其他解决方案吗?

thank you. 谢谢。

You could do this by adding a class to the cell you want to click and hooking this up using jquery such as 您可以通过在要单击的单元格中添加一个类并使用jquery将其连接起来来实现此目的,例如

<td class="clickable">...</td>

your jquery... 你的jQuery ...

$('.clickable').click(function() {
   alert('Table cell has been clicked');
 });

Yes you could do that but I usually need each cell to do something different or to send a different piece of data for each cell. 是的,您可以这样做,但是我通常需要每个单元执行不同的操作或为每个单元发送不同的数据。 So I use something like this. 所以我用这样的东西。

<td onclick="update_calendar(1337317200);">19</td>

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

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