How to pass CSS variable in background URL [duplicate] - html

This question already has answers here:
Is there a way to interpolate CSS variables with url()?
(4 answers)
Closed 4 years ago.
I need to pass an image to the CSS background like this it works:
.tinted-image {
height: 125px;
background: linear-gradient(to right, var(--color), var(--color2)),
url(https://static-cdn.jtvnw.net/ttv-boxart/Apex%20Legends-300x400.jpg);
}
but when I try to do it like this, I get a syntax error in VS Code
.tinted-image {
height: 125px;
background: linear-gradient(to right, var(--color), var(--color2)),
url(var(--url));
}

You can use it like the following:
:root {
--color: rgba(255, 0, 0, 0.5);
--color2: rgba(0, 255, 0, 0.5);
--url: url(https://static-cdn.jtvnw.net/ttv-boxart/Apex%20Legends-300x400.jpg);
}
.tinted-image {
height: 125px;
background: linear-gradient(to right, var(--color), var(--color2)), var(--url);
width: 200px;
}
<div class="tinted-image"></div>
CSS variables doesn't work on Internet Explorer. You can find all browsers with CSS variable support here: https://caniuse.com/#feat=css-variables

Related

Border shifting linear-gradient background [duplicate]

This question already has answers here:
Weird effect when applying transparent border over an element with a gradient background
(7 answers)
Closed 2 months ago.
I have a div with a background defined as linear-gradient, and an almost transparent border on top of it. It should paint correctly, but the rendering is broken.
Here is the associated CodePen.
body {
background: black;
}
.gradient-background {
background: linear-gradient(270deg, #681c2e 0%, #232a6c 49.48%);
height: 80px;
border: solid 20px rgba(248, 251, 255, 0.1);
}
<div class="gradient-background"></div>
Do you know how to fix this with CSS? It behaves consistently on Chrome and Firefox. Is it an expected behavior in the spec of CSS and HTML?
rgba(248, 251, 255, 0.1); is what causes the issue.
Use background-origin: border-box; and it will work fine.
body {
background: black;
}
.gradient-background {
background: linear-gradient(270deg, #681c2e 0%, #232a6c 49.48%);
height: 80px;
border: solid 20px rgba(248, 251, 255, 0.1);
background-origin: border-box;
}
<html>
<body>
<div class="gradient-background"></div>
</body>
</html>
For more information about this, check this source.

How can I add a blurred gradient behind an image? [duplicate]

This question already has answers here:
Is it possible to make a blurred gradient shadow with CSS?
(2 answers)
Closed 7 months ago.
What would the html and css look like to create a blurred gradient underneath an image?
I understand how to create the gradient, but am not sure how to get it underneath images.
Something like this:
The gradient can be found here:
background: linear-gradient(90deg, rgba(98,52,255,1) #6234FF%, rgba(255,0,128,1) 100%);
You can make use of a custom-gradient class which is styled like that:
.image-wrapper {
background-color: white;
height: 100%;
width: 100%;
}
.custom-gradient {
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
box-shadow: inset 0 0 12px 12px white, inset 0 0 3px 2px white;
background: linear-gradient(to right, rgba(98, 52, 255, 1), #6234FF, rgba(255, 0, 128, 1))
}
<div class="custom-gradient">
<div class="image-wrapper">
<h1>My image</h1>
</div>
</div>

why does gradient CSS not working fon ull screen [duplicate]

This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
How to remove the stripes that appears when using linear gradient property [duplicate]
(2 answers)
Closed 11 months ago.
I'm having a trouble with gradient css.
for some reason when gradient finish i see the start gradient in a small line at the end.
html , body{
height: 100%;
width: 100%;
}
body{
font-family:Arial, Helvetica, sans-serif ;
background: #bef5f5; /* this is to make sure if one of the browsers arent going to read the gradient, so this is a backup background color */
background: -moz-linear-gradient(top, #833ab4 0%, #fd1d1d 50%, #cc640e 100% );
background: -webkit-linear-gradient(top, #833ab4 0%, #fd1d1d 50%, #cc640e 100% );
background: linear-gradient(top, #833ab4 0%, #fd1d1d 50%, #cc640e 100% );
}
.designHeader{
color: #ffffff;
}
.full{
height: 100% ;
width: 100%;
}
.mainFooter{
margin: 100 px;
background-image: url("pexels-pok-rie-268261.jpg");
}

Darken CSS background image? [duplicate]

This question already has answers here:
How to darken a background using CSS?
(11 answers)
Closed 7 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Should be a fairly simple question. In my website I do this:
#landing-wrapper {
display:table;
width:100%;
background:url('landingpagepic.jpg');
background-position:center top;
height:350px;
}
What I'd like to do is make the background image darker. Since I have UI elements inside this DIV I don't think I can really place another div over it to darken it. Suggestions?
You can use the CSS3 Linear Gradient property along with your background-image like this:
#landing-wrapper {
display:table;
width:100%;
background: linear-gradient( rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5) ), url('landingpagepic.jpg');
background-position:center top;
height:350px;
}
Here's a demo:
#landing-wrapper {
display: table;
width: 100%;
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('http://placehold.it/350x150');
background-position: center top;
height: 350px;
color: white;
}
<div id="landing-wrapper">Lorem ipsum dolor ismet.</div>

Transparent CSS background color

This question already has answers here:
How do I reduce the opacity of an element's background using CSS?
(29 answers)
Closed yesterday.
I want to make the list menu's background disappear by using opacity, without affecting the font. Is it possible with CSS3?
now you can use rgba in CSS properties like this:
.class {
background: rgba(0,0,0,0.5);
}
0.5 is the transparency, change the values according to your design.
Live demo http://jsfiddle.net/EeAaB/
more info http://css-tricks.com/rgba-browser-support/
Keep these three options in mind (you want #3):
1) Whole element is transparent:
visibility: hidden;
2) Whole element is somewhat transparent:
opacity: 0.0 - 1.0;
3) Just the background of the element is transparent:
background-color: transparent;
To achieve it, you have to modify the background-color of the element.
Ways to create a (semi-) transparent color:
The CSS color name transparent creates a completely transparent color.
Usage:
.transparent{
background-color: transparent;
}
Using rgba or hsla color functions, that allow you to add the alpha channel (opacity) to the rgb and hsl functions. Their alpha values range from 0 - 1.
Usage:
.semi-transparent-yellow{
background-color: rgba(255, 255, 0, 0.5);
}
.transparent{
background-color: hsla(0, 0%, 0%, 0);
}
As of the CSS Color Module Level 4, rgb and hsl works the same way as rgba and hsla does, accepting an optional alpha value. So now you can do this:
.semi-transparent-yellow{
background-color: rgb(255, 255, 0, 0.5);
}
.transparent{
background-color: hsl(0, 0%, 0%, 0);
}
The same update to the standard (Color Module Level 4) also brought in support for space-separated values:
.semi-transparent-yellow{
background-color: rgba(255 255 0 / 0.5);
}
.transparent{
background-color: hsla(0 0% 0% / 0);
}
I'm not sure why would these two be any better than the old syntax, so consider using the a-suffixed, comma-separated variants for greater support.
Besides the already mentioned solutions, you can also use the HEX format with alpha value (#RRGGBBAA or #RGBA notation).
That's contained by the same CSS Color Module Level 4, so it has worse support than the first two solutions, but it's already implemented in larger browsers (sorry, no IE).
This differs from the other solutions, as this treats the alpha channel (opacity) as a hexadecimal value as well, making it range from 0 - 255 (FF).
Usage:
.semi-transparent-yellow{
background-color: #FFFF0080;
}
.transparent{
background-color: #0000;
}
You can try them out as well:
transparent:
div {
position: absolute;
top: 50px;
left: 100px;
height: 100px;
width: 200px;
text-align: center;
line-height: 100px;
border: 1px dashed grey;
background-color: transparent;
}
<img src="https://via.placeholder.com/200x100">
<div>
Using `transparent`
</div>
hsla():
div {
position: absolute;
top: 50px;
left: 100px;
height: 100px;
width: 200px;
text-align: center;
line-height: 100px;
border: 1px dashed grey;
background-color: hsla(250, 100%, 50%, 0.3);
}
<img src="https://via.placeholder.com/200x100">
<div>
Using `hsla()`
</div>
rgb():
div {
position: absolute;
top: 50px;
left: 100px;
height: 100px;
width: 200px;
text-align: center;
line-height: 100px;
border: 1px dashed grey;
background-color: rgb(0, 255, 0, 0.3);
}
<img src="https://via.placeholder.com/200x100">
<div>
Using `rgb()`
</div>
hsla() with space-separated values:
div {
position: absolute;
top: 50px;
left: 100px;
height: 100px;
width: 200px;
text-align: center;
line-height: 100px;
border: 1px dashed grey;
background-color: hsla(70 100% 50% / 0.3);
}
<img src="https://via.placeholder.com/200x100">
<div>
Using `hsla()` with spaces
</div>
#RRGGBBAA:
div {
position: absolute;
top: 50px;
left: 100px;
height: 100px;
width: 200px;
text-align: center;
line-height: 100px;
border: 1px dashed grey;
background-color: #FF000060
}
<img src="https://via.placeholder.com/200x100">
<div>
Using `#RRGGBBAA`
</div>
yes, thats possible. just use the rgba-syntax for your background-color.
.menue {
background-color: rgba(255, 0, 0, 0.5); //semi-transparent red
}
Here is an example class using CSS named colors:
.semi-transparent {
background: yellow;
opacity: 0.25;
}
This adds a background that is 25% opaque (colored) and 75% transparent.
CAVEAT
Unfortunately, opacity will affect then entire element it's attached to.
So if you have text in that element, it will set the text to 25% opacity too. :-(
The way to get past this is to use the rgba or hsla methods to indicate transparency* as part of your desired background "color". This allows you to specify the background transparency*, independent from the transparency of the other items in your element.
Technically we're setting the opacity, though we often like to speak/think in terms of transparency. Obviously they are related, inverses of each other, so setting one decides the other.
The number specified is the opacity %. 1 is 100% opaque, 0% transparent & vice versa).
Here are 3 ways to set a blue background at 75% opacity (25% transparent), without affecting other elements:
background: rgba(0%, 0%, 100%, 0.75)
background: rgba(0, 0, 255, 0.75)
background: hsla(240, 100%, 50%, 0.75)
In this case background-color:rgba(0,0,0,0.5); is the best way.
For example: background-color:rgba(0,0,0,opacity option);
Try this:
opacity:0;
For IE8 and earlier
filter:Alpha(opacity=0);
Opacity Demo from W3Schools
Yes you can just plain text as
.someDive{
background:transparent
}
For your case, we can use rgba():
First, we manipulate the background-color, and use rgba.
.selector {
background-color: rgba(0, 0, 0, 0.3);
}
Now what this does is, it basically adds an opacity to your element, along with the black background color. This is how it'd look when you run it.
body {background-color: #0008f3;}
.container {
height: 100px;
width: 100px;
background-color: rgba(255,255,255,0.5);
}
<body>
<div class="container"></div>
</body>
full transparent -> .youClass{background: rgba(0,0,0,0.001);}