Skip to content

Instantly share code, notes, and snippets.

@solidgoldpig
Created June 26, 2015 15:33
Show Gist options
  • Save solidgoldpig/9f69a5df5da274b4d28a to your computer and use it in GitHub Desktop.
Save solidgoldpig/9f69a5df5da274b4d28a to your computer and use it in GitHub Desktop.
Image slider with pure CSS
/**
* Image slider with pure CSS
* Original version in http://demosthenes.info/blog/css
*/
.image-slider {
position:relative;
display: inline-block;
line-height: 0;
}
/* Could use a pseudo-element, but they’re currently
super buggy. See: http://dabblet.com/gist/ab432c3f6a8f672cd077 */
.image-slider > div:first-child {
position: absolute;
top: 0; bottom: 0; left: 0;
width: 10px;
max-width: 100%;
overflow: hidden;
resize: horizontal;
}
/* Cross-browser resizer styling */
.image-slider > div:first-child:before {
content: 'drag to resize';
position: absolute;
right: 0; bottom: 0;
width: 13px; height: 13px;
padding: 5px;
background: linear-gradient(-45deg, white 50%, transparent 0);
background-clip: content-box;
cursor: ew-resize;
-webkit-filter: drop-shadow(0 0 2px black);
filter: drop-shadow(0 0 2px black);
}
.image-slider img {
user-select: none;
max-width: 400px;
}
<div class="image-slider">
<div><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-before.jpg" /></div>
<div><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-after.jpg" /></div>
</div>
// alert('Hello world!');
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"}
@solidgoldpig
Copy link
Author

Tweaked to use 2 div > imgs rather than the existing div > img, img arrangement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment