How to add saturation to a background gradient?

background: linear-gradient(90deg, rgba(63,94,251,1) 0%, rgba(252,70,107,1) 100%);
background: linear-gradient(90deg, rgba(63,94,251,1) 0%, rgba(252,70,107,1) 100%);
This gradient is inside body{}.
54 Replies
Jochem
Jochem2y ago
hsla() - CSS: Cascading Style Sheets | MDN
The hsla() functional notation expresses a given color according to its hue, saturation, and lightness components. An optional alpha component represents the color's transparency.
Jochem
Jochem2y ago
you can just change the second property of that if you want to change the saturation. IIRC vscode can translate between rgba and hsla, but if that doesn't work I'm sure there's a million translation tools on google
Mannix
Mannix2y ago
you can use alpha values in hsl no need for hsla 🙂
Jochem
Jochem2y ago
alternatively you can use blend mode to fake a saturation filter: https://css-tricks.com/apply-a-filter-to-a-background-image/
Chris Coyier
CSS-Tricks
Apply a Filter to a Background Image | CSS-Tricks
You can apply a filter to an entire element quite easily with the filter property. But what if you want to apply a filter just to the background of an
Jochem
Jochem2y ago
keep in mind that the blend mode here uses the alpha channel, so that linear-gradient(black, black) they're using needs to be black, transparent and not black, white if you want a fading saturation effect
Aman
AmanOP2y ago
@jochemm it applies the saturation to everything on the page. I only want the the background gradient to change and not the logo.
Jochem
Jochem2y ago
then just use hsl
Aman
AmanOP2y ago
hsl: (40%,10%);
hsl: (40%,10%);
am i doing the correct thing? bc i see no changes @jochemm
Jochem
Jochem2y ago
body {
background: linear-gradient(90deg, hsl(230, 96%, 62%) 0%, hsl(348, 97%, 63%) 100%);
}
body {
background: linear-gradient(90deg, hsl(230, 96%, 62%) 0%, hsl(348, 97%, 63%) 100%);
}
you can change the second percentage in both and it will desaturate the gradient I used hsl instead of hsla because you just had both alpha channels set to 1
Aman
AmanOP2y ago
thanks man you are lifesaver
Aman
AmanOP2y ago
@jochemm I do have one more issue. See this gradient just repeats itself but not the nav. I tried many things but it didnt work
Jochem
Jochem2y ago
put it in a codepen, then I can take a look
Aman
AmanOP2y ago
okke
Aman
AmanOP2y ago
Jochem
Jochem2y ago
you have to save it first
Aman
AmanOP2y ago
wait not this one im use to autosave haha
Gashy
Gashy2y ago
Its being caused by the percentage margin on your heading
Aman
AmanOP2y ago
but if i remove the margin, it wont aligned properly?
Gashy
Gashy2y ago
you would use a wrapper so that the parent has a width to work off of, and then you can use margin inline auto, or alternatively something like flex/grid
Aman
AmanOP2y ago
i dont fully understand css cuz i just started so idk what that means. havent started flexbox or grid yet
Gashy
Gashy2y ago
Id advise checking out kevins courses on it, they are super useful - here is an example on what i was on about https://codepen.io/gashydev/pen/MWXMYop
Aman
AmanOP2y ago
the repeating gradient issue was fixed after removing the margin but now its not center anymore
Jochem
Jochem2y ago
you can just stick text-align: center on that section tag
Gashy
Gashy2y ago
That as well
Jochem
Jochem2y ago
though probably not just using section {}, but with a class
Aman
AmanOP2y ago
it did solve the issue but i dont know how so yeah i'll check out his courses
Gashy
Gashy2y ago
I just went with an example of treating it like a normal block instead of specifically a text one, Jochems solution is the better approach in this use case
Aman
AmanOP2y ago
do i have to give a class? cuz i want this styling to apply to all headings on each page and there is one per page.
Jochem
Jochem2y ago
generally it's better to use classes than to apply directly to elements, but you don't have to.
Aman
AmanOP2y ago
but it didnt work without a class
Jochem
Jochem2y ago
did you remove the margins and the translate? and add text-align: center to the section?
Aman
AmanOP2y ago
yeah
Jochem
Jochem2y ago
update the codepen then and I'll take another look
Aman
AmanOP2y ago
yeah its fixed now, i just added class to the headings @jochemm @gashy Thanks for the help!
Jochem
Jochem2y ago
np
Gashy
Gashy2y ago
No worries!
Aman
AmanOP2y ago
@jochemm @gashy This is a small bug, i feel like im going in the right direction but im missing smth and idk what https://codepen.io/Aman-sghh/pen/LYrKERr I want to add active class to the link that is currently active but i only get the effect when i click on it when i let go, it goes back to normal, the styling dont stay forever
Jochem
Jochem2y ago
you have no btn-active class in your css class="btn-active" does not match .btn:active the :active pseudo-class only covers active interaction by the user, and won't highlight the page you're on automatically either
Aman
AmanOP2y ago
bcs its all btn for links, i forgot to update https://codepen.io/Aman-sghh/pen/LYrKERr its updated now thats how they did it on w3school and yt but there was some js too
Jochem
Jochem2y ago
you can't do that without js as far as I know you can't just follow half a tutorial and expect it to work 😛
Aman
AmanOP2y ago
i can only use css in this project thats why i ignored the js part
Jochem
Jochem2y ago
you can't have automatically changing active links with only css, and that's not what the :active pseudo element is for
Aman
AmanOP2y ago
So this effect is impossible without js?
Jochem
Jochem2y ago
you could manually edit each page and set a class on the appropriate link, but that's it
Aman
AmanOP2y ago
ok well thanks anyways
Jochem
Jochem2y ago
I'm curious, why can't you use javascript? there's almost no situation I can imagine where you couldn't just include a script tag at the bottom of the page, short of maybe an email template and this isn't that
Aman
AmanOP2y ago
Im in college and currently in semester 1 so they only taught us html and css, thats why we are not allowed to use javascript im just gonna ask the lecturer to do it without css😁
Gashy
Gashy2y ago
If its not an SPA you should just be able to add the class to the respected link like Jochem suggested
Aman
AmanOP2y ago
i did give it a class but its 80% complete so the the link is active only when i click on it nd changes background but as soon as i let go it goes back to normal i want to be able to see which page im currently on by just looking at the navbar and this must be done without js
Aman
AmanOP2y ago
here's an example but i dont get really get it
Gashy
Gashy2y ago
Like jochem said :active is not what this use case is for You need to add a class to the specific element itself, on each individual page so for example you have 4 pages and 4 links - home, contact, about, blog - in home.html you need to add a class to the home link element in the navigation - in contact.html you need to add a class to the contact link element in the navigation - in about.html you need to add a class to the about link element in the navigation - in blog.html you need to add a class to the blog link element in the navigation :active is for the state of a button or link whilst the user is clicking on the element, as soon as the user has finished clicking this, its no longer active (in its simplest form)
Aman
AmanOP2y ago
ah i added the same class to every element, ig thats the issue
Want results from more Discord servers?
Add your server