Skip to content

Instantly share code, notes, and snippets.

@tleunen
Created May 15, 2013 01:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tleunen/5581124 to your computer and use it in GitHub Desktop.
Save tleunen/5581124 to your computer and use it in GitHub Desktop.
Create an expandable button in width, with 3 background image in css (left, middle and right parts). All this keeping the html very simple.
.cbtn {
position: relative;
top: 0px;
left: 9px; /* width of left part (:before) */
overflow: visible; /* this make the :before and :after in position:absolute to appear */
background: url(img/middle.png);
height: 50px;
padding: 0;
border: 0;
cursor: pointer;
}
.cbtn::-moz-focus-inner,
.cbtn:focus {
border: 0;
}
.cbtn:before,
.cbtn:after {
content: "";
background: url(img/left.png);
width: 9px;
height: 50px;
position: absolute;
left: -9px; /* Same as width */
top: 0px;
}
.cbtn:after {
background: url(img/right.png);
width: 9px;
left: auto;
right: -9px; /* Same as width */
}
.cbtn:hover,
.cbtn:hover:before,
.cbtn:hover:after {
background-position: 0 -50px;
}
.cbtn:active,
.cbtn:active:before,
.cbtn:active:after {
background-position: 0 -100px;
}
<button class="cbtn">Click me!!!</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment