[英]How do I make an entire row of a table clickable in css?
If I have the following code what would I add to make a row clickable as a link? 如果我有以下代码,我会添加什么来使一行可点击作为链接? (be gentle I am new to this) I have tried a couple of things, but I am very new to this so I am struggling to get it right:
(要温柔我是新手)我尝试了几件事,但我对此很新,所以我很难做到正确:
.hoverTable { width: 700px; border-collapse: collapse; } .hoverTable td { padding: 7px; border: #315795 1px solid; font-family: "tradegothic"; font-size: 14px; color: #315795; } /* Define the default color for all the table rows */ .hoverTable tr { background: #bec7d6; } /* Define the hover highlight color for the table row */ .hoverTable tr:hover { background-color: #315795; color: #ffffff; } /* Define the hover highlight color for the table row */ .hoverTable td:hover { background-color: #315795; color: #ffffff; }
<table class="hoverTable" style="width: 700px;"> <tbody> <tr class="clickable-row" data-href="mathdept.ucr.edu"> <td colspan="3"><strong><a>CENTER FOR MATHEMATICAL & COMPUTATIONAL MODELING IN BIOLOGY & MEDICINE<span style="float: right;">►►</span></a><br /></strong></td> </tr> <tr> <td colspan="3"><strong>OUR PEOPLE - COMMITTEES <span style="float: right;">►►</span></strong></td> </tr> <tr> <td colspan="3"><strong>SEMINARS, COLLOQUIUM, CONFERENCES & RESEARCH <span style="float: right;">►►</span></strong></td> </tr> </tbody> </table>
if I understood correctly you need to create something like in the picture that I uploade: 如果我理解正确你需要创建像我上传的图片中的东西:
In order to create that you need to put the href="information" inside of tag : 为了创建你需要把href =“信息”放在标签内:
enter code here
<tr class="clickable-row">
<td colspan="3"><strong><a href="/mathdept.ucr.edu">CENTER FOR MATHEMATICAL & COMPUTATIONAL MODELING IN BIOLOGY & MEDICINE<span style="float: right;">►►</span></a><br /></strong></td>
</tr>
HTML has two basic types of elements, inline elements and block elements. HTML有两种基本类型的元素,内联元素和块元素。 If you want to know more about it, just read here .
如果您想了解更多信息, 请阅读此处 。
Because them <a>
tag belongs to the class of the inline elements, it won't fill the whole table cell. 因为它们
<a>
标签属于内联元素的类,所以它不会填充整个表格单元格。 The trick is to convert the anker tag with the link to a block element: 诀窍是将带有链接的anker标记转换为块元素:
a {
display: block;
}
Now the anker will fill the complete cell. 现在anker将填满整个单元格。 Below you will find a code example on how this solution works.
您将在下面找到有关此解决方案如何工作的代码示例。
I have two extra advices for you as beginner: 作为初学者,我有两个额外的建议:
Use of Non-Standard Fonts 使用非标准字体
Please take care, if you are using unusual fonts like tradegothic
, which are not installed an all computers. 如果您使用的是像
tradegothic
这样没有安装所有计算机的不tradegothic
字体,请注意。 If a visitor of a website does not have this font installed on his machine, he will see your website in the default font of his web browser. 如果网站的访问者没有在他的机器上安装此字体,他将以他的网络浏览器的默认字体看到您的网站。
If you want to use a custom font, please read here . 如果您想使用自定义字体,请阅读此处 。
Do not use tables if not necessary 如果没有必要,请不要使用表格
Using a table to display a navigation or other non-table data is mostly considered as a bad style of code . 使用表来显示导航或其他非表数据通常被认为是一种糟糕的代码风格 。
Below you will find the exakt same looking navigation box without using an html table. 下面你会发现exakt相同的导航框而不使用html表。 This code could be considered to be more clean.
这段代码可以被认为更干净。
.nav { width: 700px; /* Define the width of the navigation box */ padding: 0; } .nav li { list-style-type: none; margin: -1px 0 0 0; } /* Define the style of the ankers */ .nav a, .nav a:visited { display: block; border: #315795 1px solid; padding: 7px; font-family: "tradegothic"; font-size: 14px; font-weight: bold; text-decoration: none; color: #315795; background: #bec7d6; } /* Define the hover style for the ankers */ .nav a:hover { background-color: #315795; color: #ffffff; } /* Define the Arrows */ .nav a::after { content: "►►"; float: right; }
<ul class="nav"> <li><a href="http://stackoverflow.com">CENTER FOR MATHEMATICAL & COMPUTATIONAL MODELING IN BIOLOGY & MEDICINE</a></li> <li><a href="http://stackoverflow.com">OUR PEOPLE - COMMITTEES</a></li> <li><a href="http://stackoverflow.com">SEMINARS, COLLOQUIUM, CONFERENCES & RESEARCH</a></li> </ul>
Original Solution with Table 表的原始解决方案
If you, for whatever reasons, prefer the table solution, here you will find the fixed code. 如果您出于某种原因更喜欢表格解决方案,那么您将找到固定代码。
.hoverTable { width: 700px; border-collapse: collapse; } .hoverTable td { padding: 0; border: #315795 1px solid; } /* Define the style for normal and visited links */ .hoverTable a, .hoverTable a:visited { display: block; padding: 7px; text-decoration: none; font-weight: bold; font-family: "tradegothic"; font-size: 14px; color: #315795; background: #bec7d6; } /* Define the hover style for the links */ .hoverTable a:hover { color: #ffffff; background: #315795; }
<table class="hoverTable"> <tbody> <tr class="clickable-row" data-href="mathdept.ucr.edu"> <td colspan="3"><a href="http://stackoverflow.com">CENTER FOR MATHEMATICAL & COMPUTATIONAL MODELING IN BIOLOGY & MEDICINE<span style="float: right;">►►</span></a></td> </tr> <tr> <td colspan="3"><a href="http://stackoverflow.com">OUR PEOPLE - COMMITTEES <span style="float: right;">►►</span></a></td> </tr> <tr> <td colspan="3"><a href="http://stackoverflow.com">SEMINARS, COLLOQUIUM, CONFERENCES & RESEARCH <span style="float: right;">►►</span></a></td> </tr> </tbody> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.