Fill <td> with <a> link using ::after pseudoelement

This commit is contained in:
cryptogopher 2023-12-05 23:36:56 +01:00
parent 16c24f65ca
commit 588bc01911
4 changed files with 12 additions and 18 deletions

View File

@ -312,26 +312,25 @@ table.items td {
border-top: solid 1px #dddddd;
padding-block: 0.1em;
}
/* NOTE: for <a> to fill <td> completely, we use 2 copies of same <a>. 1st is
* left transparent in <td> to resize <td> to link length. 2nd is positioned
* absolutely over whole <td> cell. */
/* For <a> to fill <td> completely, we use an ::after pseudoelement. */
/* TODO: change selector from td.link to td:has(a) once :has() is available on
* FF */
table.items td.link {
padding: 0;
position: relative;
}
table.items td.link a {
color: transparent;
font: inherit;
padding-inline-start: 1em;
text-align: left;
}
table.items td.link a:last-child {
table.items td.link a {
color: inherit;
display: flex;
font: inherit;
padding-inline-start: 1em;
}
table.items td.link a::after {
content: '';
inset: 0;
position: absolute;
}
table.items td.link a.subunit {
table.items td.link .subunit {
padding-inline-start: 1.6em;
}
table.items td.actions {

View File

@ -88,11 +88,6 @@ module ApplicationHelper
image_element_to(:link, name, image, options, html_options)
end
# Workaround to fill <td> with link completely, see CSS for details.
def table_link_to(...)
link_to(...) * 2
end
private

View File

@ -21,7 +21,7 @@
<% Unit.each_with_level(@units) do |unit, level| %>
<tr>
<td class="link">
<%= table_link_to unit.symbol, edit_unit_path(unit), class: level > 0 ? 'subunit' : '' %>
<%= link_to unit.symbol, edit_unit_path(unit), class: level > 0 ? 'subunit' : '' %>
</td>
<td><%= unit.name %></td>
<td class="number"><%= scientifize(unit.multiplier) unless unit.multiplier == 1 %></td>

View File

@ -11,7 +11,7 @@
<tbody>
<% @users.each do |user| %>
<tr>
<td class="link"><%= table_link_to user.email, user_path(user) %></td>
<td class="link"><%= link_to user.email, user_path(user) %></td>
<td>
<% if user == current_user %>
<%= user.status %>