Link entire table row?

后端 未结 8 1226
后悔当初
后悔当初 2020-12-01 03:43

I know it is possible to link an entire table cell with CSS.

.tableClass td a{
   display: block;
}

Is there a way to apply a link to an en

8条回答
  •  有刺的猬
    2020-12-01 04:17

    Unfortunately, no. Not with HTML and CSS. You need an a element to make a link, and you can't wrap an entire table row in one.

    The closest you can get is linking every table cell. Personally I'd just link one cell and use JavaScript to make the rest clickable. It's good to have at least one cell that really looks like a link, underlined and all, for clarity anyways.

    Here's a simple jQuery snippet to make all table rows with links clickable (it looks for the first link and "clicks" it)

    $("table").on("click", "tr", function(e) {
        if ($(e.target).is("a,input")) // anything else you don't want to trigger the click
            return;
    
        location.href = $(this).find("a").attr("href");
    });
    

提交回复
热议问题