Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add background in CSS? #92

Open
Ajeey opened this issue Mar 17, 2017 · 2 comments
Open

How to add background in CSS? #92

Ajeey opened this issue Mar 17, 2017 · 2 comments
Labels

Comments

@Ajeey
Copy link

Ajeey commented Mar 17, 2017

If I use <i class="icon facebook"></i> the svg is rendered.

But say I want to add the svg as background in CSS.

.myclass {
   background: *** // How do I get the svg here?
}
@soenkekluth
Copy link
Collaborator

soenkekluth commented Mar 29, 2017

@Ajeey well you have some options.

all included templates for generating the css / scss from your svg files are using the :before selector to set the background image / size and position styles.

if that is not a problem for you you can just "extend" the icon class in your css / html
<div class="myclass svg-icon-youricon"></div> which will add the icon (styles) to the :before element of your .myclass

you can also write your own template that does not use :before.

templates are here https://github.com/shakyShane/gulp-svg-sprites/tree/master/tmpl

if you use sass / scss you can make use of the mixin feature. i would use https://github.com/shakyShane/gulp-svg-sprites/blob/master/tmpl/sprite.scss and just extract the background style definition to an extra mixin. so you can use it everywhere

@rruprai
Copy link

rruprai commented Dec 14, 2017

@Ajeey
Could this be what you are looking to do? Just replace with insert_dir_here with the location where the sprite is located. I just used the following below.

Possible option for insert_dir_here:
'../image/sprite/{{{sprite}}}


{{#shapes}}
  {{#first}}
    .myclass {
      background-image: url('__insert_dir_here__');
    }
  {{/first}}

  .icon--{{base}} {
    /*add other code here*/
  }
{{/shapes}}

@soenkekluth using the :before attribute is a great option as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants