how to use gradient with variables

linear-gradient(rgb(var(--main-color-1)),rgb(var(--main-color-2)) ) why this is not working
39 Replies
13eck
13eck•2y ago
You'll have to give a bit more than just that one line. What's the HTML and CSS look like? Do you have a codepen to share?
M.A.L
M.A.LOP•2y ago
background: -moz-linear-gradient(rgb(var(--main-color-1)),rgb(var(--main-color-2)) ); background: -webkit-linear-gradient(rgb(var(--main-color-1)) ,rgb(var(--main-color-2)) ); background: -ms-linear-gradient(rgb(var(--main-color-1)) ,rgb(var(--main-color-2)) );} :root{ --main-color-1:, 178, 26, 255; --main-color-2:115, 43, 222; } wait
Mannix
Mannix•2y ago
normally you use something like this
linear-gradient(45deg, red, blue);
linear-gradient(45deg, red, blue);
just take this apart a put variables where you want
M.A.L
M.A.LOP•2y ago
no dude i want to creat a settings box wheere ucan change the color of the site and the colors are all gradients so i have to use gradients with variables get it
13eck
13eck•2y ago
Well, your --main-color-1 has an extra comma right at the beginning
M.A.L
M.A.LOP•2y ago
yea i fix it
Mannix
Mannix•2y ago
you just change the values to variables
M.A.L
M.A.LOP•2y ago
and it's still doesn't work shoud i send the html file?
Mannix
Mannix•2y ago
linear-gradient(45deg, var(--main-color-1), var(--main-color-2));
M.A.L
M.A.LOP•2y ago
and var sould be rgb instead of values?
13eck
13eck•2y ago
Works just fine for me using the linear-gradient property instead of the prefix versions
M.A.L
M.A.LOP•2y ago
let me try it
13eck
13eck•2y ago
I also fixed the --main-color-1 error
Mannix
Mannix•2y ago
you can turn any part of the value into a variable
M.A.L
M.A.LOP•2y ago
bro 45deg not mandatory?
13eck
13eck•2y ago
Nope I'd recommend reading the MDN docs on the topic to learn more about what is and isn't required: https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient
M.A.L
M.A.LOP•2y ago
just one second let me put in codepen bcz it doesn't work
Mannix
Mannix•2y ago
spelling error?
13eck
13eck•2y ago
Can you give a minimum working example? You have too much extra stuff in that pen. Makes it very difficult to know what exactly you're trying to do and where
M.A.L
M.A.LOP•2y ago
okay
Mannix
Mannix•2y ago
you can't use linear-gradient in color property 😉
13eck
13eck•2y ago
Also you can't RGB and RGB colour property :p
:root{
--main-color-1:rgb(178, 26, 255) ;
--main-color-2:rgb(115, 43, 222);
}
.introduction h4{
font-size: 20px;
font-weight: 600;
color: linear-gradient(rgb(var(--main-color-1)),rgb(var(--main-color-2)));
}
:root{
--main-color-1:rgb(178, 26, 255) ;
--main-color-2:rgb(115, 43, 222);
}
.introduction h4{
font-size: 20px;
font-weight: 600;
color: linear-gradient(rgb(var(--main-color-1)),rgb(var(--main-color-2)));
}
Not to mention using pixels for font size…
M.A.L
M.A.LOP•2y ago
what okay u can see now u can check now dude
13eck
13eck•2y ago
You're still trying to use linear gradient for color property, which doesn't work in CSS
M.A.L
M.A.LOP•2y ago
now no im trying to use it in background-color
Mannix
Mannix•2y ago
background-image not background-color
M.A.L
M.A.LOP•2y ago
i can't use is iin background-color either?
Mannix
Mannix•2y ago
nope
13eck
13eck•2y ago
You can use background
M.A.L
M.A.LOP•2y ago
ahaaa i get it
13eck
13eck•2y ago
But in your codepen nothing will be working b/c you're trying to modify .introduction h4 but there is no .introduction to have an h4
M.A.L
M.A.LOP•2y ago
thank you guys you are the best
Mannix
Mannix•2y ago
thumbup
13eck
13eck•2y ago
Replace all your CSS with:
:root{
--main-color-1:rgb(178, 26, 255) ;
--main-color-2:rgb(115, 43, 222);
}

h4{
font-size: 20px;
font-weight: 600;
background: linear-gradient(var(--main-color-1),var(--main-color-2));
}
:root{
--main-color-1:rgb(178, 26, 255) ;
--main-color-2:rgb(115, 43, 222);
}

h4{
font-size: 20px;
font-weight: 600;
background: linear-gradient(var(--main-color-1),var(--main-color-2));
}
and it'll work
M.A.L
M.A.LOP•2y ago
can i ask one ,oe question more does anyone know a tutriol of how to change background image of the lading page smoothly li like in fiver
13eck
13eck•2y ago
You could try to inspect the code on their site. You can look in #resources and see if someone posted something similar. Otherwise I'd suggest using your favourite internet search engine and see what it can turn up
M.A.L
M.A.LOP•2y ago
okk
Want results from more Discord servers?
Add your server