by Andrey Kuzmin, @unsoundscapes
Andrey Kuzmin, @unsoundscapes
.icon {
background-image: url(icons.png);
display: inline-block;
}
.icon-twitter {
background-position: -137px -50px;
width: 31px; height: 31px;
}
.icon-close {
background-image: url('data:image/png;base64,iVBORw0K...
}
@font-face { font-family: IconFont; ... }
.icon:before { font-family: IconFont; }
.icon-close:before { content: "\025B6"; }
<svg>
<view id='icon-close' viewBox='0 40 20 20'/>
...
</svg>
<img src='icons.svg#icon-close' alt='x'>
<svg>
<symbol id="icon-close" viewBox="0 0 20 20"/>...</symbol>
<symbol id="icon-menu" viewBox="0 0 20 20"/>...</symbol>
...
</svg>
...
<svg><use xlink:href="#icon-close"></svg>
Illustration by @01k
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var div = document.createElement('div');
div.innerHTML = xhr.responseText;
document.body.insertBefore(div, document.body.childNodes[0]);
}
xhr.open('GET', 'img/icons.svg', true);
xhr.send();
var gulp = require('gulp');
var svgstore = require('gulp-svgstore');
gulp.task('svgstore', function () {
return gulp.src('src/icons/*.svg')
.pipe(svgstore())
.pipe(gulp.dest('dest/img'));
});
Illustration by @01k
<span class="icon icon-close">
<svg width="50" height="50">
<use xlink:href="#icon-close"></use>
</svg>
</span>
.icon { display: inline-block; vertical-align: middle; }
.icon > svg {
display: block;
fill: currentColor;
pointer-events: none;
}
.no-js .icon > svg { display: none; }
Andrey Kuzmin, @unsoundscapes