Hover Reveal Actions
悬停显示操作
A contextual action fades into view when a row is hovered or contains focus.
Where to use it
Surface secondary controls in an item list or file manager. Put occasional row actions here and reveal them on focus within the row. Provide a visible path to the same actions on touch screens.
Practical example
In a podcast library, moving across an episode row reveals its three-dot menu at the end. A producer can open it to rename or archive that episode without leaving the list.
AI prompt
Add Hover Reveal Actions to [target]. Keep the action in the DOM and reveal it with row hover and :focus-within. Reserve space so labels do not shift and show actions on touch. Keep the content readable in reduced-motion mode and preserve keyboard navigation.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hover Reveal Actions</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.file { display: flex; gap: 7px; align-items: center; width: min(100%, 215px); padding: 10px; border: 1px solid #77639a; border-radius: 9px; background: #302446; }
.symbol { color: #ccb9ff; }
.filename { flex: 1; font-size: 13px; }
.file button { min-width: 51px; transition: opacity .18s ease; }
.file button[aria-pressed="true"] { background: #665098; }
@media (hover: hover) and (pointer: fine) {
.file:not(:hover):not(:focus-within) button[aria-pressed="false"] { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .file button { transition: none; } }
</style>
</head>
<body>
<main class="demo">
<div class="file">
<span class="symbol" aria-hidden="true">▧</span>
<span class="filename">Brand notes</span>
<button type="button" class="demo-button" aria-pressed="false">Pin</button>
</div>
</main>
<script>
const button = document.querySelector('.file button');
button.addEventListener('click', () => {
button.setAttribute('aria-pressed', String(button.getAttribute('aria-pressed') !== 'true'));
});
</script>
</body>
</html>Original example by UI Skills