Dynamic color change while scrolling with CSS

Поділитися
Вставка
  • Опубліковано 3 січ 2025

КОМЕНТАРІ • 87

  • @JaredMeadows
    @JaredMeadows Рік тому +88

    A missed opportunity in this was to explain the reason we're making it white. In this case, the color is getting **subtracted**. Using #000000 (black) means you're subtracting 0, so the element remains invisible (white). On the other hand, when you set it to #FFFFFF (white), you're subtracting 255 from the color value. As a result, the element is displayed as black (0) because 255 (white background) - 255 (white element) = 0 (displayed black). Cheers! 🍻
    Regardless thank you so much for the video!! Informative and concise as always, Kevin!

    • @roadto200million
      @roadto200million Рік тому +3

      Yes, he kinda suggested that the reason it's called Difference is because in Photoshop it was used to find difference between elements, but this subtraction math where you find numerical difference between two colors is actually the reason why it's called difference

    • @NineSun001
      @NineSun001 Рік тому

      So a medium grey would become a negative number?
      Or does it get absoluted back. But then the logo should dissapear again on a color of 128 which gets subtracted to -127 and inverted back to 127. This way the logo would dissapear?

    • @Bert1986
      @Bert1986 Рік тому

      @@NineSun001 grey background = white logo becomes grey, black logo becomes grey.... :(

  • @dannymartial7997
    @dannymartial7997 Рік тому +20

    I’m a professional frontend dev, and I learn so much from these videos. I would’ve never known about mix blend mode on my own.

    • @petarkolev6928
      @petarkolev6928 Рік тому +2

      You can never know everything by hearth, not to mention that new things come along every few months. This is why such videos are so useful

    • @NineSun001
      @NineSun001 Рік тому

      Me too. Every day a new way to fancy up my sites a little bit. I am a fan of really subtle effects. transitions shorter than .1s almost invisible textures, etc. You brain will recognize them but you are not consciously aware of them (unless you actively look for them). This way the site always feels better. Can't describe it. It just enhances it greatly without being noticed (or demanding a lot of ressources)

  • @Danachew
    @Danachew Рік тому +25

    I'm literally working on a practice project with overlapping backgrounds as you scroll down. Yesterday I was thinking to myself "Man it would be awesome if I could change up the navigation's font color to keep contrast on different backgrounds..."

    • @goodshiro10
      @goodshiro10 Рік тому +3

      You're lucky😂You got your solution when you needed it

    • @Danachew
      @Danachew Рік тому +2

      @@goodshiro10 right?? LOL

  • @theojnr-kw3yv
    @theojnr-kw3yv Рік тому +5

    Genius!!
    The time you put in to discover and learn these things, just so you can share with us, is amazing!
    Thanks❤

  • @shakilahmed6870
    @shakilahmed6870 Рік тому +2

    Thought its gonna be difficult. But its very easy.
    step-1/ make the color of logo white
    step-2/ apply mix-blend-mode:difference; to the logo
    Thanks for the video❤

  • @UPLYNXED
    @UPLYNXED Рік тому +5

    This is a very interesting and clean way to do this!
    I've previously done this by having duplicate menu bars and using clip-path, which might still be useful as it does give more control in regards to colors.
    Though at the time, the main reason was that mix-blend modes just weren't fully supported yet.

  • @patricksantos2996
    @patricksantos2996 Рік тому

    thank you so much for sharing those "simple" tutorials, you make css looks so easy hehe

  • @GilGoldshlager
    @GilGoldshlager Рік тому +20

    You can use CSS filter: brightness(100); or invert(1); to turn your black/colored logo into white without modifying it.

  • @seeker3794
    @seeker3794 Рік тому

    Kevin thanks a lot.... Whenever I face a problem in css, I find your videos very useful👍.

  • @blystar4264
    @blystar4264 Рік тому

    I will forever salute you. Most of the things I know now is because of you, thank you so much

  • @bjgjuiuguoojpoo
    @bjgjuiuguoojpoo Рік тому

    Exactly what I was looking for! THANK YOU SOOOOO MUCH!!!

  • @tithos
    @tithos Рік тому +18

    Use currentColor in the svg to avoid multiple files

    • @Shaffefr
      @Shaffefr Рік тому +1

      I thought currentColor only worked with inline SVGs?

    • @wheeldwell
      @wheeldwell Рік тому

      @@Shaffefr currentColor is a CSS property, it will grab the closest color value. For example from the parent class.

    • @Shaffefr
      @Shaffefr Рік тому +1

      @@wheeldwell yes, what I was saying is that I think that currentColor doesn't work for external SVGs.

    • @AbWischBar
      @AbWischBar Рік тому

      Or avoid setting fill inside the SVG and instead set it in context? For multicolored SVGs I define classes inside the SVG and refer to them from page CSS.

  • @tooFarGonexk4he4tu3s
    @tooFarGonexk4he4tu3s Рік тому

    I usually keep an eye on CSS news, but this time my mind is completely blown. Don't know if this property is new but I have never seen it. Might come really handy in the future

  • @GuebreAdama
    @GuebreAdama Рік тому

    Greta job Kevin! It's very useful!!

  • @joeldcanfield_spinhead
    @joeldcanfield_spinhead Рік тому

    I've been playing extensively with blend modes in Affinity Photo for the past couple years. Astounding how useful it could be in CSS if I'd remember to use it . . .

  • @sarahnekam7149
    @sarahnekam7149 Рік тому +1

    Thanks for your great videos! You are a great teacher 😊

  • @panmrow5009
    @panmrow5009 Рік тому +9

    That is absolutely great, but I wonder how would you do something similar, with multiple colours. I saw something like that on a Dropbox page (years ago), I think. It had multiple, different coloured sections. Both logo and navigation were changing the way it does in Your example, but with different colour for each section. I wasn’t able to recreate it.

    • @KevinPowell
      @KevinPowell  Рік тому +5

      You could probably do it using the svg as a mask or clip-path... Would have to give it a bit of thought though

    • @Lavah
      @Lavah Рік тому +1

      I am also for something like this..

  • @GaryBarclay
    @GaryBarclay Рік тому

    I click the like before the video starts. Kevin brings CSS satisfaction guaranteed!

  • @mikalaybourn
    @mikalaybourn Рік тому +4

    The only downside to this is that you're expected to have a complete black/white page, for you to successfully use this trick. This is most times not the case for anyone. You will probably somewhere have a bit of color on the page.

    • @Bert1986
      @Bert1986 Рік тому

      use grey, and nothing works :D

  • @zakir.nuriiev
    @zakir.nuriiev Рік тому

    Very cool trick! Now I know one more. Thanks a lot!

  • @maxwebstudio
    @maxwebstudio Рік тому

    Thank you Kevin !

  • @Thekidisalright
    @Thekidisalright Рік тому

    This is so simple yet elegant, Thank you so much Kevin!

  • @D7460N
    @D7460N Рік тому

    Perfect timing!

  • @PicSta
    @PicSta Рік тому

    A very nice effect :)

  • @CharlesSmall
    @CharlesSmall Рік тому

    Thank you , Kevin

  • @ALCATRAAAZZ
    @ALCATRAAAZZ Рік тому

    Thanks much! Just finished a course on mixed-blend-mode and had the same question "why it disapears?" :)

  • @maxgamer6476
    @maxgamer6476 Рік тому

    Love you men keep blowing my mind

  • @KelseyThornton
    @KelseyThornton Рік тому

    Great effect

  • @Danroberts1984
    @Danroberts1984 Рік тому +2

    Hi Kevin, absolutely awesome video. I've been struggling to get this to work for ages. So I set it up exactly as you did and it worked. The problem I was having was I was placing my logo element into a header. Why would placing this inside another div/header cause issues?

  • @victormustin2547
    @victormustin2547 Рік тому

    I coded this on a project litterally this morning

  • @TomasHradckyComposer
    @TomasHradckyComposer Рік тому

    Very nice and helpful.

  • @preciousname3624
    @preciousname3624 Рік тому +3

    Nice video

  • @Ardo-w4w
    @Ardo-w4w 2 місяці тому

    gracias, ily

  • @ScriptRaccoon
    @ScriptRaccoon Рік тому

    How can we do this when the section has a different color than black?
    I am running into this issue right now. With black it works, but not otherwise.

  • @nikoman71326
    @nikoman71326 5 місяців тому

    not wroking for me with transparent mui appbar... the problem is appbar transparent background. not sure how to fix that

  • @nro337
    @nro337 Рік тому

    Very cool!

  • @crazy-boy6143
    @crazy-boy6143 Рік тому

    Nice effect there. It started to get problematic, the taps in my broswer are getting greater and greater because youtube keeps suggesting your nice videos XD

  • @j.almadhaji
    @j.almadhaji Рік тому +2

    Great 👏

  • @petarkolev6928
    @petarkolev6928 Рік тому

    Yet another amazing video! Thank you so much, Kevin! One can learn something new everyday thanks to you 🍻🍻

  • @matthiaspanopau
    @matthiaspanopau 10 місяців тому

    ChatGPT:
    `mix-blend-mode: difference` calculates the absolute difference between the color values of the element and the background for each of the RGB channels separately. Here's how it works with black and white logos against black and white backgrounds, explained with RGB values:
    - **White logo on white background:** turns black (`|rgb(255, 255, 255) - rgb(255, 255, 255)| = rgb(0, 0, 0)`).
    - **White logo on black background:** remains white (`|rgb(255, 255, 255) - rgb(0, 0, 0)| = rgb(255, 255, 255)`).
    - **Black logo on white background:** turns white (`|rgb(0, 0, 0) - rgb(255, 255, 255)| = rgb(255, 255, 255)`).
    - **Black logo on black background:** remains black (`|rgb(0, 0, 0) - rgb(0, 0, 0)| = rgb(0, 0, 0)`).
    This explains why it works with a white Logo but not with a black Logo. Thanks Kevin & Chatty! ^^

  • @AlThePal78
    @AlThePal78 Рік тому

    I am trying to do something like that with the nav bar and then it changes colors and sticks to thte jtop with tailiwind :)

  • @kimiamojarad-w7h
    @kimiamojarad-w7h Рік тому

    How should we get the source code you have above?
    Because I need it :)))))))))))))))

  • @ilTHfeaa
    @ilTHfeaa 11 місяців тому

    but what if i want to do this with colours? black and white hurt my eyes

  • @aashjain6460
    @aashjain6460 Місяць тому

    Hey! I was stuck on a problem, and this video is a part solution to it. However, I want to make a small tweak i.e. my background colour is #A91232 and on reaching this background, I need the text colour to be white only. How do I do it? Please help. Thanks

  • @qrx.4596
    @qrx.4596 Рік тому

    Do you have any solution if my logo has black/white typography and color image? I'm mean I'd like to change color of typography just like you presented but keep the colors untouched (not inverted)

  • @NotKyleChicago
    @NotKyleChicago Рік тому

    Will this work for a logo that is a JPG, PNG, or GIF?

  • @khantminsithu8815
    @khantminsithu8815 3 місяці тому

    Is this stop working in modern browsers? I tried using the same code and not working anymore

  • @justkailash
    @justkailash Рік тому

    Thank you for the trick...

  • @Julie-gh5ir
    @Julie-gh5ir Рік тому

    Do you think this can be used to change navigation color according to the background ?

  • @NathanHedglin
    @NathanHedglin Рік тому

    Love it.

  • @deepakjoyjose8189
    @deepakjoyjose8189 Рік тому +2

    Hi Kevin, I was wondering if it would be possible to provide the starter files for tutorials you are doing in VS Code. It is kind of difficult to replicate everything you are doing in the tutorial unless we have the same starting point. Love what you do in these videos. Much appreciated :)

  • @reyreyalldayday5708
    @reyreyalldayday5708 Рік тому

    Dammit where was this video weeks ago when I was trying to do this for a job interview!?!?!?! Lol

    • @KevinPowell
      @KevinPowell  Рік тому

      Oh no! Lol, hope it went well otherwise!

  • @keessonnema
    @keessonnema Рік тому

    I've been trying to use this only for when I scroll over images, but not on the background (behind the images and - in this case - heading). Anyone got any idea on how to only use the mix-blend-mode when scrolling over elements (images), but not the background of the section/div?

  • @user-hm1ld3bg3g
    @user-hm1ld3bg3g Рік тому +1

    Why don't you show or upload the entire initial setup code and files so that I can refer to it?😅😅

  • @mark_pherz
    @mark_pherz Рік тому

    This guy is Gale Boetticher of front-end

  • @Black1991Star
    @Black1991Star Рік тому

    How to save color for some text for :hover ? .chapterLink:hover{color: #f00 !important;} ???

  • @realraven2000
    @realraven2000 Рік тому

    quick question on the slight off white - the shorthand #fff is the same as #f0f0f0, right? 6:48 - since it;s a svg we can use fill:white; no?

    • @ScriptRaccoon
      @ScriptRaccoon Рік тому +1

      #xyz is a shorthand for #xxyyzz. So #fff is a shorthand for #ffffff, i.e. white.

    • @realraven2000
      @realraven2000 Рік тому

      @@ScriptRaccoon Alright! I always thought that I read somewhere it's padded with 0s...

  • @ritzmillan7033
    @ritzmillan7033 Рік тому

    Awsome

  • @iamTazim9
    @iamTazim9 Рік тому

    Cool 😎

  • @ankurpathak108
    @ankurpathak108 Рік тому

    you know that the effect is really easy to recreate when the video size is just 8mins 😂

  • @CristianKirk
    @CristianKirk Рік тому

    Hello Kevin, in case you read this comment, I've been wondering something. I keep seeing a lot of websites that don't use hover effects on their navigation menues. And it's clearly not a mistake or something they forgot, they are just not using it deliberately . What's your thoughts?

  • @JasonJA88
    @JasonJA88 Рік тому

    👍

  • @504-chavdarahul6
    @504-chavdarahul6 Рік тому +1

    Try to make a short video and director to the point

  • @klirmio21
    @klirmio21 Рік тому

    Why couldn't they come up with this syntax in the first place???????????????

  • @saschab.5154
    @saschab.5154 Рік тому +2

    Nothing is ever supported in Safari. It's worse than the IE was.

    • @KevinPowell
      @KevinPowell  Рік тому +6

      You didn't work with IE6-8 if you're saying that 😅
      It's definitely had it's issues, but it's often landing new features before Chromium does now. They've invested a lot into the team, and they've really leveled up a lot. The issue is, of course, people on older iPhones can't update, so we do have to keep them in mind.

  • @AdilHussain-vf4nb
    @AdilHussain-vf4nb Рік тому

    It will be your pleasure, to provide the images/logo as well. along with all lectures.

  • @nomad100hd
    @nomad100hd Рік тому

    I thought using px for media queries was bad practice?