Combining BackgroundImage and Overlay in React for a Stylish Overlapping

I was looking to add a background overlay on my background image. Below is what I was trying to achieve:

https://i.sstatic.net/NaZ6L.png

Please take a look at my codesandbox as well

Click here

 image: {
    backgroundImage:
      "linear-gradient(0deg, rgba(255, 0, 150, 0.3), #06a303), url(http://lorempixel.com/800/600/nature/2)",
    backgroundRepeat: "no-repeat",
    backgroundSize: "cover",
    backgroundPosition: "center"
  },

Answer №1

Create a stunning effect with a subtle gradient, set to black at 50-60% opacity, layered over your background image. Make sure the text is in white and add some padding for a nice finishing touch.

backgroundImage:
  "linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url(http://lorempixel.com/800/600/nature/2)",

https://i.sstatic.net/Gxhz6.png

Sample Code Snippet:

const useStyles = makeStyles((theme) => ({
  ...
  image: {
    backgroundImage:
      "linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url(http://lorempixel.com/800/600/nature/2)",
    backgroundRepeat: "no-repeat",
    backgroundSize: "cover",
    backgroundPosition: "center",
    color: "white",
    padding: "1rem"
  },
  ...
}));

https://codesandbox.io/s/overlap-backgroundimage-with-overlay-in-react-hilx7?fontsize=14&hidenavigation=1&theme=dark

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

Attempting to achieve CSS shadows on both the right and left sides of the element

I am struggling to apply a CSS box shadow to a DIV element. Specifically, I want the shadow to appear only on the left and right sides of the element. I have tried using the following code: box-shadow: 0 0 10px #000; However, despite my efforts, the shad ...

The suspense fallback feature seems to be missing in NextJS 13 when using the useRouter() for navigation

Seeking to update the search parameters of a route using the useRouter hook. I have created a basic program to demonstrate this. //page.tsx import { Suspense } from "react"; import ClientComponent from "./client-component"; import Serve ...

Problem with Active State of DOM Element

My goal is to create an effect where clicking on a DOM element, specifically a list, will cause the target list to rotate and remain in that position. Describing it can be a bit challenging, so I have provided a visual example of what I'm working on ...

What is the best way to remove an item from an array?

I'm currently working on implementing a follow/unfollow feature on my page using React/Redux. However, I am struggling to fully grasp how to achieve this. When the user follows 'something', the reducer does the following: case FOLLOW_CITY: ...

Height of inline-block list items in ul is not properly adjusted

I am working on a horizontal navigation bar using inline-block for the li tags. Here is the code snippet: <ul> <li><a href="#">HOME</a></li> <li><a href="#">FEATURES</a></li> <li><a href ...

Adjust the placement of the material autocomplete popup icon

I am currently seeking a solution for adding a unique button to the end of a material autocomplete feature. The issue I am facing is that the popup icon is styled to appear at the end of the autocomplete input which complicates adding a button in that posi ...

Align the radio buttons vertically

My goal is to align all my buttons vertically, similar to the first question. However, I'm struggling to get the second question to align correctly. Despite trying different methods like using the vertical-align: middle property, nothing seems to be w ...

"Utilizing SVG format to manipulate text, adjusting font size within tspan elements

There seems to be an issue with the font size on SVG. Even though both the SVG and paragraph have a font-size of 16px, they appear different. I would like the font size in the SVG to match that of the paragraph. Another concern is how to center <tspan ...

The web browser's engine is blocking the connection to the secure websocket server

Summary of Issue An error message stating "Websocket connection failed." appears in the browser console (Chrome or Brave) when trying to run this code: const ws = new WebSocket("wss://abcd.ngrok-free.app/") (Please note that the URL mentioned is not real ...

I'm encountering a TypeError where setGameState is not recognized as a function. Any suggestions on how to resolve this

Question about MainMenu.js file in reactjs import React,{ useContext, useState } from "react"; import { QuizContext } from "../Helpers/Contexts"; export default function MainMenu() { const {gameState, setGameState} = useState(QuizCont ...

Tips for arranging datasets in React Chart.js 2 to create stacked bar charts

Currently, I am facing an issue with sorting the datasets displayed in each stacked bar chart in descending order as they are showing up randomly. Here is the snippet of my code: import React from 'react'; import { Chart as ChartJS, CategoryS ...

Javascript code fails to execute properly on IE8

I have a scenario where I am working with two drop-down menus. When the user selects an option from one menu, it should dynamically change the options in the other menu. However, I'm facing an issue with Internet Explorer where the second drop-down me ...

Leverage CSS to generate a visually appealing table of contents incorporating images and text blocks, perfectly aligned for an enhanced

I am in the process of designing a unique clip showcase on my website. The concept involves creating a table-like structure with a thumbnail image on the left and various information on the right, including a title, publication source, date, and descriptio ...

How can you combine accessibility with absolute positioning?

Have you seen our unique hamburger design? https://i.stack.imgur.com/AmT6P.png A simple click will reveal a neat popup (the class "open" is added to a div). https://i.stack.imgur.com/yPydJ.png This cool effect is achieved using fixed positioning, but i ...

Could someone confirm if this NextJS scss module is functioning correctly, or is there an issue on my end

Within my project, I am utilizing a pagination.tsx component in conjunction with a pagination.module.scss file which houses the following styles: .pagination { ul { display: inline-block; padding-left: 0; margin: 20px 0; border-radius: 4p ...

What is the best way to achieve this Bootstrap design without copying the content?

Trying to achieve a specific Bootstrap layout without repeating content is my current challenge. Essentially, I aim to divide some content into 2 columns at the sm/md breakpoints and then switch to 3 columns for the lg breakpoint. The layout for sm/md bre ...

Having images that are too large in size and using a high percentage can

I'm encountering a strange issue. When I define the width and height of my images in pixels in my CSS file, all my jQuery animations and events work perfectly fine. However, when I switch to using percentages or 'auto' for the image dimensio ...

Display <div> exclusively when in @media print mode or when the user presses Ctrl+P

Looking for a way to create an HTML division using the div element that is only visible when the print function is used (Ctrl+P) and not visible in the regular page view. Unfortunately, I attempted the following method without success. Any advice or solut ...

How to write OpenLayers controls using JSX format

Utilizing OpenLayers within my React project, I created a new component for map controls. Basic controls like the full-screen control were implemented as follows: import { useContext, useEffect } from 'react'; import { FullScreen } from 'ol/ ...

Deleting elements along with their associated entries in a join table using express.js and react.js

My current project involves managing two main tables: Contacts and Workers. Additionally, I have a join table named WorkerContacts in use. In the context of my project, users are able to delete contacts. This operation also requires deleting associated e ...