Issue with mix-blend-mode causing text to not show up on top of the gradient

I am struggling to find a way to make text easily readable over my gradient background. Despite trying to use MUI's Typography or a simple <p>, the contrast isn't great as the text appears in black.

After some research, I discovered that I could potentially improve the contrast by utilizing mix-blend-mode, so I decided to give it a shot.

This is how I structured my div:

const useStyles = makeStyles((theme: Theme) => {
  const fontSize = 15;

  return createStyles({
    avatarText: {
      mixBlendMode: "difference",
    },
  });
});

<div className="profile-basic-info">
  <Avatar src={avatar} className="avatar" />
  <Typography variant="h3" className={classes.avatarText}>
    {firstName} {lastName}
  </Typography>
  <Typography variant="h6" className={classes.avatarText}>
    {email}
  </Typography>
</div>

Here is the CSS (SCSS) for this div:

.profile-basic-info {
  display: flex;
  flex-direction: column;
  min-width: 500px;

  border-radius: 50px 0px 0px 50px;
  padding: $padding;

  align-items: center;
  justify-content: center;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);

  .avatar {
    margin-bottom: 30px;
    width: 360px !important;
    height: 360px !important;
    box-shadow: 0px 0px 50px 30px rgba(0, 0, 0, 0.5);
  }
}

To style the Typography, I utilize classes.avatarText (this is a specific feature of MUI).

The issue arises when the mix-blend-mode is added, resulting in the text disappearing entirely:

https://i.stack.imgur.com/gq2pe.png

If I comment out the background: [...] property in my CSS, the text becomes visible once again:

https://i.stack.imgur.com/TgBPV.png

Could there be an error in my approach somewhere?

P.S This isn't an isolated MUI problem - I have tested with regular <p> elements and applying mix-blend-mode directly in the CSS file, yet the text remains hidden under the gradient.

Answer №1

The default font color is black, represented by hex code 000000. When you overlay any other color with black, the font appears to disappear.

To make the text visible, change the font color to white.

Below is a simplified example of how to achieve this:

.avatartext {
  mix-blend-mode: difference;
  width: 50%;
  height: 50%;
  color: white;
}

.profile-basic-info {
  width: 20vw;
  height: 20vw;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
}
<div class="profile-basic-info">
  <div class="avatartext">John Smith</div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Make sure to have the list available while choosing an item

I want to design a unique CSS element with the following characteristics: Include a button. When the button is clicked, a list of items (like a dropdown list) should appear. We should be able to select items by clicking on them, and the parent component s ...

Problem with Express server not fetching or applying public stylesheet

As I delve into the world of serving pages with node, express, and ejs, I encountered an issue with linking a stylesheet to my index.ejs file using a public folder. Despite setting up the link correctly in the HTML code, the styles were not loading when I ...

Aligning SVG clipping path using CSS

This problem has me stumped! I need to center the SVG clip within the surrounding div, just like in this example: http://jsfiddle.net/ztfdv9qh/ - Make sure to check the link because the SVG is quite long! <div class="svg-wrapper"> <div class ...

Place each label and input element on a separate line without using div tags

Can we separate form elements onto individual lines without enclosing them within divs? For example: <label for="one">One:</label> <input type="text" id="one"> <label for="two">Two:</label> <select id="two"> ...

Executing Javascript code from a specified web address

Let's say I have an image that needs to be shifted vertically, and I achieve it using the following code snippet: document.getElementById('ImgID1').style.verticalAlign = However, the value by which I need to shift the image is provided thr ...

What methods can be used to accomplish this effect using CSS and/or Javascript?

Is there a way to achieve the desired effect using just a single line of text and CSS, instead of multiple heading tags and a CSS class like shown in the image below? Current Code : <h2 class="heading">Hi guys, How can i achieve this effect using j ...

Move the DIV element to the bottom of the webpage

On my website, I have implemented a countdown timer and a responsive wallpaper. My goal now is to center the div at the bottom of the page and make sure it always stays there. I've tried some code snippets from StackOverflow, but they either gave me a ...

Activate the horizontal scrollbar within each flex item when it is stretched beyond its original width

My goal is to have both the child-1 (blue) and child-2 (black) retain their original width when the sidebar appears by enabling horizontal scrolling upon clicking anywhere in the demo below. document.body.onclick = () => document.querySelector(&apos ...

Error 403 with Firefox on Font Loading for CodeIgniter Website

Utilizing font-face in CSS to integrate custom fonts onto a web application being developed with CodeIgniter. This is the CSS code: @font-face { font-family: 'UniversLT-UltraCondensed'; src: url('../Fonts/LTUnivers/universlt59ultrac ...

Bug with IOS double tap on Element UI VueJS select input element

Encountering a strange problem on iOS safari or chrome. When attempting to select an option from a dropdown input, the options show up correctly on the first tap, but when trying to actually select an option, it requires two taps to work properly. This is ...

React JS - Difficulty when combining toggle drawer and resize functionality in Material UI

Currently, I am working on implementing toggle drawer functionality with resizing in React JS and Material UI. The reference code I found utilizes a class-based component, which can be viewed here. I am attempting to achieve the same outcome using functio ...

Changing between two images using HTML and CSS

I am currently designing a WordPress theme and I would like to create an effect where two different thumbnail images switch on hover. The code that I have come up with so far looks something like this : <a class="thumb" href="posturl"> <img src= ...

MUI: A Fragment cannot be used as a child for the Menu component

Developed a Menu component with 3 menu items that are conditionally rendered, but encountering an issue where 'MUI: The Menu component doesn't accept a Fragment as a child. Consider providing an array instead.' keeps showing up on the consol ...

Tips on adjusting the width of a Material widget in Flutter

I am facing an issue with setting the width attribute for a Material widget that wraps a MaterialButton. Even after trying to use a SizedBox, the Material widget continues to occupy all the space on the screen. Here is the code snippet: return new SizedB ...

Implementing lodash debounce on a React input field handling function

import _, { debounce } from 'lodash'; Can you explain the process of using debounce in lodash? I would like to have a function call triggered two seconds after a key press event. const handleChange = (event, onChange) => { try { ...

Arranging and overlaying images with HTML and CSS

Currently, I am in the process of developing a simplistic game through the use of HTML and CSS. The game consists of a background image portraying an alleyway, and my objective is to incorporate additional images on top of this background as clues within t ...

Crafting an interactive saturation effect for mouseover interactions in a circular design

I'm looking to create a unique hover effect for my images. I have both a desaturated version and a full color version of the same image. My idea is to have mousing over the desaturated image reveal a circle spotlighting the color version underneath, a ...

Bootstrap slider aligned to the right side

I'm currently utilizing bootstrap 3 for my website. However, I encountered an issue with the slider when viewing the page on a mobile device as the image was displaying outside the viewport, shifted to the right. Additionally, in Firefox, the slider ...

What is the appropriate event type to pass to the onKeyPressed function in a React application utilizing MaterialUI and written with Typescript?

I am currently working on a React application using Typescript and MaterialUI, where I have implemented a TextField component. My goal is to capture the value of the input HTML element when the user presses the enter key. To achieve this, I have created ...

I am in the process of creating several checkboxes and am looking to incorporate some added functionality

Currently, I am working on a project that involves creating multiple checkboxes. My goal is to implement a specific functionality where only one checkbox can be checked in each group with the correct or incorrect value. Once all groups have been selected, ...