How to apply text opacity with fading out gradient? - css

I have a container with scrolling content (white text, black background).
Like it is possible to apply fading out opacity to the background of a div, I would like to apply opacity only to the bottom of the text within the container, so that it looks like the text is fading out when you scroll down.
Usually, you apply opacity to text like so:
color: rgba(255,255,255,0.8);
How do you add a gradient to this, i.e. changing levels of opacity from top (opacity 100%) to bottom (opacity 0%) of the container?
I unsuccessfully tried this:
color: linear-gradient( bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);

You need an element to simulate the gradient.
Check out this fiddle: http://jsfiddle.net/T5pd7/
.gradient{
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
background: -webkit-linear-gradient(bottom, rgba(0,0,0,0.8), rgba(0,0,0,0.0));
background: -moz-linear-gradient(bottom, rgba(0,0,0,0.8), rgba(0,0,0,0.0));
}

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
:)

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

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>

Display Sunset Effect with Gradients Above Background Image in Body

I'm trying to create a gradient based sunset effect on my website's background.
Example Link (with sunset effect, in the background) https://web.archive.org/web/20161017071941/https://www.embroideryaffair.com/about/
Try to scroll down on the example link & you will notice the "sunset" effect.
This is what I've achieved so far: https://sirsakisan101.provenreviews.com/
I was able to display the two palm images, side-by-side, by using the following code.
body {
background-image: url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/left.png), url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/right.png), url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/sunsetbgbottom.png);
background-repeat: no-repeat, no-repeat, repeat-x;
background-attachment: fixed, fixed;
background-position: left top, right top, bottom;
}
Now, I'm trying to use the following code (mentioned below) for achieving the sunset effect on my background images, but it is not working. I've also tried removing the "before" element & adding the background images, along with gradients but then, it is appearing above the background images.
body:before {
background: linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
background: -o-linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
background: -moz-linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
background: -webkit-linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
background: -ms-linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#012c57', endColorstr='#ffcb70');
background: -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(255,203,112)), color-stop(0.3, rgb(107,138,169)), color-stop(1, rgb(205,217,230)) ) !important;
}
I want to display this code behind my background images, to achieve the sunset effect from the example website. I can't understand why it is not working. I will be grateful for any help.
Thank You.
You can do it with another html element inside the background image one.
<div> // has your background image
<div class="gradient"> // will have the gradiant style
</div>
</div>
css
.gradient {
background: linear-gradient( rgba(255,255,255,0.23) 0%, rgba(164,49,34, .85) 100%);
}
Here is an example fiddle
Note i just simplified the gradient css. Keep your own styling.
Consider the way you use the body tag like you currently do. You need to make sure the div inside (with the gradient) spans directly on top of the other div. Maybe you have to do something like
.parent {
// The element with the image
position: relative;
}
.child {
// the element with the gradient
position absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
You can directly add the gradient to the other background-images (since the gradient property is considered a background image) like this:
body {
background-image: url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/left.png),
url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/right.png),
url(https://sirsakisan101.provenreviews.com/wp-content/uploads/2019/01/sunsetbgbottom.png),
-webkit-linear-gradient(bottom, rgb(255,203,112) 0%, rgb(107,138,169) 30%, rgb(1,44,87) 100%);
}
That worked for me and it's much easier than adding additional elements ;)

Gradient opacity on borders of image

I'd like to make gradient opacity from 100% to 0% only on borders of image.
I can for example make gradient opacity on one direction of image like here( bottom has gradient)
.opacitygradient{
-webkit-mask-image: -webkit-gradient(linear, left top,
left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}
<img src="http://placehold.it/300x300" class="opacitygradient">
But i'd like to have 10px gradient going on each side (all borders), not just one direction like in snippet above.
Any ideas?
To mask off an image, you can do this.
The trick is to use two linear-gradients for the background of the container of the image, one horizontal and one vertical, that are transparent in the middle and fully white at the edges.
(Note that you will have to use another value than 255,255,255 for the rgbas if the background of the page is not white.)
.container {
display: inline-block;
background:
linear-gradient(0deg, rgba(255,255,255,1), rgba(255,255,255,0) 5%,
rgba(255,255,255,0) 95%, rgba(255,255,255,1)),
linear-gradient(90deg, rgba(255,255,255,1), rgba(255,255,255,0) 5%,
rgba(255,255,255,0) 95%, rgba(255,255,255,1));
}
.opacitygradient {
vertical-align: top;
position: relative;
z-index: -1;
}
<div class="container">
<img src="http://placehold.it/300x300" class="opacitygradient">
</div>
As a bonus, it works in all browsers, not just the ones that understand mask-image.

IE gradient solid in the middle, faded on the left and right

I'm trying to make a gradient which would be faded on the left and right, but solid in the middle. Is this possible? I've made my research, but couldn't find any tutorial online.
P.S. This is for Internet Explroer
You question is a little vague but it's just a matter of applying color stops as and when required.
If you apply two color stops at different points but the color is the same at both...you get solid color in the middle.
JSFiddle Demo
CSS (unprefixed)
.box {
width:25%;
height:200px;
border:1px solid lightgrey;
display: inline-block;
}
.one {
background: linear-gradient(to right,
rgba(255,255,255,1) 0%,
rgba(0,0,255,1) 25%, /* intermediate color stop */
rgba(0,0,255,1) 75%, /* second intermediate stop */
rgba(255,255,255,1) 100%)
; /* W3C */
}
Use the Gradient Editor for this

Resources