Click Entire Row (preserving middle click and ctrl+click)

后端 未结 10 1162
独厮守ぢ
独厮守ぢ 2020-12-07 20:49

I have an HTML table with a link in the first column. I want to allow the user to click anywhere in the row to activate that link. At the same time, I would like to preser

10条回答
  •  醉梦人生
    2020-12-07 21:12

    I would attack this from the HTML/css side. This used to be a common problem when most sites did all layout in tables.

    First make the contents of all table cells into links. If you don't want them to look like links you can use CSS to remove the underline from the 'non link' cells. But they will be links, which is semantically what you want anyway.

    Next you want to make the link expand to fill the entire cell. StackOverflow already knows the answer to this:

    td a { display: block; width: 100%; height: 100%; line-height: 100%; }

    With a typical table with no spaces between the cells the entire row will be clickable. And since this relies on no tricks or browser specific hacks it should work everywhere.

提交回复
热议问题