Permutation Icône & Texte
L’icône et le mot échangent instantanément leur place avec glissement croisé.
Démo en direct
Survolez les boutons pour voir l'effet.
Comment utiliser cet effet
Collez le HTML dans votre page et le CSS dans votre feuille de style. Modifiez --btn-color, --btn-bg et --anim-speed selon votre design.
<button class="hover-btn btn-size-md btn-hover-icon-swap-morph swap-from-right">
<span class="btn-content-wrap">HoverLab</span>
<svg class="btn-icon btn-icon-swap-right" width="18" height="18" viewBox="0 0 256 256" fill="currentColor"><path d="M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z"></path></svg>
</button>
/* ==========================================
HoverLab Effect #19: 19. Permutation Icône & Texte
Self-Contained & Plug-and-Play CSS
========================================== */
:root {
--btn-color: #e6332a;
--btn-bg: #eeeeee;
--anim-speed: 0.35s;
}
/* Base Button Styles */
.hover-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 10px;
padding: 12px 28px;
font-family: inherit;
font-size: 15px;
font-weight: 500;
letter-spacing: -0.01em;
white-space: nowrap;
cursor: pointer;
background-color: transparent;
color: var(--btn-color, #e6332a);
border: 1.5px solid var(--btn-color, #e6332a);
border-radius: 9999px;
text-decoration: none;
user-select: none;
transition: all var(--anim-speed, 0.35s) cubic-bezier(0.16, 1, 0.3, 1);
box-sizing: border-box;
}
.hover-btn.btn-icon-only {
padding: 0 !important;
aspect-ratio: 1 / 1;
width: 44px;
height: 44px;
}
.hover-btn .btn-icon {
display: block;
flex-shrink: 0;
transition: transform var(--anim-speed, 0.35s) cubic-bezier(0.16, 1, 0.3, 1);
}
/* Effect Styles */
.btn-hover-icon-swap-morph {
position: relative;
overflow: hidden;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
z-index: 1;
--swap-text-x: -26px;
--swap-icon-x: 76px;
--swap-text-right-x: 26px;
--swap-icon-right-x: -76px;
transition: transform var(--anim-speed, 0.3s) cubic-bezier(0.16, 1, 0.3, 1),
background-color var(--anim-speed, 0.3s) ease,
border-color var(--anim-speed, 0.3s) ease,
color var(--anim-speed, 0.3s) ease,
box-shadow var(--anim-speed, 0.3s) ease;
}
.btn-size-sm.btn-hover-icon-swap-morph {
--swap-text-x: -22px;
--swap-icon-x: 66px;
--swap-text-right-x: 22px;
--swap-icon-right-x: -66px;
}
.btn-size-lg.btn-hover-icon-swap-morph {
--swap-text-x: -29px;
--swap-icon-x: 87px;
--swap-text-right-x: 29px;
--swap-icon-right-x: -87px;
}
.btn-hover-icon-swap-morph::before {
content: '';
position: absolute;
inset: -1px;
background-color: var(--btn-color, #18181b);
transform: scale(0);
border-radius: inherit;
transition: transform var(--anim-speed, 0.4s) cubic-bezier(0.16, 1, 0.3, 1);
z-index: -1;
}
.btn-hover-icon-swap-morph:hover::before {
transform: scale(1);
}
.btn-hover-icon-swap-morph .btn-content-wrap,
.btn-hover-icon-swap-morph .btn-icon-swap-left,
.btn-hover-icon-swap-morph .btn-icon-swap-right {
position: relative;
z-index: 1;
transition: transform var(--anim-speed, 0.45s) cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-hover-icon-swap-morph:hover .btn-icon-swap-left ~ .btn-content-wrap {
transform: translateX(var(--swap-text-x));
}
.btn-hover-icon-swap-morph:hover .btn-icon-swap-left {
transform: translateX(var(--swap-icon-x));
}
.btn-hover-icon-swap-morph.swap-from-right:hover .btn-content-wrap {
transform: translateX(var(--swap-text-right-x));
}
.btn-hover-icon-swap-morph.swap-from-right:hover .btn-icon-swap-right {
transform: translateX(var(--swap-icon-right-x));
}
.btn-hover-icon-swap-morph:hover {
color: var(--btn-bg, #ffffff) !important;
border-color: var(--btn-color, #18181b) !important;
transform: translateY(-2px);
box-shadow: 0 8px 24px -4px #00000029;
}
.btn-hover-icon-swap-morph:active {
transform: translateY(0) scale(0.98);
}
Quand l'utiliser
Les effets de mouvement déplacent le bouton ou son contenu. Un léger déplacement rend la cible plus physique et plus cliquable. Utilisez-les sur des interfaces ludiques, des landing pages et des boutons icônes, avec une course courte.
Accessibilité
Utilisez un vrai élément <button> ou <a> pour que l'effet marche aussi au clavier : dupliquez les sélecteurs :hover avec :focus-visible. Pour les visiteurs qui préfèrent moins d'animations, placez transitions et animations dans @media (prefers-reduced-motion: no-preference).
Compatibilité navigateurs
L'effet repose sur du CSS standard (transitions, transformations, pseudo-éléments et variables CSS). Il fonctionne sur les versions actuelles de Chrome, Edge, Firefox et Safari, sans JavaScript ni dépendance.