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

Using an svg with css backgrounds....as a css background #33

Open
ccbayer opened this issue Aug 1, 2013 · 0 comments
Open

Using an svg with css backgrounds....as a css background #33

ccbayer opened this issue Aug 1, 2013 · 0 comments

Comments

@ccbayer
Copy link

ccbayer commented Aug 1, 2013

Something like this works in IE, but not FF / Chrome, at least in my experimenting.

It's an element whose background is an SVG, which in turn also has the responsive backgrounds which load based on mediaquery.

Setting different background colors in the SVG media queries works, so i know that the SVG is loading.

Is this the same security issues as using inline images?

html:

    <style>
    .svg{
        background-image:url('path/to/svgfile.svg');
        background-size:cover;
        height: 100px;
        width: 100%;
        }
    </style>
    <div class="svg"></div>

svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800" preserveAspectRatio="xMidYMid meet">

  <title>The Clown Car Technique</title>
  <style>
    svg {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    }

    @media screen and (max-width: 400px) {
      svg {
        background-color: blue;
        background-image: url("../images/small.jpg");
      }
    } 

    @media screen and (min-width: 401px) and (max-width: 800px) {
      svg {
        background-color: red;
        background-image: url("../images/medium.jpg");
      }
    }

    @media screen and (min-width: 801px){
      svg {
        background-color: black;
        background-image: url("../images/large.jpg");
      }
    }
  </style>
</svg>

Chrome:
chrome

IE 10:
ie

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

No branches or pull requests

1 participant