Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Last active January 22, 2016 16:39
Show Gist options
  • Save jacopotarantino/f0fa514fe4633bec87c9 to your computer and use it in GitHub Desktop.
Save jacopotarantino/f0fa514fe4633bec87c9 to your computer and use it in GitHub Desktop.
Make broken images not suck.
<script>
(() => {
'use strict'
let styles = `
.pretty-broken-image {
visibility: hidden;
position: relative;
}
.pretty-broken-image:after {
content: 'oops!';
background: lightblue;
display: block;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
visibility: visible;
color: white;
text-align: center;
line-height: 40px;
}
`
let stylesheet = document.createElement('style')
stylesheet.innerHTML = styles
document.body.appendChild(stylesheet)
})()
</script>
<img src="foobar-broken-link.gif" alt="i shouldn't load and this should have ugliness" onerror="this.classList.add('pretty-broken-image')">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment