Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Difference / Invert Text color, on hovering

Mpampis

New Coder
Hello!

I am trying to make an awesome effect :)

I would like to change the color of the text, to be inverted according to the background of each section/div.

From my search, I think that I have to use this attributes as styles.

Code:
mix-blend-mode: difference;
filter: invert(1);

What I have try so fat but not working as I like it, is this one. I am trying to make the text to be black outside of the div, but change and make it's color difference as it hovers over the green box.



If you have any suggestions, I would love to hear them!
 
It's been along time since I have worked with HTML/CSS, and even then, I haven't done as anything advanced as this, so I will apologise right now if I don't offer the best advice/solution.

Based on the Codepen I looked through(which, was quite wonky for me) and what you appear to be wanting, you want the text in the green box to change to white, and the text outside of that box to be black, correct?

If this is the case, I'll investigate the MDN(Mozilla Developer Network) for you whenever I get the chance.

I'll leave this here for myself, you, and anybody else, who wants to further understand the properties used in your original post:
Again, I can't look into this at the moment, but will whenever I get the chance(or maybe somebody will post an answer here before me).
 
Hey guys, thanks a lot for your answers!

Basically I am trying to make the text outside of the box black, but when it is hovering over the box to have the difference color of the backround.
For example when it's over the green box, the difference color is something like purple etc.

Yes I know it's tricky, but I like the thought of making it working :) :)
 
Hello there again.

After some tinkering about and reading the MDN for examples, I believe this might be what you're looking for:
[CODE lang="css" title="Possible Solution"]p {
mix-blend-mode: difference;
filter: invert(90%);
}[/CODE]

The reason you never got a change in colour was because you did not specify what unit was to be used in the filter property(in this case, it was a percentage sign that you needed). Removing the comments surrounding this section of the code also helped(pro-tip: don't comment out code unless it's due for removal in an update).

Please let me know if this is what you're looking for(or close to it anyway). The colour changes when inside the box, but the outside text isn't black.
 
Sounds like you need pseudo tags!

[CODE lang="css" title="Example"]p{
color:black;
}
p:hover{
color:white;
}[/CODE]

Pseudo tags tell the element how to react when the cursor is placed over the selection. Commonly used on links to change text color when hovered on and activated.
 

New Threads

Buy us a coffee!

Back
Top Bottom