SVG + CSS – how to include in HTML and scale & color?

I ma trying to understand how to include a SVG as a class and manipulate it via CSS for hover etc.

I got the following svg example from icomoon. The purpose is to avoid a number of http requests in a page and include as much icon information into a CSS using class.

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512"><g id="icomoon-ignore">
</g>
<path d="M192 232c0 13.2-10.8 24-24 24h-48c-13.2 0-24-10.8-24-24v-48c0-13.2 10.8-24 24-24h48c13.2 0 24 10.8 24 24v48z"></path>
<path d="M352 232c0 13.2-10.8 24-24 24h-48c-13.2 0-24-10.8-24-24v-48c0-13.2 10.8-24 24-24h48c13.2 0 24 10.8 24 24v48z"></path>
<path d="M192 392c0 13.2-10.8 24-24 24h-48c-13.2 0-24-10.8-24-24v-48c0-13.2 10.8-24 24-24h48c13.2 0 24 10.8 24 24v48z"></path>
<path d="M352 392c0 13.2-10.8 24-24 24h-48c-13.2 0-24-10.8-24-24v-48c0-13.2 10.8-24 24-24h48c13.2 0 24 10.8 24 24v48z"></path>
<path d="M456.041 80l55.959-55.958v-24.042h-24.041l-55.959 55.958-55.959-55.958h-24.041v24.042l55.959 55.958-55.959 55.958v24.042h24.041l55.959-55.958 55.959 55.958h24.041v-24.042z"></path>
<path d="M0 384h32v64h-32v-64z"></path>
<path d="M0 288h32v64h-32v-64z"></path>
<path d="M416 224h32v64h-32v-64z"></path>
<path d="M416 416h32v64h-32v-64z"></path>
<path d="M416 320h32v64h-32v-64z"></path>
<path d="M0 192h32v64h-32v-64z"></path>
<path d="M0 96h32v64h-32v-64z"></path>
<path d="M256 64h64v32h-64v-32z"></path>
<path d="M160 64h64v32h-64v-32z"></path>
<path d="M64 64h64v32h-64v-32z"></path>
<path d="M224 480h64v32h-64v-32z"></path>
<path d="M320 480h64v32h-64v-32z"></path>
<path d="M128 480h64v32h-64v-32z"></path>
<path d="M32 480h64v32h-64v-32z"></path>
</svg>

I know from codepen example that if I just include it as a html code – it will work. (http://codepen.io/anon/pen/epvLgO)

But what I want to do is something like

.icon {
     <insert the contents of the svg file here>
}

.icon:hover {
fill: red ;
}

and then in html do something like

<span class="icon"></span>

also – for this icon – how can I change the size on the fly for various medias ?

meaning

if iphone, I want to set the icon size differently…

.icon {
width: 32px;
heigh: 32px;
}

thanks.. (this is to see how I can reduce the total number of http call – by using SVG and CSS)


Source: css3

Leave a Reply