It's the first time I'm going to use SVG graphics and I'm a bit confused… I've researched extensively but I cannot seem to find an answer to what I'm trying to do.
I want to give an image the following appearance, given the source image is a color image.
The main reason behind this effect is to overcome bad quality images (both in terms of aesthetics and resolution) my clients might upload to their websites.
In Photoshop this is a Gradient Map and a transparent grid in Mode Multiply.
I've managed to apply a filter for the grayscale and "gradient map" but I cannot add the grid/pattern.
This is my code so far:
SVG file gradient-map.svg
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<feColorMatrix type="matrix" result="grayscale"
values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0" >
</feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
HTML
<div class="image">
<img src="link/to/file" />
</div>
CSS
.image {
filter: url('../images/gradient-map.svg#duotone_filter');
}
And the SVG file for the pattern/fill
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<circle cx="3" cy="3" r="2" />
</svg>
Is this the way things should be done? How should I proceed to achieve this effect?
If you could also link me to useful resources I would much appreciate. I haven't found any recent guides or articles.
Thanks.
You're on the right track. Here's a demo I put together (and on Codepen). And the output:
There's a helpful question to Overlay grid on responsive image, but I opted for simply overlaying and scaling a large transparent PNG. You'll likely end up with better results if you use a small, repeating grid section. Of course you'll have to choose what color, size, etc. to make the grid overlay.
As a side note, you cannot use the :after or :before pseudo-elements with img elements, so you need to wrap them in a container. You could also accomplish this with an additional element, like:
<div class="img-container">
<img src="..." />
<div class="grid-overlay"></div>
</div>
But I prefer pseudo-elements so I don't have to repeat <div class="grid-overlay"></div> every time I want the grid overlay.
img {
filter: url(#duotone_filter)
}
.img-container {
display: inline-block;
overflow: hidden;
position: relative;
height: 375px;
}
.img-container::after {
content: '';
display: block;
position: absolute;
background-image: url('http://www.freeiconspng.com/uploads/grid-png-31.png');
background-size: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="img-container"><img src="http://kb4images.com/images/random-image/37670495-random-image.jpg" /></div>
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<feColorMatrix type="matrix" result="grayscale"
values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0" >
</feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
Also an example using only SVGs (symbols):
One final example that also works in Firefox and uses two SVG filters. The key to this example is that it uses another filter to create a composite image. I took another SVG from the web but you could use an inline SVG and reference it by ID as well.
<filter id="overlay">
<feImage result="sourceTwo" xlink:href="http://www.vectorstash.com/vectors/vectorstash-grid.svg" width="500" height="375" preserveAspectRatio="none" x="0" y="0" />
<feComposite in="SourceGraphic" in2="sourceTwo" operator="out" x="0" y="0" />
</filter>
A handy way to do this is to combine the grid overlay with the filter by putting inline SVG for the grid into an feImage primitive.
(I also changed your greyscale matrix because it was only using the red channel as source which is going to create weird results on blue/green heavy photos.)
.filterclass {
filter: url(#duotone_filter);
}
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feImage width="6" height="6" xlink:href= "data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20x%3D%220%22%20y%3D%220%22%20width%3D%226px%22%20height%3D%226px%22%20viewBox%3D%220%200%206%206%22%3E%0A%20%20%20%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%226%22%20height%3D%226%22%20fill%3D%22none%22%20stroke%3D%22grey%22/%3E%0A%3C/svg%3E"/>
<feTile result="overlay"/>
<feColorMatrix in="SourceGraphic" type="matrix" result="grayscale"
values=".33 .33 .33 0 0
.33 .33 .33 0 0
.33 .33 .33 0 0
0 0 0 1 0" />
<feComponentTransfer result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
<feBlend mode="multiply" in="overlay"/>
</filter>
</svg>
<div >
<img class="filterclass" src="http://kb4images.com/images/random-image/37670495-random-image.jpg" />
</div>
The source SVG for the inlined data uri is
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<rect x="0" y="0" width="6" height="6" fill="none" stroke="grey"/>
</svg>
If you want to tweak it - I use this converter for svg+xml - which is pretty useful https://codepen.io/yoksel/details/JDqvs
Related
I am using a SVG instead of an actual emoji in my website to make sure that it looks the same on all devices. However, the edges of the SVG are appearing blurry and pixelated when I view it on my iPhone. (does not happen on desktop.)
As you can see from the first image (✌️emoji svg), some parts of the SVG are blurry while others are crisp. In the second svg, (💭emoji) the edges are completely blurry.
It is not the svg that is causing the blurriness, it appears completely crisp on desktop.
This is how I am inserting the svg:
.emoji {
background-position:center center;
background-repeat:no-repeat;
background-size:1em 1em;
display:inline-block;
height:1em;
margin:0 .05em 0 .1em;
vertical-align:-0.1em;
width:1em
}
.emoji.victory-hand {
background-image: url(../emojis/emoji/victory_hand_color_default.svg);
}
.emoji.thought-balloon {
background-image: url(../emojis/emoji/thought_balloon_color.svg);
}
<h2>hello<i class="emoji victory-hand"></i></h2>
<h2>projects <i class="emoji thought-balloon"></i></h2>
The svg is fine when I use an svg viewer to view it or use a computer, it only appears blurry on mobile. Does anyone know why this is happening?
As commented, iOS safari apparently renders masked images at a fixed resolution.
So the image gets blurry when zooming in.
That's probably the reason, why some contours in the OP's emoji are crisp while others are blurry/pixelated.
Left: masked shape; right: clipped shape
body {
font-size: 5em;
background: #000;
}
svg {
height: 100%
}
.icon-wrap {
height: 1em;
display: inline-block;
}
<div class="icon-wrap">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
<defs>
<mask id="mask">
<rect x="0" y="0" width="100%" height="100%" fill="#000"></rect>
<path fill="#fff" d="M62.05 7.31c6.86 0 14.13 6.46 14.41 12.79c0.21 4.74-1.42 10.5-3 16.07c-1.98 6.98-3.68 13.01-2.02 17.42a3 3 0 0 0 2.81 1.94h0.11l7.2-0.25h0.06c7.33 0 13.3 5.96 13.31 13.3l0.05 42.21c0 2.5-0.97 4.86-2.74 6.63s-4.12 2.75-6.63 2.75h-0.08c-8.6-0.07-21.51-0.41-34.19-1.6c-8.6-0.81-17.48-2.09-24.11-5.85c-2.2-1.25-4.58-1.54-6.49-1.78c-0.76-0.09-1.47-0.18-2.03-0.32c-4.2-0.99-7.14-4.61-7.15-8.8l-0.08-32.75c-0.01-3.78 2.69-6.95 6.42-7.53c0.15-0.02 0.31-0.06 0.45-0.11c0.56-0.18 13.94-4.55 24.05-12.45c4.87-3.81 9.05-9.67 11.17-15.68s2.1-12.36 2.09-17.5c0-2.44-0.01-5.74 0.41-6.74a10.97 10.97 0 0 1 5.98-1.75"></path>
</mask>
</defs>
<radialGradient id="a" cx="51.77" cy="31.401" r="87.039" gradientTransform="matrix(-.00218 1 -.7873 -.00172 76.604 -20.315)" gradientUnits="userSpaceOnUse">
<stop offset=".6" stop-color="#FFCA28" />
<stop offset="1" stop-color="#FFB300" />
</radialGradient>
<path mask="url(#mask)" fill="url(#a)" d="M85.52 121.67c-8.63-.07-21.58-.41-34.32-1.61-8.77-.83-17.83-2.14-24.71-6.04-1.94-1.1-4.06-1.37-5.94-1.6-.8-.1-1.55-.19-2.19-.34-4.88-1.15-8.29-5.37-8.31-10.26l-.07-32.75c-.01-4.53 3.22-8.32 7.69-9.02.08-.01.15-.03.23-.05.55-.18 13.69-4.46 23.59-12.2 4.66-3.64 8.65-9.25 10.68-15 2.02-5.73 2.01-11.98 2-17 0-3.24-.01-7.27.87-7.86 2.14-1.41 4.5-2.13 7.01-2.13 7.72 0 15.6 7.05 15.91 14.23.22 4.98-1.45 10.86-3.06 16.54-1.9 6.73-3.55 12.54-2.06 16.49.22.59.78.97 1.4.97l7.29-.25h.07c8.16 0 14.8 6.64 14.81 14.79l.05 42.21c0 2.91-1.12 5.64-3.18 7.69a10.81 10.81 0 01-7.69 3.19h-.07z" />
</svg>
</div>
<div class="icon-wrap">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
<defs>
<clipPath id="clip">
<rect x="0" y="0" width="100%" height="100%" fill="#000"></rect>
<path fill="#fff" d="M62.05 7.31c6.86 0 14.13 6.46 14.41 12.79c0.21 4.74-1.42 10.5-3 16.07c-1.98 6.98-3.68 13.01-2.02 17.42a3 3 0 0 0 2.81 1.94h0.11l7.2-0.25h0.06c7.33 0 13.3 5.96 13.31 13.3l0.05 42.21c0 2.5-0.97 4.86-2.74 6.63s-4.12 2.75-6.63 2.75h-0.08c-8.6-0.07-21.51-0.41-34.19-1.6c-8.6-0.81-17.48-2.09-24.11-5.85c-2.2-1.25-4.58-1.54-6.49-1.78c-0.76-0.09-1.47-0.18-2.03-0.32c-4.2-0.99-7.14-4.61-7.15-8.8l-0.08-32.75c-0.01-3.78 2.69-6.95 6.42-7.53c0.15-0.02 0.31-0.06 0.45-0.11c0.56-0.18 13.94-4.55 24.05-12.45c4.87-3.81 9.05-9.67 11.17-15.68s2.1-12.36 2.09-17.5c0-2.44-0.01-5.74 0.41-6.74a10.97 10.97 0 0 1 5.98-1.75"></path>
</clipPath>
</defs>
<radialGradient id="a" cx="51.77" cy="31.401" r="87.039" gradientTransform="matrix(-.00218 1 -.7873 -.00172 76.604 -20.315)" gradientUnits="userSpaceOnUse">
<stop offset=".6" stop-color="#FFCA28" />
<stop offset="1" stop-color="#FFB300" />
</radialGradient>
<path clip-path="url(#clip)" fill="url(#a)" d="M85.52 121.67c-8.63-.07-21.58-.41-34.32-1.61-8.77-.83-17.83-2.14-24.71-6.04-1.94-1.1-4.06-1.37-5.94-1.6-.8-.1-1.55-.19-2.19-.34-4.88-1.15-8.29-5.37-8.31-10.26l-.07-32.75c-.01-4.53 3.22-8.32 7.69-9.02.08-.01.15-.03.23-.05.55-.18 13.69-4.46 23.59-12.2 4.66-3.64 8.65-9.25 10.68-15 2.02-5.73 2.01-11.98 2-17 0-3.24-.01-7.27.87-7.86 2.14-1.41 4.5-2.13 7.01-2.13 7.72 0 15.6 7.05 15.91 14.23.22 4.98-1.45 10.86-3.06 16.54-1.9 6.73-3.55 12.54-2.06 16.49.22.59.78.97 1.4.97l7.29-.25h.07c8.16 0 14.8 6.64 14.81 14.79l.05 42.21c0 2.91-1.12 5.64-3.18 7.69a10.81 10.81 0 01-7.69 3.19h-.07z" />
</svg>
</div>
Workarounds:
replace <mask> with <clipPath>
use compound paths for cutout shapes like holes (e.g. in the letter O)
try another emoji library with a more simplistic/cleaner svg structure
Safari has this really big issue where svgs are not rendered properly for its device's retina display.
Try adding:
-webkit-transform: translate3d(0,0,0)
To the svg.
If not, it might not be fixable as any svgs in Safari do not work well with outlines.
Also try adding:
shape-rendering="geometricPrecision"
To the svg.
Instead if that does not work either try:
shape-rendering = "crispEdges"
Instead of geometricPrecision, that disables anti-aliasing on the image through the browser.
So I am having issues with svg and all of its quirks, where I cannot <use> an <svg> from a file where I store all of my <svg> designs.
I tried using various methods to display the <svg> using <object> <img> & <svg> <use>, but no success.
The svg just does not display on the browser when I have an svg inside a <symbol> that contains other attributes like <g> Or <defs>,
however <symbol> svg's that contain just <path> work perfectly fine.
Project Structure:
assets/
|-> svg-icons.svg (<-- Main SVG icons location)
|-> checkMark.svg (<-- Copy of <symbol id="checkMark" in svg-icons.svg)
index.html
svg-icons.svg
<svg xmlns="http://www.w3.org/2000/svg">
<!--
Checkmark vector icon
-->
<symbol id="checkMark" width="27" height="27" viewBox="0 0 27 27" fill="black">
<g filter="url(#filter0_d)">
<path
d="M13.6635 6.5408C9.67777 6.5408 6.43506 9.78351 6.43506 13.7692C6.43506 17.7549 9.67777 20.9977 13.6635 20.9977C17.6492 20.9977 20.8919 17.7549 20.8919 13.7692C20.8919 9.78351 17.6492 6.5408 13.6635 6.5408ZM17.4254 11.3467L12.7547 16.907C12.7035 16.968 12.6397 17.0173 12.5678 17.0515C12.4958 17.0858 12.4174 17.1042 12.3377 17.1054H12.3283C12.2504 17.1054 12.1733 17.089 12.1021 17.0573C12.0309 17.0255 11.9672 16.9792 11.9151 16.9212L9.91339 14.6971C9.86255 14.6432 9.82301 14.5796 9.79708 14.5102C9.77115 14.4408 9.75936 14.3669 9.76239 14.2929C9.76543 14.2188 9.78324 14.1461 9.81478 14.0791C9.84631 14.012 9.89093 13.9519 9.94601 13.9024C10.0011 13.8528 10.0655 13.8147 10.1355 13.7904C10.2055 13.7661 10.2797 13.756 10.3537 13.7608C10.4276 13.7655 10.4999 13.785 10.5662 13.8181C10.6325 13.8512 10.6915 13.8972 10.7398 13.9534L12.3137 15.7021L16.574 10.6315C16.6695 10.521 16.8047 10.4525 16.9503 10.4409C17.096 10.4293 17.2403 10.4755 17.3521 10.5695C17.464 10.6634 17.5344 10.7976 17.5481 10.943C17.5618 11.0885 17.5177 11.2335 17.4254 11.3467V11.3467Z"
fill="#333333" />
</g>
<defs>
<filter id="filter0_d" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
<feOffset />
<feGaussianBlur stdDeviation="2.78016" />
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
</filter>
</defs>
</symbol>
<!-- House on sale/rent vector icon -->
<symbol id='sell-house-vector' width="44" height="52" viewBox="0 0 44 52">
<path
d="M10.6449 38.3145C10.6449 39.419 11.5403 40.3145 12.6449 40.3145H40.5794C41.684 40.3145 42.5794 39.419 42.5794 38.3145V14.9915C42.5794 13.887 41.684 12.9915 40.5794 12.9915H12.6449C11.5403 12.9915 10.6449 13.887 10.6449 14.9915V38.3145ZM25.5578 16.8353C26.3121 16.1898 27.4259 16.1954 28.1737 16.8485L36.796 24.3786C37.3467 24.8596 37.0065 25.7662 36.2754 25.7662C35.8382 25.7662 35.4839 26.1205 35.4839 26.5576V35.8306C35.4839 36.9351 34.5885 37.8306 33.4839 37.8306H30.7414C29.6369 37.8306 28.7414 36.9351 28.7414 35.8306V31.3145C28.7414 30.2099 27.846 29.3145 26.7414 29.3145H26.4829C25.3783 29.3145 24.4829 30.2099 24.4829 31.3145V35.8306C24.4829 36.9351 23.5874 37.8306 22.4829 37.8306H20.0966C18.992 37.8306 18.0966 36.9351 18.0966 35.8306V26.5689C18.0966 26.1256 17.7372 25.7662 17.2939 25.7662C16.5484 25.7662 16.2056 24.8384 16.772 24.3536L25.5578 16.8353ZM9.09657 6.2501C7.992 6.2501 7.09657 5.35467 7.09657 4.2501V2C7.09657 0.895432 6.20114 0 5.09657 0H2C0.89543 0 0 0.895431 0 2V49.3145C0 50.419 0.89543 51.3145 2 51.3145H5.09657C6.20114 51.3145 7.09657 50.419 7.09657 49.3145V11.4443C7.09657 10.3397 7.992 9.44429 9.09657 9.44429H42.4029C43.285 9.44429 44 8.72924 44 7.84719C44 6.96514 43.285 6.2501 42.4029 6.2501H9.09657Z" />
</symbol>
<!-- Search Property vector icon -->
<symbol id='search-vector' width="35" height="34" viewBox="0 0 35 34">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M25.7641 23.2125C28.0071 20.3208 29.0643 16.6831 28.7204 13.0396C28.3765 9.39611 26.6575 6.02045 23.9131 3.59938C21.1687 1.17831 17.605 -0.1063 13.9471 0.00689208C10.2891 0.120084 6.81171 1.62258 4.22224 4.2087C1.63051 6.79661 0.12311 10.2754 0.00721327 13.9361C-0.108684 17.5968 1.17565 21.164 3.59848 23.9107C6.02132 26.6574 9.40031 28.3768 13.0469 28.7187C16.6935 29.0606 20.3332 27.9991 23.2243 25.7506L23.3016 25.8315L30.932 33.4637C31.0991 33.6308 31.2975 33.7633 31.5158 33.8538C31.7342 33.9442 31.9682 33.9908 32.2046 33.9908C32.4409 33.9908 32.675 33.9442 32.8933 33.8538C33.1117 33.7633 33.3101 33.6308 33.4772 33.4637C33.6443 33.2965 33.7769 33.0981 33.8673 32.8798C33.9578 32.6614 34.0043 32.4274 34.0043 32.191C34.0043 31.9547 33.9578 31.7207 33.8673 31.5023C33.7769 31.2839 33.6443 31.0855 33.4772 30.9184L25.8451 23.2881C25.8188 23.2622 25.7918 23.237 25.7641 23.2125ZM22.0299 6.75394C23.0455 7.75311 23.8532 8.94347 24.4064 10.2564C24.9597 11.5692 25.2475 12.9787 25.2533 14.4034C25.2591 15.828 24.9828 17.2398 24.4402 18.5571C23.8977 19.8745 23.0997 21.0714 22.0923 22.0788C21.0849 23.0862 19.888 23.8842 18.5707 24.4267C17.2533 24.9692 15.8416 25.2455 14.4169 25.2397C12.9922 25.2339 11.5828 24.9461 10.2699 24.3929C8.95701 23.8397 7.76665 23.032 6.76748 22.0164C4.77071 19.9868 3.65681 17.2505 3.6684 14.4034C3.68 11.5563 4.81615 8.82906 6.82937 6.81583C8.8426 4.80261 11.5698 3.66646 14.4169 3.65486C17.264 3.64327 20.0004 4.75717 22.0299 6.75394Z" />
</symbol>
</svg>
checkMark.svg
<svg xmlns="http://www.w3.org/2000/svg" id="checkMark" width="27" height="27" viewBox="0 0 27 27" fill="black">
<g filter="url(#filter0_d)">
<path
d="M13.6635 6.5408C9.67777 6.5408 6.43506 9.78351 6.43506 13.7692C6.43506 17.7549 9.67777 20.9977 13.6635 20.9977C17.6492 20.9977 20.8919 17.7549 20.8919 13.7692C20.8919 9.78351 17.6492 6.5408 13.6635 6.5408ZM17.4254 11.3467L12.7547 16.907C12.7035 16.968 12.6397 17.0173 12.5678 17.0515C12.4958 17.0858 12.4174 17.1042 12.3377 17.1054H12.3283C12.2504 17.1054 12.1733 17.089 12.1021 17.0573C12.0309 17.0255 11.9672 16.9792 11.9151 16.9212L9.91339 14.6971C9.86255 14.6432 9.82301 14.5796 9.79708 14.5102C9.77115 14.4408 9.75936 14.3669 9.76239 14.2929C9.76543 14.2188 9.78324 14.1461 9.81478 14.0791C9.84631 14.012 9.89093 13.9519 9.94601 13.9024C10.0011 13.8528 10.0655 13.8147 10.1355 13.7904C10.2055 13.7661 10.2797 13.756 10.3537 13.7608C10.4276 13.7655 10.4999 13.785 10.5662 13.8181C10.6325 13.8512 10.6915 13.8972 10.7398 13.9534L12.3137 15.7021L16.574 10.6315C16.6695 10.521 16.8047 10.4525 16.9503 10.4409C17.096 10.4293 17.2403 10.4755 17.3521 10.5695C17.464 10.6634 17.5344 10.7976 17.5481 10.943C17.5618 11.0885 17.5177 11.2335 17.4254 11.3467V11.3467Z"
fill="#333333" />
</g>
<defs>
<filter id="filter0_d" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
<feOffset />
<feGaussianBlur stdDeviation="2.78016" />
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
</filter>
</defs>
</svg>
index.html
<!-- Does not work -->
<img src="./assets/svg-icons.svg#checkMark" alt="design-img" title="design-img">
<!-- Does not work -->
<object type='image/svg+xml'data="./assets/svg-icons.svg#checkMark"> </object>
<!-- Does not work -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/svg-icons.svg#checkMark"></use>
</svg>
<!-- Works! -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/svg-icons.svg#sell-house-vector"></use>
</svg>
<!-- Does not work -->
<svg width="27" height="27" viewBox="0 0 27 27" xmlns="http://www.w3.org/2000/svg">
<use xlink:href="./assets/checkMark.svg"></use>
</svg>
<!-- Works -->
<object type='image/svg+xml'data="./assets/checkMark.svg"> </object>
Please try this: In the ./assets/svg-icons.svg change all the <symbol> in <svg> and add
<style type="text/css">
<![CDATA[
svg > svg:not(:target) {
display: none;
}
]]>
</style>
This is saying that only the targeted nested svg elements should be displayed.
Now in the index.html you should be able to see the image and the object.
Please read about How SVG Fragment Identifiers Work
Is it possible to transform a font with CSS to have rounded edges?
I'm talking about an effect similar to this smooth edges in Photoshop
So far I tried using a SVG filter, but it seems a bit complicated.
Is there a better way?
The code for the SVG filter used is this:
<svg viewbox="0 0 100% 100%">
<defs>
<filter id="smooth">
<feMorphology operator="dilate" radius="0" />
<feGaussianBlur stdDeviation="3" />
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer out="rounded1">
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComposite in2="rounded1" in="SourceGraphics" operator="in"/>
</filter>
</defs>
</svg>
and the explanations are here: https://dev.to/codingdudecom/css-smooth-font-edges-3pbb
One possible solution is using a goo filter like so. As an observation you need to know that for a different font and a different font-size you may need to change the values of the feColorMatrix and stdDeviation
div {
height: 200px;
padding:10px 60px;
font-size:200px;
font-family:Arial;
filter:url(#goo);
}
svg{position:absolute;}
<svg width="0" height="0">
<defs>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" stdDeviation="7" />
<feColorMatrix mode="matrix" values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 35 -7" />
<feBlend in="SourceGraphic" />
</filter>
</defs>
</svg>
<div>
<span>A B</span>
</div>
Please read about The Goeey Effect
I need to make a shadow for rect element for svg. The snippet below does the job, but I don't know how to control the color/opacity of the shadow? Any help will be appreciated!
<svg height="120" width="120">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="20" dy="20" />
<feBlend in="SourceGraphic" in2="offOut" mode="normal" />
</filter>
</defs>
<rect width="90" height="90" stroke="green" stroke-width="3" fill="yellow" filter="url(#f1)" />
Came across this w3schools page with similar examples. Based on the examples given there, it looks like you need to add few more filters (like feColorMatrix and feGaussianBlur) to bring the desired effect.
Your code with new filters:
<svg height="120" width="120">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="10" dy="10" />
<feColorMatrix result="matrixOut" in="offOut" type="matrix"
values="0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0" />
<feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="10" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" /> </filter>
</defs>
<rect width="90" height="90" stroke="green" stroke-width="3" fill="yellow" filter="url(#f1)" />
You can use this jsfiddle also.
Update:
We can achieve opacity & color change just with feColorMatrix filter. Check this updated jsFiddle.
But, in order achieve the desired color you need to understand more about setting values attribute of feColorMatrix.
Following links may be helpful:
Match colors in feColorMatrix filter
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix
SVG Drop Shadow - opacity, feOffset and viewBox difficulties
I have an svg image that works as a button. As you hover over the button the svg fill changes to a different color, but I also wish the inner shadow filter I created to appear as well. That is, to change from 0% opacity to 100%.
I was able to change the fill color with css transitions. Is it possible to change the opacity of the filter too with css?
Here's the SVG code:
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="36.25px" height="23px" viewBox="5 -5 36.25 23" enable-background="new 0 0 36.25 23" xml:space="preserve">
<!--Definiciones del Filtro-->
<filter id="sombra" x="-50%" y="-50%" width="200%" height="200%">
<feComponentTransfer in="SourceAlpha">
<feFuncA type="table" tableValues="1 0" />
</feComponentTransfer>
<feGaussianBlur stdDeviation="1"/>
<feOffset dx="-1" dy="-1" result="offsetblur"/>
<feFlood flood-color="rgb(20, 0, 0)" result="color"/>
<feComposite in2="offsetblur" operator="in"/>
<feComposite in2="SourceAlpha" operator="in" />
<feMerge>
<feMergeNode in="SourceGraphic" />
<feMergeNode />
</feMerge>
</filter>
<g filter="url(#sombra)">
<polygon points="23.671,8.625 23.671,4.657 21.786,4.657 21.786,7.513 18.255,5.433 18.194,5.398 18.058,5.398
4.724,13.249 5.502,14.57 7.862,13.179 7.862,18.343 9.396,18.343 9.396,12.276 18.128,7.138 26.854,12.276 26.854,18.343
28.388,18.343 28.388,13.179 30.75,14.57 31.526,13.249 "/>
<rect x="15.289" y="11.553" width="2.44" height="2.444"/>
<rect x="18.523" y="11.553" width="2.438" height="2.444"/>
<rect x="15.289" y="14.656" width="2.44" height="2.439"/>
<rect x="18.523" y="14.656" width="2.438" height="2.439"/>
</g>
</svg>
Here is the CSS:
#Capa_1{
fill:#FFFFFF;
-webkit-transition: fill 0.3s;
}
#Capa_1:hover{
fill:#8A653B;
}
Thanks in advance...!
After hours of searching somebody had already answered this question.
Here's the workaround:
Using CSS, is there a way to change the opacity of an SVG's <filter> element?
It works around pretty well on the current versions of Firefox and Chrome. SVG animations don't seem to work well in IE though, but the filter opacity did change however.
Thanks!
Yes MDN doc has a working draft of the animatable filter.
but not a lot of support is currently available :(
And on svg elements it only works in firefox.
Here is a fiddle for the fire fox users: Fiddle
Applying an svg filter: filter: url(#filterid)
Applying an svg opacity filter: filter: opacity(50%);
And combined: filter: url(#filterid) opacity(50%);