简体   繁体   English

CSS可见性:隐藏被延迟

[英]CSS visibility: hidden is delayed

I have a table with data and buttons on the right.我有一个表格,右侧有数据和按钮。 I only want the buttons to show up, when i hover over the row.当我将鼠标悬停在该行上时,我只想显示按钮。 I'm trying to implement it only with CSS and it already kinda works, but when the cursor leaves the row of the table, the button still stays for a few seconds.我试图只用 CSS 来实现它,它已经有点工作了,但是当光标离开表格的行时,按钮仍然停留几秒钟。 I found the solution to use transition: ease-in-out 2s linear;我找到了使用transition: ease-in-out 2s linear; but then my buttons background transition on hover doesn't work anymore.但随后我的悬停按钮背景过渡不再起作用。

CSS CSS

.button {
    display: inline-block;
    border-radius: 3px;
    padding: 10px;
    margin-bottom: 5px;
    text-align: center;
    transition: 0.3s;
}

.button:hover {
    text-decoration: none;
}

.button-secondary {
    color: #999;
    background-color: #00000000;
    border: 1px solid #999;
}

.button-secondary:hover {
    color: #000;
    background-color: #0053ff16;
    border-color: #000;
}

.button-danger {
    color: #fff;
    background-color: #e01e37;
    border: 1px solid #c71f37;
}

.button-danger:hover {
    color: #fff;
    background-color: #c71f37;
}

.invisiblebutton-container .button {
    visibility: hidden;
}

.invisiblebutton-container:hover {
    background-color: #f3f3f3;
}

.invisiblebutton-container:hover .button {
    visibility: visible;
}

CSHTML CSHTML

@foreach (var item in Model) {
        <tr class="invisiblebutton-container">
            <td class="col-sm-5">
                @Html.DisplayFor(modelItem => item.Username)
            </td>
            <td class="col-sm-5">
                @Html.DisplayFor(modelItem => item.Email)
            </td>
            <td class="col-sm-2">
                <a asp-action="Details" asp-route-id="@item.Id" class="button button-secondary">Details</a>
                <a asp-action="Delete" asp-route-id="@item.Id" class="button button-danger">Delete</a>
            </td>
        </tr>
}

You can try to set transition to 0.05s,so that buttons background transition on hover will still work,and when the cursor leaves the row of the table, the button will only stay 0.05s:您可以尝试将transition设置为0.05s,这样按钮在悬停时的背景过渡仍然有效,并且当光标离开表格的行时,按钮只会停留0.05s:

.button {
    display: inline-block;
    border-radius: 3px;
    padding: 10px;
    margin-bottom: 5px;
    text-align: center;
    transition: 0.05s;
}

.button:hover {
    text-decoration: none;
}

.button-secondary {
    color: #999;
    background-color: #00000000;
    border: 1px solid #999;
}

.button-secondary:hover {
    color: #000;
    background-color: #0053ff16;
    border-color: #000;
}

.button-danger {
    color: #fff;
    background-color: #e01e37;
    border: 1px solid #c71f37;
}

.button-danger:hover {
    color: #fff;
    background-color: #c71f37;
}

.invisiblebutton-container .button {
    visibility: hidden;
}

.invisiblebutton-container:hover {
    background-color: #f3f3f3;
}

.invisiblebutton-container:hover .button {
    visibility: visible;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM