sorry if it has been already asked but I can't find the solution on how to apply a gradient color to a png logo. Here is the website i'm starting to work on: julienbraida.com.
White Logo is on top left. Client wants apply a gradient color on top of the branding logo and change the gradient color according to pages (to match the theme of the page).
I only was able to apply a color using a filter. But it's not a gradient color and I would need help to do that please.
I've done this:
.mobile-header-bar .mobile-branding img {
filter: sepia(100%) hue-rotate(19deg) saturate(100%);
}
But no gradient ... Thanks in advance for your help!
Set your image as a background:
NOTE:
filters apply to foreground elements, typically images.
Gradients are backgrounds and are effectively "under" images.
so if you want to apply a linear-gradient to an img you have to overlay the <img> with another element with a greater z-index
div {
height: 100px;
width: 150px;
display: inline-block;
}
.bgImageOnly {
background: url('https://picsum.photos/id/1/200/300') no-repeat;
}
.bgImgFilter {
filter: sepia(100%) hue-rotate(19deg) saturate(100%);
background: url('https://picsum.photos/id/1/200/300') no-repeat;
}
.bgImgGradient {
background: linear-gradient(135deg, rgba(255, 121, 0, .5) 0%, rgba(250, 0, 255, .5) 54%, rgba(126, 0, 255, .5) 100%), url('https://picsum.photos/id/1/200/300') no-repeat;
;
}
div.logos{
width: 100%;
overflow:hidden;
}
div.logos img{
height: 80px;
width: 150px;
}
img{
padding: 20px 0px;
}
.yourFilterParameters{
filter: brightness(1) invert(0) drop-shadow(0 1px 1px rgba(41, 55, 90, .4));
}
.somethingMoreVisible {
filter: brightness(70%) invert(30%) drop-shadow(4px 2px 2px rgba(255, 0, 0, 0.75))
}
div.gradientOverlay{
height: 80px;
width: 150px;
position:relative;
z-index:0;
}
div.gradientOverlay::after{
content:"";
position:absolute;
top:20px;
left:0px;
z-index: 1000;
height: 80px;
width: 150px;
background-image: linear-gradient(135deg, rgba(255, 121, 0, .5) 0%, rgba(250, 0, 255, .5) 54%, rgba(126, 0, 255, .5) 100%);
}
<div class="bgImageOnly"></div>
<div class="bgImgFilter"></div>
<div class="bgImgGradient"></div>
<hr>
<div class="logos">
<img src="https://picsum.photos/id/1/200/300"
class="yourFilterParameters">
<img src="https://picsum.photos/id/1/200/300"
class="somethingMoreVisible">
<div class="gradientOverlay">
<img src="https://picsum.photos/id/1/200/300">
</div>
</div>
Kiwi bird SVG (c)Chris Coyer # CSS-Tricks.com: see Using SVG
.logo {
width: 122px;
height: 100px;
}
.kiwi {
fill: url(#lgrad);
}
<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="612px" height="502.174px" viewBox="0 65.326 612 502.174" enable-background="new 0 65.326 612 502.174" xml:space="preserve"
class="logo">
<defs>
<linearGradient id="lgrad" x1="0%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" style="stop-color:rgb(255, 121, 0);stop-opacity:.5" />
<stop offset="50%" style="stop-color:rgb(250, 0, 255);stop-opacity:.5" />
<stop offset="100%" style="stop-color:rgb(126,0,155);stop-opacity:.5" />
</linearGradient>
</defs>
<ellipse class="ground" cx="283.5" cy="487.5" rx="259" ry="80"/>
<path class="kiwi" d="M210.333,65.331C104.367,66.105-12.349,150.637,1.056,276.449c4.303,40.393,18.533,63.704,52.171,79.03
c36.307,16.544,57.022,54.556,50.406,112.954c-9.935,4.88-17.405,11.031-19.132,20.015c7.531-0.17,14.943-0.312,22.59,4.341
c20.333,12.375,31.296,27.363,42.979,51.72c1.714,3.572,8.192,2.849,8.312-3.078c0.17-8.467-1.856-17.454-5.226-26.933
c-2.955-8.313,3.059-7.985,6.917-6.106c6.399,3.115,16.334,9.43,30.39,13.098c5.392,1.407,5.995-3.877,5.224-6.991
c-1.864-7.522-11.009-10.862-24.519-19.229c-4.82-2.984-0.927-9.736,5.168-8.351l20.234,2.415c3.359,0.763,4.555-6.114,0.882-7.875
c-14.198-6.804-28.897-10.098-53.864-7.799c-11.617-29.265-29.811-61.617-15.674-81.681c12.639-17.938,31.216-20.74,39.147,43.489
c-5.002,3.107-11.215,5.031-11.332,13.024c7.201-2.845,11.207-1.399,14.791,0c17.912,6.998,35.462,21.826,52.982,37.309
c3.739,3.303,8.413-1.718,6.991-6.034c-2.138-6.494-8.053-10.659-14.791-20.016c-3.239-4.495,5.03-7.045,10.886-6.876
c13.849,0.396,22.886,8.268,35.177,11.218c4.483,1.076,9.741-1.964,6.917-6.917c-3.472-6.085-13.015-9.124-19.18-13.413
c-4.357-3.029-3.025-7.132,2.697-6.602c3.905,0.361,8.478,2.271,13.908,1.767c9.946-0.925,7.717-7.169-0.883-9.566
c-19.036-5.304-39.891-6.311-61.665-5.225c-43.837-8.358-31.554-84.887,0-90.363c29.571-5.132,62.966-13.339,99.928-32.156
c32.668-5.429,64.835-12.446,92.939-33.85c48.106-14.469,111.903,16.113,204.241,149.695c3.926,5.681,15.819,9.94,9.524-6.351
c-15.893-41.125-68.176-93.328-92.13-132.085c-24.581-39.774-14.34-61.243-39.957-91.247
c-21.326-24.978-47.502-25.803-77.339-17.365c-23.461,6.634-39.234-7.117-52.98-31.273C318.42,87.525,265.838,64.927,210.333,65.331
z M445.731,203.01c6.12,0,11.112,4.919,11.112,11.038c0,6.119-4.994,11.111-11.112,11.111s-11.038-4.994-11.038-11.111
C434.693,207.929,439.613,203.01,445.731,203.01z"/>
</svg>
I would like to create a web page where the background is flat black but I need to add also a background pattern that should be visible only inside some shapes (circles in this simple example, but they will be a complicated path, different for each section).
I know I could assign the pattern to the shapes, but I need also to animate the shapes and is not possible to animate the pattern.
Here my starting code
I applied a texture in CSS to the entire page and I add some circles.
Now I need to "hide" the texture everywhere except inside the shapes. And the page background should be black.
How can I do that?
Is this the sort of thing you are after?
/* hide the SVG */
svg#pattern {
position: absolute;
left: -9999px;
}
body {
background-color: black;
height: 2000px;
color: white;
}
section {
height: 400px;
}
circle {
animation: throb 1s infinite;
}
#keyframes throb {
0% { r: 48px; }
50% { r: 30px; }
100% { r: 48px; }
}
<svg id="pattern">
<defs>
<pattern id="check" width="10" height="10" patternUnits="userSpaceOnUse">
<rect width="10" height="10" fill="linen"/>
<rect width="5" height="5" fill="black"/>
<rect x="5" y="5" width="5" height="5" fill="black"/>
</pattern>
</defs>
</svg>
<div>
<h1>Test page</h1>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
</div>
body {
background-color: black;
}
.container {
opacity: 0.8;
background-image: linear-gradient(135deg, black 25%, transparent 25%), linear-gradient(225deg, black 25%, transparent 25%), linear-gradient(45deg, black 25%, transparent 25%), linear-gradient(315deg, black 25%, #e5e5f7 25%);
background-position: 10px 0, 10px 0, 0 0, 0 0;
background-size: 10px 10px;
background-repeat: repeat;
width:200px;
height:200px;
}
<div class="container" style='clip-path: url("#test");'></div>
<svg x="0" y="0" width="0" height="0">
<clipPath id="test">
<circle cx="100" cy="100" r="20" fill="red"></circle>
</clipPath>
</svg>
I'm trying to use clip path but this is not working on firefox.
I already search about this and i found this code in stack overflow.
I have several shapes implemented but this is just work in chrome and safari.
.shape
{
width: 300px;
height: 300px;
display: inline-block;
position: relative;
box-sizing: border-box;
-webkit-clip-path: url(#clipper);
-moz-clip-path: url(#clipper);
clip-path: url(#clipper);
background-color: $page-title-background-green;
}
img
{
position: absolute;
top: 2px;
left: 2px;
width: 296px;
height: 296px;
-webkit-clip-path: url(#clipper);
-moz-clip-path: url(#clipper);
clip-path: url(#clipper);
}
<svg width="0" height="0">
<defs>
<clipPath id="clipper" clipPathUnits="objectBoundingBox">
<polygon points=".15 0, .7 0, 1 .5, .7 1, .15 1, 0 .7, .2 .5, 0 .3"/>
</clipPath>
</defs>
</svg>
<div class="shape">
<img src="http://lorempixel.com/g/600/400/">
</div>
How can i solve that?
Thank's
I have this code:
<body>
<svg class="svg-defs">
<defs>
<clipPath id="clipping">
<polygon points="98.4999978 153.75 38.2520165 185.424245 49.7583542 118.337123 1.01670635 70.8257603 68.3760155 61.037872 98.5000012 1.1379786e-14 128.624005 61.0378871 195.98331 70.8258091 147.241642 118.337136 158.747982 185.424247"></polygon>
</clipPath>
</defs>
</svg>
<svg width="200" height="300">
<style type="text/css" media="screen">
image {
clip-path: url(#clipping);
}
</style>
<image xlink:href="http://img-fotki.yandex.ru/get/5607/5091629.6b/0_612e6_b9039c0d_M.jpg" width="200" height="300" />
</svg>
</body>
So, try to set the style inside your SVG element, or give a style attribute to image, like this:
<image style="clip-path: url(#clipping);" xlink:href="...">
I have a problem with CSS3. I don't know how to make a diagonal round gradient border like that:
I found something like this:
.box {
width: 250px;
height: 250px;
margin: auto;
background: #eee;
border: 20px solid transparent;
-moz-border-image: -moz-linear-gradient(top left, #3acfd5 0%, #3a4ed5 100%);
-webkit-border-image: -webkit-linear-gradient(top left, #3acfd5 0%, #3a4ed5 100%);
border-image: linear-gradient(to bottom right, #3acfd5 0%, #3a4ed5 100%);
border-image-slice: 1;
}
<div class="box"></div>
But unfortunately this works only with squares.
Any help would be appreciated.
Conical gradient is a gradient which goes along the circular arc around a center. This is what we see in color wheels. As Paulie_D had noted, these are currently not possible with CSS but Lea Verou has developed a polyfill for it.
Having said that, what you are looking for doesn't seem to be a conical gradient, it is normal angled linear gradient but applied only to the borders.
This cannot be achieved through CSS border-image property because of how it is intended to work as per specs.
A box's backgrounds, but not its border-image, are clipped to the appropriate curve
If the center portion of the circle is a solid color then the approach mentioned in Vitorino's answer can be used. If it is not a solid color (that is, the page background is a gradient or an image which needs to show through) then it would not help. The following approaches can be used for that case.
Using Mask Image:
This approach uses a circular mask image to mask the inner portion of the circle. This makes it look as though only the border has the gradient applied to it. The drawback is that this feature is currently supported only in Webkit powered browsers.
.border-gradient-mask {
height: 200px;
width: 200px;
border-radius: 50%;
background-image: linear-gradient(to bottom left, #7B73A4 0%, #150E5E 100%);
-webkit-mask-image: radial-gradient(circle at center, transparent 57%, white 58%);
mask-image: radial-gradient(circle at center, transparent 57%, white 58%);
}
body {
background: radial-gradient(circle at center, sandybrown, chocolate);
}
<div class="border-gradient-mask"></div>
Using SVG Shape or Mask:
The other approach is to use SVG circle element to create the circle and then assign the gradient to the stroke property. The gradient also has a gradientTransform applied to it because that is the only way to produce angled linear gradients with SVG.
.border-gradient-svg {
position: relative;
height: 200px;
width: 200px;
border-radius: 50%;
}
.border-gradient-svg svg {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
.border-gradient-svg circle {
fill: transparent;
stroke: url(#grad);
stroke-width: 8;
}
body {
background: radial-gradient(circle at center, sandybrown, chocolate);
}
<div class="border-gradient-svg">
<svg viewBox="0 0 100 100">
<defs>
<linearGradient id="grad" gradientUnits="objectBoundingBox" gradientTransform="rotate(135 0.5 0.5)">
<stop offset="0%" stop-color="#7B73A4" />
<stop offset="100%" stop-color="#150E5E" />
</linearGradient>
</defs>
<circle r="46" cx="50" cy="50" />
</svg>
</div>
The same can be achieved by using SVG mask also. All that is needed is to create a mask with two circle elements, fill the larger circle with white, smaller circle with black and then apply the mask to our original circle element. The area occupied by smaller circle (with black fill) will be transparent.
.border-gradient-svg {
position: relative;
height: 200px;
width: 200px;
border-radius: 50%;
}
.border-gradient-svg svg {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
.border-gradient-svg .grad-border {
fill: url(#grad);
mask: url(#masker);
}
body {
background: radial-gradient(circle at center, sandybrown, chocolate);
}
<div class="border-gradient-svg">
<svg viewBox="0 0 100 100">
<defs>
<linearGradient id="grad" gradientUnits="objectBoundingBox" gradientTransform="rotate(135 0.5 0.5)">
<stop offset="0%" stop-color="#7B73A4" />
<stop offset="100%" stop-color="#150E5E" />
</linearGradient>
<mask id="masker" x="0" y="0" width="100" height="100">
<circle r="50" cx="50" cy="50" fill="#fff" />
<circle r="42" cx="50" cy="50" fill="#000" />
</mask>
</defs>
<circle r="50" cx="50" cy="50" class="grad-border"/>
</svg>
</div>
Using Clip Path:
Another approach to creating this would be to use a clip-path (with inline SVG) with clip-rule set to evenodd. Advantage of clip path solution over the others is that this will trigger hover effects only while hovering on filled area (and not the transparent area). The drawback is that IE doesn't support clip paths (even with SVG).
.border-gradient-clip {
height: 200px;
width: 200px;
border-radius: 50%;
background-image: linear-gradient(to bottom left, #7B73A4 0%, #150E5E 100%);
-webkit-clip-path: url(#clipper);
clip-path: url(#clipper);
}
body {
background: radial-gradient(circle at center, sandybrown, chocolate);
}
<svg width="0" height="0">
<defs>
<clipPath id="clipper" clipPathUnits="objectBoundingBox">
<path d="M0,0.5 a0.5,0.5 0 1,0 1,0 a0.5,0.5 0 1,0 -1,0z M0.08,0.5 a0.42,0.42 0 1,0 0.84,0 a0.42,0.42 0 1,0 -0.84,0z" clip-rule="evenodd" />
</clipPath>
</defs>
</svg>
<div class="border-gradient-clip"></div>
You can try something like this i have used a pseudo element with -ve z-index
Note: the background is not transparent as i have used a background-color for inner element
.box {
width: 250px;
height: 250px;
position: relative;
margin: auto;
margin: 30px;
border-radius: 50%;
background: #fff;
}
.box:after {
content: '';
position: absolute;
top: -15px;
bottom: -15px;
right: -15px;
left: -15px;
background-image: linear-gradient(to bottom left, #7B73A4 0%, #150E5E 100%);
z-index: -1;
border-radius: inherit;
}
<div class="box"></div>
Can you CSS Blur based on a gradient mask?
Something similar to this effect, http://www.imagemagick.org/Usage/mapping/#blur?
This can help you http://codepen.io/iamvdo/pen/xECmI
.effet{
width: 400px; height: 300px;
margin: 0 auto 50px auto;
box-shadow: 0 1px 5px rgba(0,0,0,.5);
}
.effet img{
position: absolute;
}
.filtre--r{
-webkit-mask: -webkit-radial-gradient( center, closest-side, transparent 30%, black 80%);
-webkit-mask: radial-gradient( closest-side at center, transparent 50%, black 110%);
-webkit-filter: blur(5px);
mask: url('#mask-radial');
filter: url('#filtre1');
}
.filtre--l{
-webkit-mask: -webkit-linear-gradient(black, transparent 30%, black);
-webkit-mask: linear-gradient(black, transparent 30%, black);
-webkit-filter: blur(3px);
mask: url('#mask-linear');
filter: url('#filtre2');
}
.filtre:hover{
-webkit-mask: none;
-webkit-filter: none;
mask: none;
filter: none;
}
p{
text-align: center;
color: rgba(0,0,0,.6);
margin: 1em;
}
p a{
color: rgba(0,0,0,.6);
}
<p><strong>Radial</strong> progressive blur</p>
<div class="effet">
<img src="http://css3create.com/squelettes/images/articles/flou-localise-1.jpg" alt="" />
<img class="filtre filtre--r" src="http://css3create.com/squelettes/images/articles/flou-localise-1.jpg" alt="" />
</div>
<p><strong>Linear</strong> progressive blur</p>
<div class="effet">
<img src="http://css3create.com/squelettes/images/articles/flou-localise-2.jpg" alt="" />
<img class="filtre filtre--l" src="http://css3create.com/squelettes/images/articles/flou-localise-2.jpg" alt="" />
</div>
<p>Hover over images to see without blur</p>
<p>Next demo: iOS 7 background blur with CSS</p>
<svg height="0">
<defs>
<mask id="mask-radial">
<rect width="400" height="300" fill="url(#g1)"></rect>
<radialGradient id="g1" cx="50%" cy="50%" r="50%">
<stop stop-color="black" offset="50%"/>
<stop stop-color="white" offset="110%"/>
</radialGradient>
</mask>
<mask id="mask-linear">
<rect width="400" height="300" fill="url(#l1)"></rect>
<linearGradient id="l1" x1="0" y1="0" x2="0" y2="1">
<stop stop-color="white" offset="0%"/>
<stop stop-color="black" offset="30%"/>
<stop stop-color="white" offset="100%"/>
</linearGradient>
</mask>
<filter id="filtre1">
<feGaussianBlur in="SourceGraphic" stdDeviation="5"/>
</filter>
<filter id="filtre2">
<feGaussianBlur in="SourceGraphic" stdDeviation="3"/>
</filter>
</defs>
</svg>
[EDIT] As of October 2022, it is now possible in all the modern browsers.
Yes you can, but at the moment the backdrop blur is not supported on all the browsers.
Here is a simple example working on Chrome and Safari but not Firefox (because of the lack of backdrop-filter support).
https://codepen.io/antoniandre/pen/vYpWQXd?editors=0100
* {margin: 0}
body {
height: 100vh;
background-image: url("https://images.unsplash.com/photo-1501854140801-50d01698950b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2600&q=80");
background-size: cover;
&:after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
backdrop-filter: blur(20px);
mask: linear-gradient(transparent, black 60%);
transition: 1s;
}
&:hover:after {opacity: 1;}
}
You might nowadays simply use:
backdrop-filter: blur(4px)
All modern browsers except Firefox support it.