Make link in table cell fill the entire row height

后端 未结 10 1018
清酒与你
清酒与你 2020-11-27 03:54

I have a table of data and each cell is a link. I want to allow the user to click anywhere in the table cell and have them follow the link. Sometimes the table cells are m

10条回答
  •  無奈伤痛
    2020-11-27 04:51

    You need a small change in your CSS. Making td height:100%; works for IE 8 and FF 3.6, but it doesn't work for Chrome.

    td {
      width: 200px;
      border: solid 1px green;
      height: 100%
    }
    td a {
      display: block;
      height:100%;
      width:100%;
    }
    

    But making height to 50px works for Chrome in addition to IE and FF

    td {
      width: 200px;
      border: solid 1px green;
      height: 50px
    }
    td a {
      display: block;
      height:100%;
      width:100%;
    }
    

    Edit:

    You have given the solution yourself in another post here; which is to use display: inline-block;. This works when combined with my solution for Chrome, FF3.6, IE8

    td {
      width: 200px;
      border: solid 1px green;
      height: 100%}
    td a {
      display: inline-block;
      height:100%;
      width:100%;
    }
    

    Update

    The following code is working for me in IE8, FF3.6 and chrome.

    CSS

    td {
      width: 200px;
      border: solid 1px green;
      height: 100%;
    }
    td a {
      display: inline-block;
      height:100%;
      width:100%;
    }
    td a:hover {
      background-color: yellow;
    }
    

    HTML

    Cell 1
    second line
    Cell 2 Cell 3 Cell 4

    The example lays here

提交回复
热议问题