Cross browser compatibility with SVG background - svg
I work on a app which supports on IE 10 and Chrome. For background images we go with svg sprite.Wherever we need to position icons we have defined a common class for the image and also defined class based on the icon.
Once we build the app, we found the positioning is fine on chrome browser and for IE we need to write a separate css fix based on the browser.
html
<ul>
<li><a class="pico menu href="javascript:void(0)">Home</a></li>
</ul>
My css looks like
.pico:after{
background:('sprite.svg') 0 0 no-repeat;
background-size: 280px 660px;
position:absolute;
content:""
}
.pico.menu:after{
background-position:-106px 6px;
}
.ie .pico.menu:after{
background-position:-110px 6px;
}
Is there anyway to have a generic styles for IE and Chrome ?. Or is the default behavior of the browsers.
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="300px" height="650px" viewBox="561 165 246 580" enable-background="new 561 165 246 580" xml:space="preserve">
<g>
<g>
<polygon fill="#F47621" points="580.3,230 585.5,235.2 590.8,230 589.8,229 585.5,233.1 581.3,229 "/>
</g>
<g>
<polygon fill="#F47621" points="580.3,225.5 585.5,230.7 590.8,225.5 589.8,224.6 585.5,228.8 581.3,224.6 "/>
</g>
</g>
</svg>
Here i cleaned up some of the code. Don't use the external url for your images of course.
Tested in chrome and IE 11 and IE 10. Both will display the image correctly.
.pico::after {
background: url(http://imgh.us/test_55.svg) 0 0 no-repeat;
background-size: 280px 660px;
position: absolute;
content: "";
display: inline-block;
width: 30px;
height: 20px;
}
.pico.menu::after {
background-position: -10px -65px;
}
svg {
border: 5px solid black;
}
<ul>
<li><a class="pico menu" href="javascript:void(0)">Home</a>
</li>
</ul>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="650px" viewBox="561 165 246 580" enable-background="new 561 165 246 580" xml:space="preserve">
<polygon fill="#F47621" points="580.3,230 585.5,235.2 590.8,230 589.8,229 585.5,233.1 581.3,229 " />
<polygon fill="#F47621" points="580.3,225.5 585.5,230.7 590.8,225.5 589.8,224.6 585.5,228.8 581.3,224.6 " />
</svg>
Related
css rotate introduces outline when using SVG clip-path or mask
Is there a way to stop this outline in firefox? #blob { background: red; width: 500px; height: 500px; clip-path: url(#myClip); transform: rotate(20deg);} <div id="blob"></div> <svg> <defs> <path d="M320.403196,424.677624 C426.787532,365.585154 447.310044,306.188587 433.45394,197.28033 C419.597836,88.3720737 316.997962,53.8862578 227.347416,40.9086547 C144.650118,28.9375873 104.472702,88.6407456 69.862267,131.812053 C15.52584,199.588564 48.3439099,300.905451 80.8563197,361.757908 C110.80391,417.809872 214.018859,483.770094 320.403196,424.677624 Z" id="path-1"></path> <clipPath id="myClip"><use href="#path-1"></use></clipPath> </defs> </svg> This renders correctly in other browsers, just need some work around for this firefox bug same outline appears using either clip-path or mask
As a workaround you could rotate the clipPath instead: #blob { background: red; width: 500px; height: 500px; clip-path: url(#myClip); } <div id="blob"></div> <svg viewBox="0 0 397 409"> <defs> <path d="M320.403196,424.677624 C426.787532,365.585154 447.310044,306.188587 433.45394,197.28033 C419.597836,88.3720737 316.997962,53.8862578 227.347416,40.9086547 C144.650118,28.9375873 104.472702,88.6407456 69.862267,131.812053 C15.52584,199.588564 48.3439099,300.905451 80.8563197,361.757908 C110.80391,417.809872 214.018859,483.770094 320.403196,424.677624 Z" id="path-1" /> <clipPath id="myClip" transform="rotate(20)" transform-origin="center"> <use href="#path-1"></use> </clipPath> </defs> </svg>
SVG <image> class does not work in Safari
I am using the <image> element within an <svg> in Safari. Whilst the <image> displays in Chrome it does not display in Safari. Here is my code .swatch { width: 10rem; } .swatch-base { width: 100%; height: 100%; } .filter-swatch { width: 100%; height: 100%; mix-blend-mode: multiply; } <svg class="swatch" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 305 305" preserveAspectRatio="xMidYMin slice"> <image class="swatch-base" xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/7QA4UGhvdG9zaG9w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2gTILhhgPLr71JsVxh4rAicNUK5aExJoooK8KY8AfCtCdpIn/Wmx0XAf8QMMQMFVZOxOtFFBN2OCWsgWlAMhldrVUCl8UFFIwmhMtM6KKBXA/DNibIRs7FWc4u1rHw1wybZGzIC/wDVrRRQT/EA4WKcNDCqIAgUUUUH/9k= " preserveAspectRatio="xMinYMin" onerror="" x="0" y="0"></image> <rect class="filter-swatch" fill="#ecd5cf"></rect> </svg> Please note that within my code I have inlined the image so that no external resources are used and this answer will therefore still be useful when the image no longer lives on my server. In production though, I am referencing an image and not inlining it. How can I display the image as is displayed in Chrome?
For Safari width and height on images must be specified as attributes and not via CSS. Using CSS on images is new in SVG 2 and Safari hasn't implemented this part of SVG 2 yet. .swatch { width: 10rem; } .filter-swatch { width: 100%; height: 100%; mix-blend-mode: multiply; } <svg class="swatch" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 305 305" preserveAspectRatio="xMidYMin slice"> <image class="swatch-base" xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAZABkAwEiAAIRAQMRAf/EABkAAAMBAQEAAAAAAAAAAAAAAAACAwEEB//EADoQAAIBAgMHAgQFAgQHAAAAAAECEQASAyExEyIyQVFhYlJxI0JygQQzocHhU9EUkbHxQ2OCk7LS0//EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPw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VFYAFlERkRkOn1GnwgHxVCjaEkmGGTdz/oKUi1gZz1GWvVvcUGYhwrt44ij5VRogd+9FMWVWJXIMZuK5v3ooB3ucQ2001EXHp7DWtZlJYBzigxbP/EPT2FK+9iNcyvkoYocvpHencS+Je6MIW4qBn0Ve4oIIpLmMGQTERqctz2HWrYZllIS+7QT+Z/tUDhpIlW8rTquUBT1qmGgHEx5B9nz6W/vQMy7xDqHXJTl+ZHy/aptswhDYZa7rM4hHL7U7wjMWYTAm0DTt5UhZLHF5CgZ5aaQF70GqqEEiGk9TvnlHtTkrdiy4e/iCj80zG7/FYgnDxJIAEBui55Bf3pijK2LeFWBvWxujw70Bg2XBgGxCTJs+YjmOwqknZmQxBi8DXEPj2qeENmwLALGsRl0AHfnTtIRpIUJFzD5M9FoMw2BYA4ReNbdWPbsNKm2pkZ5XRlPSPbnToHw8ziHDjWzOMsgOvU1FtDLQF1PonSPfnQa6IXJKM5nNgcie1FSdipAOI2HlwLovYUUF8YxiG2BmqZD9ffvTYsK+IVUCFVRHyn1DvlrRRQRLMAIdhBKrnw6ZjvVVBUXKzAiLc+HLMiiigbEOy2gTILhhgPLr71JsVxh4rAicNUK5aExJoooK8KY8AfCtCdpIn/Wmx0XAf8QMMQMFVZOxOtFFBN2OCWsgWlAMhldrVUCl8UFFIwmhMtM6KKBXA/DNibIRs7FWc4u1rHw1wybZGzIC/wDVrRRQT/EA4WKcNDCqIAgUUUUH/9k= " preserveAspectRatio="xMinYMin" onerror="" x="0" y="0" width="100%" height="100%"></image> <rect class="filter-swatch" fill="#ecd5cf"></rect> </svg>
SVG - inherit multiple colors/animations
What I try to do: Using a <use> element to copy an icon, and color the icon in two different colors when a specific class is added to the <use> element. The Icon: <symbol xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="red5" x="0px" y="0px" viewBox="0 0 48.1 50.8"> <style type="text/css"> .st0{ fill:#D73647; stroke:#000000; stroke-miterlimit:10; } /* use.active .color-a{ fill: green; } use.active .color-b{ fill: blue; }*/ // Not working... </style> <g> <path class="st0 color-a" d="M2.3,20.2L11.8,20.2C11.8,20.2 12.5,10.9 22.3,11.2C22.3,11.2 28.5,11.1 32.3,16L26.3,22.4L47.5,22.4L47.5,2.7L40.4,9C40.4,9 36.1,0.4 23.6,0.5C23.6,0.5 4.8,-0.2 2.3,20.2z"> </path> <path class="st0 color-b" d="M45.8,30.6L36.3,30.6C36.3,30.6 35.6,39.9 25.8,39.6C25.8,39.6 19.6,39.7 15.8,34.8L21.8,28.4L0.5,28.4L0.5,48.1L7.7,41.7C7.7,41.7 12,50.3 24.5,50.2C24.5,50.3 43.3,51 45.8,30.6z"> </path> </g> </symbol> The Use Element: <use id="svg_16" xlink:href="#red5" transform="matrix(0.6730555893894703,0,0,0.7071457914654147,-239.09557391490307,-165.87702520953462) " y="269.9999919533732" x="473.99998587369964" class="default-state" fill="black"></use> When the class of the <use> is changed from "default-state" to "active", I want the colors of the arrows to change (each to its own color). What I've tried so far: I understood that for the paths to change their color from the <use> element I have to change their CSS class to this: .st0{ fill: inherit; // <- changed stroke: #000000; stroke-miterlimit: 10; } and the color classes to this: use.active { fill: green; } but then when I set the class of <use> to "active" they both get the same color... I would like to do the same thing for animations. What am I missing? How do I achive this?
This is how I would do it: I would create one symbol and I would reuse twice the same path: once as it is and once rotated 180 degs. For the "default" state please remove the active class of the g element. .st0{ stroke-miterlimit:10; } .active .color-a{ fill: green; } .active .color-b{ fill: blue; } svg{width:90vh;border:1px solid} <svg viewBox="0 0 140 150" > <symbol id="a" viewBox="0 0 48.1 50.8"> <path class="st0 color-a" id="k" d="M2.3,20.2L11.8,20.2C11.8,20.2 12.5,10.9 22.3,11.2C22.3,11.2 28.5,11.1 32.3,16L26.3,22.4L47.5,22.4L47.5,2.7L40.4,9C40.4,9 36.1,0.4 23.6,0.5C23.6,0.5 4.8,-0.2 2.3,20.2z"> </path> </symbol> <g class="active" id="svg_16" > <use class="color-a" xlink:href="#a"> </use> <use class="color-b" transform="rotate(180 70 75)" xlink:href="#a"> </use> </g> </svg>
SVG will not display in browser
I am trying to display a simple bar in the browser using svg but for some reason it is not displaying. Here is the code I am using. It does not display the bar. <h3>SVG Bar</h3> <svg> <rect with="50" height="200" style="fill: blue"/> </svg> What am I missing?
You've written your width attribute as "with". But even correcting the typo, you can make a few more improvements: svg { border: 1px solid black; width: 20vw; height: 20vw; } <h3>SVG Bar</h3> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 1000 1000"> <rect x="0" y="0" width="200" height="500" style="fill: blue"> </svg>
How to round image inside svg
I create an image inside a svg but want to round it and fill the shape (small circle). I already did image round in html image tag using css style but not know how i can do it in side a svg or apply same css style in svg. Here is a code: <HTML> <HEAD> <style> .pic-circle-corner { display: block; width: 25px; height: 25px; /* margin: .8em auto; */ background-size: cover; background-repeat: no-repeat; background-position: center center; -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%; border: 5px ; /* solid #eee*/ box-shadow: 0 3px 2px rgba(0, 0, 0, 0.3); } </style> </HEAD> <BODY> <div> picture should fill inside round shape.. <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 40 40" enable- background="new 0 0 40 40" xml:space="preserve"> <filter id="this_image" x="0%" y="0%" width="100%" height="100%"> <feImage width="28px" height="28px" xlink:href="http://pic.1fotonin.com/data/wallpapers/1/WDF_499177.jpg"/> </filter> <circle cx="46" cy="42" r="40" stroke="black" stroke-width="3" filter="url(#this_image)" /> <path fill-rule="evenodd" clip-rule="evenodd" fill="#026890" d="M35.686,13.595c-0.172-1.381-0.541-2.705-1.085-3.979 c-0.517-1.208-1.19-2.327-1.995-3.37c-0.758-0.982-1.629-1.855-2.593-2.629c-1.124-0.901-2.359-1.633-3.688-2.197 c-1.44-0.613-2.941-1.011-4.497-1.179c-2.306-0.252-4.575-0.041-6.787,0.672c-1.006,0.324-1.975,0.741-2.896,1.261 c-1.782,1.007-3.32,2.295-4.606,3.889C6.355,7.53,5.472,9.165,4.893,10.956c-0.397,1.23-0.63,2.498-0.694,3.793 c-0.057,1.153-0.017,2.301,0.175,3.438c0.158,0.944,0.415,1.866,0.749,2.767c0.369,0.994,0.842,1.938,1.434,2.815 c0.666,0.986,1.373,1.944,2.053,2.921c1.443,2.076,10.465,12.023,11.379,13.173c1.063-1.314,10.533-11.896,13.064-15.517 c0.96-1.372,1.713-2.839,2.175-4.453c0.242-0.849,0.427-1.708,0.52-2.586C35.875,16.068,35.84,14.832,35.686,13.595z M20,28.318 c-7.041,0-12.75-5.709-12.75-12.751S12.958,2.817,20,2.817c7.042,0,12.75,5.708,12.75,12.75S27.042,28.318,20,28.318z"/> </svg> </div> <div style="padding-top:50px;"> <image class="pic-circle-corner" src="http://pic.1fotonin.com/data/wallpapers/1/WDF_499177.jpg"> </div> </BODY> </HTML> Can someone tell me a correct way.
these are some options: 1) absolute position - place the SVG path inside a container and place an absolute positioned circled div with a background image on top of the path. HTML/SVG: <div class="container"> <div class="circle-div"> </div> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 40 40"> <path fill-rule="evenodd" clip-rule="evenodd" fill="#026890" d="M35.686,13.595c-0.172-1.381-0.541-2.705-1.085-3.979 c-0.517-1.208-1.19-2.327-1.995-3.37c-0.758-0.982-1.629-1.855-2.593-2.629c-1.124-0.901-2.359-1.633-3.688-2.197 c-1.44-0.613-2.941-1.011-4.497-1.179c-2.306-0.252-4.575-0.041-6.787,0.672c-1.006,0.324-1.975,0.741-2.896,1.261 c-1.782,1.007-3.32,2.295-4.606,3.889C6.355,7.53,5.472,9.165,4.893,10.956c-0.397,1.23-0.63,2.498-0.694,3.793 c-0.057,1.153-0.017,2.301,0.175,3.438c0.158,0.944,0.415,1.866,0.749,2.767c0.369,0.994,0.842,1.938,1.434,2.815 c0.666,0.986,1.373,1.944,2.053,2.921c1.443,2.076,10.465,12.023,11.379,13.173c1.063-1.314,10.533-11.896,13.064-15.517 c0.96-1.372,1.713-2.839,2.175-4.453c0.242-0.849,0.427-1.708,0.52-2.586C35.875,16.068,35.84,14.832,35.686,13.595z M20,28.318 c-7.041,0-12.75-5.709-12.75-12.751S12.958,2.817,20,2.817c7.042,0,12.75,5.708,12.75,12.75S27.042,28.318,20,28.318z"/> </svg> </div> CSS: .container { position: relative; } .circle-div { border-radius: 50%; background-image: url('http://pic.1fotonin.com/data/wallpapers/1/WDF_499177.jpg'); width: 25px; height: 25px; background-size: cover; background-position: 25% 25%; position: absolute; left: 7.5px; top: 2.5px; } 2) SVG clipPath - place an SVG image on top the SVG path and clip it with a circle. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40px" height="40px" viewBox="0 0 40 40"> <defs> <clipPath patternUnits="userSpaceOnUse" id="clip"> <circle cx="50%" cy="40%" r="13" ></circle> </clipPath> </defs> <image preserveAspectRatio="xMidYMid slice" clip-path="url(#clip)" x="5" y="2" width="100%" height="65%" xlink:href="http://pic.1fotonin.com/data/wallpapers/1/WDF_499177.jpg"></image> <path stroke-width="1px" stroke="#026890" fill-rule="evenodd" clip-rule="evenodd" fill="#026890" d="M35.686,13.595c-0.172-1.381-0.541-2.705-1.085-3.979 c-0.517-1.208-1.19-2.327-1.995-3.37c-0.758-0.982-1.629-1.855-2.593-2.629c-1.124-0.901-2.359-1.633-3.688-2.197 c-1.44-0.613-2.941-1.011-4.497-1.179c-2.306-0.252-4.575-0.041-6.787,0.672c-1.006,0.324-1.975,0.741-2.896,1.261 c-1.782,1.007-3.32,2.295-4.606,3.889C6.355,7.53,5.472,9.165,4.893,10.956c-0.397,1.23-0.63,2.498-0.694,3.793 c-0.057,1.153-0.017,2.301,0.175,3.438c0.158,0.944,0.415,1.866,0.749,2.767c0.369,0.994,0.842,1.938,1.434,2.815 c0.666,0.986,1.373,1.944,2.053,2.921c1.443,2.076,10.465,12.023,11.379,13.173c1.063-1.314,10.533-11.896,13.064-15.517 c0.96-1.372,1.713-2.839,2.175-4.453c0.242-0.849,0.427-1.708,0.52-2.586C35.875,16.068,35.84,14.832,35.686,13.595z M20,28.318 c-7.041,0-12.75-5.709-12.75-12.751S12.958,2.817,20,2.817c7.042,0,12.75,5.708,12.75,12.75S27.042,28.318,20,28.318z"/> </svg> 3) SVG pattern - place an SVG circle on top the SVG path and fill it with a pattern that is the image itself. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40px" height="40px" viewBox="0 0 40 40"> <defs> <pattern id="pf" x="0" y="0" height="100%" width="100%" viewBox="0 0 960 420" preserveAspectRatio="xMinYMid slice"> <image x="-150" y="11" width="960" height="420" xlink:href="http://pic.1fotonin.com/data/wallpapers/1/WDF_499177.jpg" ></image> </pattern> </defs> <circle cx="50%" cy="40%" r="13" fill="url(#pf)"></circle> <path stroke-width="1px" stroke="#026890" fill-rule="evenodd" clip-rule="evenodd" fill="#026890" d="M35.686,13.595c-0.172-1.381-0.541-2.705-1.085-3.979 c-0.517-1.208-1.19-2.327-1.995-3.37c-0.758-0.982-1.629-1.855-2.593-2.629c-1.124-0.901-2.359-1.633-3.688-2.197 c-1.44-0.613-2.941-1.011-4.497-1.179c-2.306-0.252-4.575-0.041-6.787,0.672c-1.006,0.324-1.975,0.741-2.896,1.261 c-1.782,1.007-3.32,2.295-4.606,3.889C6.355,7.53,5.472,9.165,4.893,10.956c-0.397,1.23-0.63,2.498-0.694,3.793 c-0.057,1.153-0.017,2.301,0.175,3.438c0.158,0.944,0.415,1.866,0.749,2.767c0.369,0.994,0.842,1.938,1.434,2.815 c0.666,0.986,1.373,1.944,2.053,2.921c1.443,2.076,10.465,12.023,11.379,13.173c1.063-1.314,10.533-11.896,13.064-15.517 c0.96-1.372,1.713-2.839,2.175-4.453c0.242-0.849,0.427-1.708,0.52-2.586C35.875,16.068,35.84,14.832,35.686,13.595z M20,28.318 c-7.041,0-12.75-5.709-12.75-12.751S12.958,2.817,20,2.817c7.042,0,12.75,5.708,12.75,12.75S27.042,28.318,20,28.318z"/> </svg> I think the easiest solution in this case is to go with CSS, as it requires less position-tweaking to get proper results. demo