I'm wanting to add a transparent black overlay to a button for it' :active state, so when you click it, it's the same gradient but with just an overlay of e.g. rgba(0,0,0,.3)
The way I thought this would work is (using webkit in this example):
background:rgba(0,0,0,.3), -webkit-linear-gradient(top, #fcfcfc 0%,#bababa 100%);
or without the comma, and the order reversed... but nothing shows up at all!
I'm not keen on adding another div to act as the overlay to do it, so is there a strictly CSS way to do this? I was thinking maybe it's a :before or :after pseudo class, but I don't have a clue how to use these!
Would really appreciate an answer, this has been bugging me for a long time.
You can't do that; rgba defines a colour, not an image. What you can do is use a gradient that's not a gradient:
background: -webkit-linear-gradient(rgba(0, 0, 0, .3), rgba(0, 0, 0, .3)), -webkit-linear-gradient(top, #fcfcfc 0%,#bababa 100%);
This is why I always specify background-image instead of using the shorthand when developing - it makes debugging easier.
You can do it with ::after pseudo-element.
First, you need to define the button CSS with position: relative and then use ::after with position: absolute, like this:
.button {
position: relative;
}
.button:active::after {
content: ' ';
position: absolute;
background: rgba(0, 0, 0, 0.3);
top: 0;
left: 0;
bottom: 0;
right: 0;
}
Live Fiddle demo
Think in Reverse
Set background-color: black and overlay the gradient with your colors converted from hex to rgba (initially set to 1 for alpha), then on :active fade the gradient to 0.7 (which will show 30% black) alpha.
See the fiddle.
button {
background-color: black;
background-image: -webkit-linear-gradient(top, rgba(252, 252, 252, 1) 0%, rgba(186, 186, 186, 1) 100%);
background-image: -moz-linear-gradient(top, rgba(252, 252, 252, 1) 0%, rgba(186, 186, 186, 1) 100%);
}
button:active {
background-image: -webkit-linear-gradient(top, rgba(252, 252, 252, .7) 0%, rgba(186, 186, 186, .7) 100%);
background-image: -moz-linear-gradient(top, rgba(252, 252, 252, .7) 0%, rgba(186, 186, 186, .7) 100%);
}
Related
Below is an image of a figma design which i working on transforming into a ReactJS page, the background consist of a gradient as follows
background: linear-gradient(180deg, #E5EFFF 0%, rgba(229, 239, 255, 0.262661) 83.7%, rgba(229, 239, 255, 0) 100%);
but as you see in the background there is a another white large line in right side of the page (an image) , so how i can merge the image alone with the background together ? appreciate the feedback
You can apply multiple backgrounds to elements, something like this.
.bg1 {
width: 100%;
height: 400px;
background-image: url(https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png),
linear-gradient(180deg, #E5EFFF 0%, rgba(229, 239, 255, 0.262661) 83.7%, rgba(229, 239, 255, 0) 100%);
background-repeat: no-repeat,
no-repeat;
background-position: top right,
right;
}
<div class="bg1"></div>
I'm trying to create a line, using gradients, that becomes transparent towards every side, similar to this: Image - A vertical, bright line, that fades into the background on all sides
I have come somewhat close to recreating that. Image - The same except for some minor differences
In my best attempt, as seen above, I cheated and set the sides to the background-color:
.outer-div:before {
content: "";
background:
/* sides same color as background */
linear-gradient(to right, rgba(100, 100, 90, 1), rgba(0, 0, 0, 0), rgba(100, 100, 90, 1)),
linear-gradient(rgba(100, 100, 90, 1) 0, rgba(0, 0, 0, 0) 20% 80%, rgba(100, 100, 90, 1) 100%),
/* the actual color */
/*rgba(149, 147, 132, 1);*/
/* changed to white so it's easier to see */
rgba(255, 255, 255, 1);
float: left;
/* again, changed from 5 to 20px so it's easier to see */
width: /*5px;*/ 20px;
height: 112px;
}
<div class="outer-div">
A div with some text<br/>
text<br/>
text<br/>
text<br/>
text<br/>
text
</div>
And that's the best I could come up with.
Has anyone got any idea on how to get the sides to be actually transparent?
The easiest way is probably to use a blur on a gradient.
div::before {
content: '';
display: block;
width: 10px;
height: 150px;
background: linear-gradient(to bottom, transparent, black 20%, black 50%, transparent);
filter: blur(3px);
}
<div></div>
The border-top-color is #9b9c9d and the border-bottom-color is #f6f9fc. The gradients are intended to transition the top color to the bottom color on the border-left and border-right.
How do I mix border-left-image and border-right-image with border-top-color and border-bottom-color?
HTML
<a class="button-style">Evil Whales</a>
CSS
.button-style
{
background: linear-gradient(to bottom,
rgba(129,232,117,1) 0%,
rgba(129,232,117,1) 50%,
rgba(62,179,48,1) 51%,
rgba(62,179,48,1) 100%);
border-top-color: #9b9c9d;
border-left-image: linear-gradient(to bottom,
rgba(155,156,157,1) 0%,
rgba(246,249,252,1) 100%);
border-bottom-color: #f6f9fc;
border-right-image: linear-gradient(to bottom,
rgba(155,156,157,1) 0%,
rgba(246,249,252,1) 100%);
border-style: solid;
}
You can stack two gradients and use background-size, padding and background-clip to draw the border:
.button-style {
background: linear-gradient(to bottom, rgba(129, 232, 117, 1) 0%, rgba(129, 232, 117, 1) 50%, rgba(62, 179, 48, 1) 51%, rgba(62, 179, 48, 1) 100%) no-repeat
/* use for background */
, linear-gradient(to bottom, rgba(155, 156, 157, 1) 0%, rgba(246, 249, 252, 1) 100%)
/* use for border */
;
background-size: 100% 100%, auto auto;
background-clip: content-box, border-box;
padding: 3px;
}
html {
padding: 3em;
background: gray;
<a class="button-style">Evil Whales</a>
Got it to work though just in Chrome, Firefox and IE aren't working.
background: linear-gradient(to bottom,
rgba(129,232,117,1) 0%,
rgba(129,232,117,1) 50%,
rgba(62,179,48,1) 51%,
rgba(62,179,48,1) 100%);
border-image: linear-gradient(to bottom,
rgba(155,156,157,1) 0%,
rgba(246,249,252,1) 100%) 25 30 10 20 repeat;
border-image-repeat: stretch;
border-width: 4px;
It should be noted that there is no border-left-image and related properties; unfortunately not one of the better documented CSS properties.
I am try to get the equivalent of:
background-image: linear-gradient(90deg, rgb(166, 230, 230), rgb(231, 231, 231) 5%, rgb(255, 255, 255) 15%);
using webkit gradient.
Use left instead of 90deg for -webkit.
http://jsfiddle.net/Wyv4f/1/
I want to give linear and radial gradient to single control. Is it possible to combine this two.?
I use enjoycss for combined gradients and other complex css stuff
it automatically generate CSS,
you just play with controls, just like in photoshop
http://enjoycss.com/6y/2#background
here is generated code
background: -webkit-linear-gradient( -225deg, rgba(180,180,180,0.2) 0, rgba(255,255,255,0.2) 51%, rgba(255,255,255,0.4) 51%, rgba(255,255,255,0.8) 100%), -webkit-radial-gradient( ellipse closest-side, rgba(255,183,107,1) 0, rgba(255,167,61,1) 38%, rgba(255,124,0,1) 65%, rgba(255,127,4,1) 100%);
background: -moz-linear-gradient( 315deg, rgba(180,180,180,0.2) 0, rgba(255,255,255,0.2) 51%, rgba(255,255,255,0.4) 51%, rgba(255,255,255,0.8) 100%), -moz-radial-gradient( ellipse closest-side, rgba(255,183,107,1) 0, rgba(255,167,61,1) 38%, rgba(255,124,0,1) 65%, rgba(255,127,4,1) 100%);
background: linear-gradient( 315deg, rgba(180,180,180,0.2) 0, rgba(255,255,255,0.2) 51%, rgba(255,255,255,0.4) 51%, rgba(255,255,255,0.8) 100%), radial-gradient( ellipse closest-side, rgba(255,183,107,1) 0, rgba(255,167,61,1) 38%, rgba(255,124,0,1) 65%, rgba(255,127,4,1) 100%);
Yes it is possible to put linear and radial gradients in a single background.
The trick is to reduce the opacity of these gradients! If they are opaque they will certainly not be seen because the gradient above it will block the view, as the images and gradients are stacked one over the other.
Code example for multiple gradients (Linear + Radial) under an image:
background: url('images/picture.png') no-repeat,linear-gradient(rgba(0, 0, 0, 0.1),rgba(0, 0, 0, 0.3)),radial-gradient(rgb(221, 221, 221), rgb(78, 78, 78));
In the above example the image is stacked on the top followed by the linear-gradient just below the image layer and the radial-gradient is the lowest layer.
Note that the linear-gradient layer is not fully opaque, because if it was opaque it would not show the layer below it which is the radial-gradient in this case.
You can't put two gradient on the same element. But if you use css gradient the browser must be css3 compatible. You can use the :before and :after pseudo class to have two differents css selector.
Try this :
div {
position: relative;
width: 500px;
height: 500px;
background: -webkit-gradient(linear, 0 0, 0 500, from(rgba(220,30,50,1)), to(rgba(10,150,20,1)));
}
div:after {
content : ' ';
position: absolute;
top: 0;
left: 0;
width: 500px;
height: 500px;
background: -webkit-gradient(radial, center center, 0, center center, 400, from(rgba(65,100,220,.5)), to(rgba(240,200,90,.5)));
}
EDIT :
Multiple background is IE 9+
And after pseudo element is IE 8+
-webkit is for Safari and Chrome. You need to use -moz for firefox. Here is a cool generator to help. http://westciv.com/tools/gradients/index-moz.html