如何使链接具有与父标记相同的高度和宽度,其中父标记的尺寸是可变的?
我发现了this question here,Gaurav Saxena在那里发表了一篇文章,在我为HTML5添加DOCTYPE之前,这篇文章一开始很有效。如果我这样做了,它就不再在Firefox8中工作了(不过,它仍然在Chrome中工作)。
下面是完整的例子:

<!DOCTYPE html>
<head>
<style type="text/css">
.std {width: 200px; border: solid 1px green; height: 100%}
.std a {display: inline-block; height:100%; width:100%;}
.std a:hover {background-color: yellow;}
</style>
<title></title>
</head>
<body>
<table>
  <tbody>
   <tr>
    <td class="std">
     <a href="http://www.google.com/">Cell 1<br>
     second line</a>
    </td>
   <td class="std">
    <a href="http://www.google.com/">Cell 2</a>
   </td>
   <td class="std">
    <a href="http://www.google.com/">Cell 3</a>
   </td>
   <td class="std">
    <a href="http://www.google.com/">Cell 4</a>
   </td>
  </tr>
 </tbody>
</table>
</body>

提前谢谢你的帮助!

最佳答案

$('td a').each(function(){
    $(this).css({
        'width': $(this).parent().width(),
        'height': $(this).parent().height()
    });
});

在加载文档DOM时运行。

关于css - 链接以填写父标签(td,div),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8552321/

10-10 06:53