Related
I'm trying to make a gradient overlay in my images, that makes this effect:
As you can see, gradient will be darker at the bottom, BUT, the top WONT be affected by the darkness.
I've tried this:
#include linear-gradient(to top, rgba(0,0,0,0.4) 0%, rgba(255,255,255,1));
But this will make a whitish effect at the top. I want the gradient to darken only the bottom part of the image, and DON'T do anything to the upper part of the image.
Has anyone know how to do this?
Thanks
You can use the following CSS, http://jsfiddle.net/3sxd82nf/5/
<div id="test">x</div>
<div id="gradient"></div>
#test {
position:absolute;
top: 10px;
left: 0px;
width: 200px;
height: 200px;
background-image: url('http://images2.layoutsparks.com/1/198321/50s-diner-chick-squares.jpg');
}
#gradient {
position:absolute;
top: 10px;
left: 0px;
width: 200px;
height: 200px;
background: -moz-linear-gradient(top, rgba(0,0,0,0) 50%, rgba(0,0,0,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
}
This used to work fine, however recently the gradient doesn't work properly in Webkit. Seems to be fine in Firefox. Can someone check if I'm setting something incorrectly. Don't pay attention to the images. Its the gradient I can't get to render. Any ideas please?
JSFIDDLE: http://jsfiddle.net/UdxUg/2/
-webkit-gradient
It's due to the old syntax, generally webkit/blink now allows using a vendor-less value.
Generally you should use a :pseudo-element --> http://jsfiddle.net/UdxUg/6/
anyways here's a code that works.
works with image
.create {
border: 1px solid #63ac5c;
background: #d9ead8 url('http://tinyurl.com/mezxsk6') no-repeat 0px -10px;
background: url('http://tinyurl.com/mezxsk6') no-repeat 0px -10px, -webkit-gradient(linear, left top, left bottom, color-stop(0%, #dbe8d9), color-stop(100%, #bcd7b9));
/* Safari 4+, Chrome 2+ */
background: url('http://tinyurl.com/mezxsk6') no-repeat 0px -10px, -moz-linear-gradient(top, #dbe8d9, #bcd7b9);
background: url('http://tinyurl.com/mezxsk6') no-repeat 0px -10px, -webkit-linear-gradient(top, #dbe8d9, #bcd7b9);
background: url('http://tinyurl.com/mezxsk6') no-repeat 0px -10px, linear-gradient(top, #dbe8d9, #bcd7b9);
height: 23px;
text-align:center;
}
use this instead though
.create {
border: 1px solid #63ac5c;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #dbe8d9), color-stop(100%, #bcd7b9)); /* Safari 4+, Chrome 2+ */
background: -webkit-linear-gradient(top, #dbe8d9, #bcd7b9);
background: -moz-linear-gradient(top, #dbe8d9, #bcd7b9);
background: linear-gradient(top, #dbe8d9, #bcd7b9);
height: 23px;
text-align:center;
position: relative
}
.create:before {
content: '';
background: #d9ead8 url('http://tinyurl.com/mezxsk6') no-repeat 0 0;
height: 23px;
width: 23px;
position: absolute;
top: 0;
left: 0;
}
Check this I always use this generator to generate gradients, it is faster and it is good.
CSS3 Ultimate Gradient Generator
BTW if you remove that images the gradient works just fine in webkit.
Check on jsFiddle
.create {
border: 1px solid #63ac5c;
background: rgb(188,215,185); /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIyNCUiIHN0b3AtY29sb3I9IiNiY2Q3YjkiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSI5OSUiIHN0b3AtY29sb3I9IiNkYmU4ZDkiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(188,215,185,1) 24%, rgba(219,232,217,1) 99%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(24%,rgba(188,215,185,1)), color-stop(99%,rgba(219,232,217,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(188,215,185,1) 24%,rgba(219,232,217,1) 99%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(188,215,185,1) 24%,rgba(219,232,217,1) 99%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(188,215,185,1) 24%,rgba(219,232,217,1) 99%); /* IE10+ */
background: linear-gradient(to bottom, rgba(188,215,185,1) 24%,rgba(219,232,217,1) 99%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bcd7b9', endColorstr='#dbe8d9',GradientType=0 ); /* IE6-8 */
height: 23px;
text-align:center;
}
How could one go about dynamically generating a shape like this in CSS3:
Ignore the borders, as the important aspects are:
- The gradient in the arrow body, and that the gradient lasts from the tip to the end of the arrow.
- The length of the square part will vary.
I tried the regular :after method of adding a triangle to the end of a div element, but I couldn’t get the gradient to span both the tip and the body properly.
Fiddle: http://jsfiddle.net/rtuY9/8/
You can try something like this - DEMO
div {
width: 50px;
height: 100px;
position: relative;
margin: 100px;
background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 100%);
background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 100%);
}
div:after {
z-index: -1;
content: "";
display: block;
position: absolute;
left: -125px;
top: -51px;
margin: 100px;
height: 100px;
width: 100px;
background: #c00;
-webkit-transform:rotate( -45deg );
-moz-transform:rotate( -45deg );
transform:rotate( -45deg );
background: -webkit-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
background: -moz-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
}
I'm generating a bar of horizontal gradient as a background across my site that works perfectly in every browser except...IE9.
The gradient itself is working, it is just that I want to limit the height of the blue bar. Check it out in Safari/Firefox/Chrome and then in IE9 and you can see that the blue gradient fills the entire element.
Horizontal gradient bar using CSS
Here is my CSS:
#inner {
background: #1e5799;
background: -moz-linear-gradient(top, #1e5799 0%, #0057be 35%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(35%,#0057be));
background: -webkit-linear-gradient(top, #1e5799 0%,#0057be 35%);
background: -o-linear-gradient(top, #1e5799 0%,#0057be 35%);
background: -ms-linear-gradient(top, #1e5799 0%,#0057be 35%);
background: linear-gradient(to bottom, #1e5799 0%,#0057be 35%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#0057be',GradientType=0 );
background-size: 1px 10%;
background-repeat: repeat-x;
margin: 0 auto;
padding: 1em 0;
}
This code should work on IE9:
background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZzEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjMWU1Nzk5Ii8+PHN0b3Agb2Zmc2V0PSIwLjM1IiBzdG9wLWNvbG9yPSIjMDA1N2JlIi8+PC9saW5lYXJHcmFkaWVudD48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2cxKSIgLz48L3N2Zz4=);
I made it with Visual CSS Gradient Generator
Updated CSS:
#inner {
background: #1e5799;
background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZzEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjMWU1Nzk5Ii8+PHN0b3Agb2Zmc2V0PSIwLjM1IiBzdG9wLWNvbG9yPSIjMDA1N2JlIi8+PC9saW5lYXJHcmFkaWVudD48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2cxKSIgLz48L3N2Zz4=);
background: -webkit-gradient(linear, center top, center bottom, color-stop(0%, #1e5799), color-stop(35%, #0057be));
background: -webkit-linear-gradient(top, #1e5799 0%, #0057be 35%);
background: -moz-linear-gradient(top, #1e5799 0%, #0057be 35%);
background: -ms-linear-gradient(top, #1e5799 0%, #0057be 35%);
background: -o-linear-gradient(top, #1e5799 0%, #0057be 35%);
background: linear-gradient(to bottom, #1e5799 0%, #0057be 35%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#0057be',GradientType=0 );
background-size: 1px 10%;
background-repeat: repeat-x;
margin: 0 auto;
padding: 1em 0;
}
IE9 doesn't support CSS3 gradients, but it supports inline SVG. I don't recommend to mix up filter and SVG backgrounds on IE9, i think the best approach is to use conditional comments as explained in this article by Paul Irish.
I'm trying to style my HTML buttons using CSS, so that they have the reflected shine like the icons on iOS devices' home page. Apple does this to icons automatically as shown here. I need something similar to the shine in CSS.
Take a look at this fiddle.
Here's the code:
HTML:
<div class="icon">
<div class="shine"></div>
</div>
And CSS:
.icon {
width: 150px;
height: 150px;
border-radius: 30px;
background: red;
float: left;
margin: 50px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.5);
}
.shine {
background: -moz-linear-gradient(top, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0.2) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.7)), color-stop(100%,rgba(255,255,255,0.2))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* IE10+ */
background: linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b3ffffff', endColorstr='#33ffffff',GradientType=0 ); /* IE6-9 */
height: 90px;
width: 150px;
box-shadow: inset 0px 2px 1px rgba(255, 255, 255, 0.7);
border-top-right-radius: 30px;
border-top-left-radius: 30px;
border-bottom-right-radius: 100px 40px;
border-bottom-left-radius: 100px 40px;
}
my example uses a background-color:red instead of an image, but just put any image as background in the #icon div and it should also work.
(btw I used this awesome site: http://www.colorzilla.com/gradient-editor/ for the gradients)
HTML:
<div class="icon">
<div class="shine">
</div>
</div>
CSS:
.icon {
width:50px;
height:50px;
background-color: red;
overflow: hidden;
position: relative;
}
.shine {
position: absolute;
top: -70px;
left: -25px;
width:100px;
height:100px;
border-radius: 50px;
background: -webkit-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* Chrome10+,Safari5.1+ */
background: -moz-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 150%); /* FF3.6+ */
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(255,255,255,1.5)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -o-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* Opera 12+ */
background: -ms-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* IE10+ */
background: radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
Hope it works for you!