How to fill a fontawesome icon with a background on hover? [duplicate] - css

Is there a generator , or an easy way to generate text like this but without having to define every letter
So something like this:
.rainbow {
background-image: -webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
background-image: gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
color:transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="rainbow">Rainbow text</span>
But not with rainbow colors but generate with other colors (for example white to grey/light blue gradient etc) I can't find an easy solution for this. Any solutions?

I don't exactly know how the stop stuff works.
But I've got a gradient text example. Maybe this will help you out!
_you can also add more colors to the gradient if you want or just select other colors from the color generator
.rainbow2 {
background-image: linear-gradient(to right, #E0F8F7, #585858, #fff);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
.rainbow {
background-image: linear-gradient(to right, #f22, #f2f, #22f, #2ff, #2f2, #ff2);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="rainbow">Rainbow text</span>
<br />
<span class="rainbow2">No rainbow text</span>

The way this effect works is very simple. The element is given a background which is the gradient. It goes from one color to another depending on the colors and color-stop percentages given for it.
For example, in rainbow text sample (note that I've converted the gradient into the standard syntax):
The gradient starts at color #f22 at 0% (that is the left edge of the element). First color is always assumed to start at 0% even though the percentage is not mentioned explicitly.
Between 0% to 14.25%, the color changes from #f22 to #f2f gradually. The percenatge is set at 14.25 because there are seven color changes and we are looking for equal splits.
At 14.25% (of the container's size), the color will exactly be #f2f as per the gradient specified.
Similarly the colors change from one to another depending on the bands specified by color stop percentages. Each band should be a step of 14.25%.
So, we end up getting a gradient like in the below snippet. Now this alone would mean the background applies to the entire element and not just the text.
.rainbow {
background-image: linear-gradient(to right, #f22, #f2f 14.25%, #22f 28.5%, #2ff 42.75%, #2f2 57%, #2f2 71.25%, #ff2 85.5%, #f22);
color: transparent;
}
<span class="rainbow">Rainbow text</span>
Since, the gradient needs to be applied only to the text and not to the element on the whole, we need to instruct the browser to clip the background from the areas outside the text. This is done by setting background-clip: text.
(Note that the background-clip: text is an experimental property and is not supported widely.)
Now if you want the text to have a simple 3 color gradient (that is, say from red - orange - brown), we just need to change the linear-gradient specification as follows:
First parameter is the direction of the gradient. If the color should be red at left side and brown at the right side then use the direction as to right. If it should be red at right and brown at left then give the direction as to left.
Next step is to define the colors of the gradient. Since our gradient should start as red on the left side, just specify red as the first color (percentage is assumed to be 0%).
Now, since we have two color changes (red - orange and orange - brown), the percentages must be set as 100 / 2 for equal splits. If equal splits are not required, we can assign the percentages as we wish.
So at 50% the color should be orange and then the final color would be brown. The position of the final color is always assumed to be at 100%.
Thus the gradient's specification should read as follows:
background-image: linear-gradient(to right, red, orange 50%, brown).
If we form the gradients using the above mentioned method and apply them to the element, we can get the required effect.
.red-orange-brown {
background-image: linear-gradient(to right, red, orange 50%, brown);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
.green-yellowgreen-yellow-gold {
background-image: linear-gradient(to right, green, yellowgreen 33%, yellow 66%, gold);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="red-orange-brown">Red to Orange to Brown</span>
<br>
<span class="green-yellowgreen-yellow-gold">Green to Yellow-green to Yellow to Gold</span>

You can achieve that effect using a combination of CSS linear-gradient and mix-blend-mode.
HTML
<p>
Enter your message here...
To be or not to be,
that is the question...
maybe, I think,
I'm not sure
wait, you're still reading this?
Type a good message already!
</p>
CSS
p {
width: 300px;
position: relative;
}
p::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(45deg, red, orange, yellow, green, blue, purple);
mix-blend-mode: screen;
}
What this does is add a linear gradient on the paragraph's ::after pseudo-element and make it cover the whole paragraph element. But with mix-blend-mode: screen, the gradient will only show on parts where there is text.
Here's a jsfiddle to show this at work. Just modify the linear-gradient values to achieve what you want.

Example of CSS Text Gradient
background-image: -moz-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -webkit-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -o-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -ms-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: linear-gradient(top,#E605C1 0%,#3B113B 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position:relative;
display:inline-block; /*required*/
Online generator
textgradient.com

body{ background:#3F5261; text-align:center; font-family:Arial; }
h1 {
font-size:3em;
background: -webkit-linear-gradient(top, gold, white);
background: linear-gradient(top, gold, white);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position:relative;
margin:0;
z-index:1;
}
div{ display:inline-block; position:relative; }
div::before{
content:attr(data-title);
font-size:3em;
font-weight:bold;
position:absolute;
top:0; left:0;
z-index:-1;
color:black;
z-index:1;
filter:blur(5px);
}
<div data-title='SOME TITLE'>
<h1>SOME TITLE</h1>
</div>

.gradient_text_class{
font-size: 72px;
background: linear-gradient(to right, #ffff00 0%, #0000FF 30%);
background-image: linear-gradient(to right, #ffff00 0%, #0000FF 30%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div class="gradient_text_class">Hello</div>

#import url(https://fonts.googleapis.com/css?family=Roboto+Slab:400);
body {
background: #222;
}
h1 {
display: table;
margin: 0 auto;
font-family: "Roboto Slab";
font-weight: 600;
font-size: 7em;
background: linear-gradient(330deg, #e05252 0%, #99e052 25%, #52e0e0 50%, #9952e0 75%, #e05252 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
line-height: 200px;
}
<h1>beautiful</h1>

Related

Placing a gradient background on an image with transparent background

What I would like to achieve is basically have a gradient appear on the text as opposed to the background of an image. I have created an example here:
https://codepen.io/BenSagiStuff/pen/BaYKbNj
body{
background: black;
}
img{
padding: 30px;
background: linear-gradient(to right, #E50000 8%, #FF8D00 28%, #FFEE00 49%, #008121 65%, #004CFF 81%, #760188 100%);
}
<img src="https://upload.wikimedia.org/wikipedia/commons/9/95/Transparent_google_logo_2015.png" >
As you can see, currently the background of the image has the gradient, but, what I would like is for the text "Google" to have the gradient and the background of the png should stay as black.
Ultimately the goal would be to have the gradient transition underneath the image as well, so the gradient slides horizontally under the image as well.
Use the image as a mask on a common element
body{
background: black;
}
.box{
--img:url(https://upload.wikimedia.org/wikipedia/commons/9/95/Transparent_google_logo_2015.png);
width:300px;
aspect-ratio:3;
background: linear-gradient(to right, #E50000 8%, #FF8D00 28%, #FFEE00 49%, #008121 65%, #004CFF 81%, #760188 100%);
-webkit-mask: var(--img) 50%/cover;
mask: var(--img) 50%/cover;
}
<div class="box"></div>
There's a little problem with your implementation.
PNG is transparent, but it's a square piece of image. You might be successful using a svg image or just applying this gradient background in a text tag.
on your HTML you make this way:
<div>
<h1>Google</h1>
</div>
Your CSS this way
body{
background: black;
font-family:helvetica;
}
h1{
background: linear-gradient(to right, #E50000 8%, #FF8D00 28%, #FFEE00 49%, #008121 65%, #004CFF 81%, #760188 100%);
font-size: 160px;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
div {
display:flex;
}
It's also better for performance.
Also, you can animate easily.
Such as the example in this codepen https://codepen.io/shshaw/pen/YpERQQ
:)

Linear gradient with multiple backgrounds

What is the syntax for a linear gradient with multiple backgrounds? My code just produces the yellow instead of a graduation from yellow to pink?
background-color: rgba(red,1);
background:
url(/src/stat/chevronRight.svg) 90% 45% no-repeat,
linear-gradient(to bottom, rgba(yellow,1) 0%, rgba(pink,1) 100%);
background-size: 7px;
Many thanks
Martin
You can set color as word yellow or you can use RGB, RGBA or Hexadecimal color values.
div {
height: 100vh;
background: url('http://placehold.it/150x150'), linear-gradient(to bottom, yellow, pink);
background-repeat: no-repeat;
}
<div></div>

Gradient text color

Is there a generator , or an easy way to generate text like this but without having to define every letter
So something like this:
.rainbow {
background-image: -webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
background-image: gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
color:transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="rainbow">Rainbow text</span>
But not with rainbow colors but generate with other colors (for example white to grey/light blue gradient etc) I can't find an easy solution for this. Any solutions?
I don't exactly know how the stop stuff works.
But I've got a gradient text example. Maybe this will help you out!
_you can also add more colors to the gradient if you want or just select other colors from the color generator
.rainbow2 {
background-image: linear-gradient(to right, #E0F8F7, #585858, #fff);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
.rainbow {
background-image: linear-gradient(to right, #f22, #f2f, #22f, #2ff, #2f2, #ff2);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="rainbow">Rainbow text</span>
<br />
<span class="rainbow2">No rainbow text</span>
The way this effect works is very simple. The element is given a background which is the gradient. It goes from one color to another depending on the colors and color-stop percentages given for it.
For example, in rainbow text sample (note that I've converted the gradient into the standard syntax):
The gradient starts at color #f22 at 0% (that is the left edge of the element). First color is always assumed to start at 0% even though the percentage is not mentioned explicitly.
Between 0% to 14.25%, the color changes from #f22 to #f2f gradually. The percenatge is set at 14.25 because there are seven color changes and we are looking for equal splits.
At 14.25% (of the container's size), the color will exactly be #f2f as per the gradient specified.
Similarly the colors change from one to another depending on the bands specified by color stop percentages. Each band should be a step of 14.25%.
So, we end up getting a gradient like in the below snippet. Now this alone would mean the background applies to the entire element and not just the text.
.rainbow {
background-image: linear-gradient(to right, #f22, #f2f 14.25%, #22f 28.5%, #2ff 42.75%, #2f2 57%, #2f2 71.25%, #ff2 85.5%, #f22);
color: transparent;
}
<span class="rainbow">Rainbow text</span>
Since, the gradient needs to be applied only to the text and not to the element on the whole, we need to instruct the browser to clip the background from the areas outside the text. This is done by setting background-clip: text.
(Note that the background-clip: text is an experimental property and is not supported widely.)
Now if you want the text to have a simple 3 color gradient (that is, say from red - orange - brown), we just need to change the linear-gradient specification as follows:
First parameter is the direction of the gradient. If the color should be red at left side and brown at the right side then use the direction as to right. If it should be red at right and brown at left then give the direction as to left.
Next step is to define the colors of the gradient. Since our gradient should start as red on the left side, just specify red as the first color (percentage is assumed to be 0%).
Now, since we have two color changes (red - orange and orange - brown), the percentages must be set as 100 / 2 for equal splits. If equal splits are not required, we can assign the percentages as we wish.
So at 50% the color should be orange and then the final color would be brown. The position of the final color is always assumed to be at 100%.
Thus the gradient's specification should read as follows:
background-image: linear-gradient(to right, red, orange 50%, brown).
If we form the gradients using the above mentioned method and apply them to the element, we can get the required effect.
.red-orange-brown {
background-image: linear-gradient(to right, red, orange 50%, brown);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
.green-yellowgreen-yellow-gold {
background-image: linear-gradient(to right, green, yellowgreen 33%, yellow 66%, gold);
color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
<span class="red-orange-brown">Red to Orange to Brown</span>
<br>
<span class="green-yellowgreen-yellow-gold">Green to Yellow-green to Yellow to Gold</span>
You can achieve that effect using a combination of CSS linear-gradient and mix-blend-mode.
HTML
<p>
Enter your message here...
To be or not to be,
that is the question...
maybe, I think,
I'm not sure
wait, you're still reading this?
Type a good message already!
</p>
CSS
p {
width: 300px;
position: relative;
}
p::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(45deg, red, orange, yellow, green, blue, purple);
mix-blend-mode: screen;
}
What this does is add a linear gradient on the paragraph's ::after pseudo-element and make it cover the whole paragraph element. But with mix-blend-mode: screen, the gradient will only show on parts where there is text.
Here's a jsfiddle to show this at work. Just modify the linear-gradient values to achieve what you want.
Example of CSS Text Gradient
background-image: -moz-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -webkit-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -o-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: -ms-linear-gradient(top,#E605C1 0%,#3B113B 100%);
background-image: linear-gradient(top,#E605C1 0%,#3B113B 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position:relative;
display:inline-block; /*required*/
Online generator
textgradient.com
body{ background:#3F5261; text-align:center; font-family:Arial; }
h1 {
font-size:3em;
background: -webkit-linear-gradient(top, gold, white);
background: linear-gradient(top, gold, white);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position:relative;
margin:0;
z-index:1;
}
div{ display:inline-block; position:relative; }
div::before{
content:attr(data-title);
font-size:3em;
font-weight:bold;
position:absolute;
top:0; left:0;
z-index:-1;
color:black;
z-index:1;
filter:blur(5px);
}
<div data-title='SOME TITLE'>
<h1>SOME TITLE</h1>
</div>
.gradient_text_class{
font-size: 72px;
background: linear-gradient(to right, #ffff00 0%, #0000FF 30%);
background-image: linear-gradient(to right, #ffff00 0%, #0000FF 30%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div class="gradient_text_class">Hello</div>
#import url(https://fonts.googleapis.com/css?family=Roboto+Slab:400);
body {
background: #222;
}
h1 {
display: table;
margin: 0 auto;
font-family: "Roboto Slab";
font-weight: 600;
font-size: 7em;
background: linear-gradient(330deg, #e05252 0%, #99e052 25%, #52e0e0 50%, #9952e0 75%, #e05252 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
line-height: 200px;
}
<h1>beautiful</h1>

CSS dynamic Text gradient

I Want to Gradient Some Text, I done it Using Following Code.
The Problem is,
It works on Chrome,But didn't work on Internet Explorer
Another thing it applies horizontally
I want it Vertically, More specifically in 45 Angle position, center focused or Circular Gradient
Style Sheet:
<style>
h1 {
font-size: 60px;
background: -webkit-linear-gradient(RED, GREEN, BLUE);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
p {
font-size: 18px;
background: -webkit-linear-gradient(RED, GREEN, BLUE);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
Tags:
<h1>I Want Gradient</h1>
<p>I want to apply Some Gradient<br/>ON Given Paragraph With<br/>Different angles and<br/>With Different Styles</p>
Result on Chrome:
Result on IE:
Please help me, Thanks,
Here's 45 degree angle gradient: http://jsfiddle.net/swm53ran/75/
.grad1 {
display:inline-block;
background: -webkit-linear-gradient(45deg,red,yellow,green);
background: linear-gradient(45deg,red,yellow,green);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Heres a Circle Gradient example: http://jsfiddle.net/swm53ran/74/
<div>
<h1 class="grad1">I Want Gradient</h1>
<br/>
<p class="grad1">I want to apply Some Gradient<br/>ON Given Paragraph With<br/>Different angles and<br/>With Different Styles</p>
</div>
.grad1 {
display:inline-block;
background: -webkit-radial-gradient(red 5%, green 15%, blue 60%); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(red 5%, green 15%, blue 60%); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(red 5%, green 15%, blue 60%); /* For Firefox 3.6 to 15 */
background: radial-gradient(red 5%, green 15%, blue 60%); /* Standard syntax (must be last) */
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

CSS tricks: underline with alpha-gradient on both ends

I need to underline my elements (menu items) with a line which has an gradient on BOTH ends.
It can't simply be a graphic (even stretched one), since the width of elements may vary significantly.
The desired effect:
What I did, was to create a line, 1000px wide, with gradient on both ends, then append following HTML <div><div class="right"> </div></div> to every element to be underlined.
The CSS is following
#navmenu li div
{
height: 1px;
background-image: url('images/1000glight.png');
background-repeat: no-repeat;
}
#navmenu li div.right
{
width:35px;
float: right;
background-position: -965px 0;
background-image: url('images/1000glight.png');
background-color: #212121;
}
This however is not truly alpha. I need to specify the background color of "right-side" div in order to "cover" the image (1000px line) which is below.
Any ideas how could I improve it, keeping pure CSS?
Using an approach similar to this, with the gradient being the background image of a wrapping div with padding-bottom to show only the lower part of the background:
<div class="wrap">
<div class="content">Some Text!</div>
</div>
And CSS:
.wrap {
float: left;
padding-bottom: 5px;
/* IE10 */
background-image: -ms-linear-gradient(right, #fff 0%, #000 25%, #000 75%, #fff 100%);
/* Mozilla Firefox */
background-image: -moz-linear-gradient(right, #fff 0%, #000 25%, #000 75%, #fff 100%);
/* Opera */
background-image: -o-linear-gradient(right, #fff 0%, #000 25%, #000 75%, #fff 100%);
/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, right top, left top, color-stop(0, #fff), color-stop(0.25, #000), color-stop(0.75, #000), color-stop(1, #fff));
/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(right, #fff 0%, #000 25%, #000 75%, #fff 100%);
/* Proposed W3C Markup */
background-image: linear-gradient(right, #fff 0%, #000 25%, #000 75%, #fff 100%);
}
.content {
background-color: #fff;
}
Works, but does omit IE<10; which might be do-able with some kind of filter, but that'll take more reading before I can post such.
JS Fiddle demo of current implementation.
Unfortunately the DX.transform option doesn't appear able to allow for multiple stops that the above uses, reference: Simulating color stops in gradients for IE
So, perhaps you'd have to use a background-image fallback for IE<10, which is far less than ideal.
Use the border-image gradient CSS3.
div {
width:200px;
border-style:solid;
border-width:15px;
text-align: center;
-webkit-border-image:
-webkit-linear-gradient(left, rgba(255,255,255,1) 1%,rgba(0,0,0,1) 50%,rgba(255,255,255,1) 100%) 0 0 100% 0/0 0 15px 0 stretch;
}
Demo here.
This will only work with Webkit browsers (Chrome, Safari etc). There should be some vendor specific equivalents.
You can use an empty div with a CSS3 Gradient... check out the presets here: http://www.colorzilla.com/gradient-editor/ - of course you'll have to change the orientation of the gradient. I use this a lot for similar issues. It's a great alternative to images.

Resources