Skip to content

Instantly share code, notes, and snippets.

@Abban
Last active October 14, 2016 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abban/5176186 to your computer and use it in GitHub Desktop.
Save Abban/5176186 to your computer and use it in GitHub Desktop.
CSS to add a white or black alpha hover state on any colour button. This allows a single hover state to be applied to buttons of multiple colours without having to manually set colours.
.orange{ background: #ff7a4d; }
.blue{ background: #7396ff; }
.button {
display: inline-block;
*display: inline;
color: #ffffff;
text-decoration: none;
padding: 6px 10px;
position: relative;
}
.button:hover {
color: #ffffff;
}
.button:hover:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.3);
}
.button.dark:hover:before {
background: rgba(0, 0, 0, 0.2);
}
<!-- Light hover -->
<a href="#" class="button orange">What, How, Why? Find Out &raquo;</a>
<!-- Dark hover -->
<a href="#" class="button dark blue">What, How, Why? Find Out &raquo;</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment