Skip to content

Instantly share code, notes, and snippets.

@henrahmagix
Created December 2, 2012 18:32
Show Gist options
  • Save henrahmagix/4190346 to your computer and use it in GitHub Desktop.
Save henrahmagix/4190346 to your computer and use it in GitHub Desktop.
Indented button with increased hit area.
.button {
background-color: #EDEDE7;
border: 1px solid #593723;
-moz-box-shadow: 0 10px 0 0 #593723, 0 10px 15px 2px rgba(0, 0, 0, 0.8);
-webkit-box-shadow: 0 10px 0 0 #593723, 0 10px 15px 2px rgba(0, 0, 0, 0.8);
box-shadow: 0 10px 0 0 #593723, 0 10px 15px 2px rgba(0, 0, 0, 0.8);
color: #593723;
display: block;
padding: 10px;
position: relative;
top: 0;
text-decoration: none;
width: 120px;
}
.button:hover, .button:focus {
-moz-box-shadow: 0 2px 0 0 #593723, 0 2px 2px 1px rgba(0, 0, 0, 0.8);
-webkit-box-shadow: 0 2px 0 0 #593723, 0 2px 2px 1px rgba(0, 0, 0, 0.8);
box-shadow: 0 2px 0 0 #593723, 0 2px 2px 1px rgba(0, 0, 0, 0.8);
top: 8px;
}
.button:active {
-moz-box-shadow: inset 0 2px 2px 1px #593723, 0 0 0 0 rgba(0, 0, 0, 0.1);
-webkit-box-shadow: inset 0 2px 2px 1px #593723, 0 0 0 0 rgba(0, 0, 0, 0.1);
box-shadow: inset 0 2px 2px 1px #593723, 0 0 0 0 rgba(0, 0, 0, 0.1);
top: 10px;
}
.not-jumpy:before {
content: '';
background-color: transparent;
display: block;
position: absolute;
bottom: 100%;
left: 0;
height: 0;
width: 100%;
}
.not-jumpy:hover:before, .not-jumpy:focus:before, .not-jumpy:active:before {
border: 1px solid transparent;
left: -1px;
}
.not-jumpy:hover:before, .not-jumpy:focus:before {
height: 8px;
}
.not-jumpy:active:before {
height: 10px;
}
.show-hit-area:before {
background-color: #000;
}
.animated {
-webkit-transition: all .1s ease;
-moz-transition: all .1s ease;
-ms-transition: all .1s ease;
-o-transition: all .1s ease;
transition: all .1s ease;
}
.animated:active {
-webkit-transition: all 0s ease;
-moz-transition: all 0s ease;
-ms-transition: all 0s ease;
-o-transition: all 0s ease;
transition: all 0s ease;
}
body {
background-color: #B9B79E;
color: #2C241D;
font-family: "PT Sans", Arial;
font-size: 12px;
font-weight: normal;
}
code {
background-color: #EDEDE7;
color: #2C241D;
padding: 0 0.5em;
}
a {
color: inherit;
text-decoration: inherit;
}
.title, .subtitle, .button {
font-family: "Arvo";
text-align: center;
}
article {
color: #EDEDE7;
margin: 2% 0;
text-align: justify;
width: 38%;
}
p {
background-color: #593723;
border: 2px solid #EDEDE7;
-moz-box-shadow: 4px 4px 4px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 4px 4px 4px 2px rgba(0, 0, 0, 0.3);
box-shadow: 4px 4px 4px 2px rgba(0, 0, 0, 0.3);
padding: 2%;
}
.left {
float: left;
margin-left: 5%;
}
.right {
float: right;
margin-right: 5%;
}
.button {
cursor: pointer;
font-size: 16px;
line-height: 16px;
margin: 0 auto 30px;
}
.side-by-side {
margin: 0 auto;
position: relative;
text-align: center;
}
.info {
color: #2C241D;
}
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
<html>
<head>
<title>Quick Jump Link</title>
<link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="button.css">
</head>
<body>
<h1 class="title">Indented Button</h1>
<h2 class="subtitle">A button using <code>:before</code> and <code>:after</code> to increase hit area, thus avoiding a jumpy effect.</h2>
<section class="clearfix">
<article class="left">
<p>Slowly move your cursor onto the button from above and notice how it jumps. This is because the button is moved using <code>top</code> when hovered on, which means the button's hit area is no longer under the cursor.</p>
<a class="button jumpy" href="#">Jumpy</a>
<a class="button animated" href="#">I'm animated!</a>
</article>
<article class="right">
<p>Do the same to this button and your cursor will hit a transparent <code>:before</code> element, which is deemed a child element of the button, thus increasing its hit area.</p>
<div class="side-by-side">
<a class="button not-jumpy" href="#">Not jumpy</a>
<a class="button not-jumpy show-hit-area" href="#">Show effect</a>
<span class="info"><strong>The <code>:before</code> element is shown in black.</strong></span>
</div>
</article>
</section>
<h2 class="subtitle">Try clicking them too!</h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment