P粉2521165872023-08-14 11:48:16
As mentioned in the comments, there are some reasons why you might not want to show child elements on mouseover: it relies on the user using the mouse. Alternatively, the entire row can be made clickable, which may provide a better user experience.
Though for the sake of completeness, here is how to solve the problem I asked:
In the Razor page, add CSS Id selectors for the row (parent) and button (child) HTML tags:
@foreach (var item in Items) { <tbody> <tr id="FileTableRow"> <th>@item.Name</th> <th>@item.Description</th> <th>@item.UserName</th> <th>@item.UploadDate.ToString("dd-MM-yyyy")</th> <th><button id="FileTableRowButton" type="button" class="btn btn-primary" @onclick="() => DoSomething()">Do Work</button></th> </tr> </tbody> }
We can then use CSS to apply styles to the button (child) on hover over the row (parent):
#FileTableRowButton { visibility: hidden; } #FileTableRow { &:hover { #FileTableRowButton { visibility: visible; } } }
Depending on your use case, you may want to apply different styles. For example, use display: none; instead of visibility: hidden;