Skip to content

Instantly share code, notes, and snippets.

@sseletskyy
Last active June 23, 2020 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sseletskyy/7e0adb247e2fae2dfe200c3dd53559c4 to your computer and use it in GitHub Desktop.
Save sseletskyy/7e0adb247e2fae2dfe200c3dd53559c4 to your computer and use it in GitHub Desktop.
Universal hover/active effect for the button
.link {
height: 36px;
line-height: 36px;
display: inline-block;
/* position: relative is required for :after to work correctly */
position: relative;
background-color: white;
color: black;
border: 1px solid gray;
}
.link.selected {
background-color: darkgray;
color: white;
}
/* hover is not added in case of touch screen devices */
/* IE does not support @media hover, so -ms-high-contrast for backward compatibility */
@media (hover: hover), (-ms-high-contrast: none) {
.link:hover::after {
content: '\A';
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.1);
position: absolute;
top: 0;
left: 0;
}
}
/* :active pseudo class should be defined after :hover */
.link:active::after {
content: '\A';
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.2);
position: absolute;
top: 0;
left: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment