Creating custom styles with makeStyles in Material UI

How can I properly write the following CSS value as a string in a makeStyles function within Material UI?

background: linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.8)),
    url(../assets/pexels-pixabay-41949.jpg),

I attempted to do it this way but it was incorrect

background: 'linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.8)),
    url(../assets/pexels-pixabay-41949.jpg)',

Answer №1

To achieve this, utilize Template literals to handle the process. Firstly, assign the URL to a variable, and then construct the desired CSS property.

const url = "https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80";
const useStyles = makeStyles(() => ({
    boxBackground: {
    background: `linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.8)),url(${url
})`,
    },
  }));

You can find a working example at this CodeSandbox link.

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

There is no compatible version available for [email protected]

While executing npm install npm ERR! code ETARGET npm ERR! notarget No matching version found for <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a7d6f766a37e61767776">[email protected]</a> npm ERR! notarget In m ...

Unable to attach a tooltip to a list item

As an Angular developer, I am working on a list element that displays all the cars and I am looking to add a tooltip to enhance its visual appeal. Here is what I have attempted so far: I created a span tag with the class "tooltip" to wrap around the ul el ...

Issue with react-bootstrap-table2: Pagination dropdown feature malfunctioning

I am having trouble with the pagination drop down in react-bootstrap-table2. Here are my options: const options = { paginationSize: 4, pageStartIndex: 0, //alwaysShowAllBtns: true, // Always show next and pre ...

Tips for maintaining a loading screen for longer than 4 seconds?

I want to maintain the loading screen for a minimum of 4 seconds. However, the timer at the end does not seem to be functioning as expected. Here is the code snippet I am using: window.addEventListener("load", () => { const preload = document.querySe ...

Different ways to personalize Material UI select

I'm currently working on enhancing the design of a material-ui dropdown menu, aiming to achieve a specific look. You can preview what I have so far by visiting this link: https://codesandbox.io/s/busy-black-2fgdn?file=/src/App.js. My goal is to enabl ...

What is the best way to adjust the footer width to match the sidebar using Bootstrap 5?

Currently working on a Bootstrap 5 template for my website, but being new to it makes it a bit challenging. Specifically struggling with aligning the footer to fit the full width of the sidebar. <!DOCTYPE html> <html lang="en"> <head&g ...

When multiple files are used, .env does not return any values

Having trouble with two files utilizing .env, as both are returning undefined for variables. I attempted setting a root .env file for both the front-end and backend, but still facing issues with loading the .env variables. In the frontend, any .env variab ...

Is there a way to display tags on hover and darken an image on hover as well?

Currently, I am using a theme that does not include the feature to display tags when hovering or darken images and gifs on hover. You can view the theme here. I would like to modify my theme to show tags similar to this example theme: If anyone could ass ...

How can I apply a blurred effect to the background image of a jumbotron in Bootstrap-vue without affecting the clarity of the text overlay

I need help figuring out how to blur the background image of my jumbotron without blurring the text on top. <b-container fluid class="text-center"> <div> <b-jumbotron class="jumbotron"> <p style=& ...

Contrasts between space and the greater than selector

Can you explain the distinction between selector 6 and selector 7 as outlined on the w3 website? Inquiring minds want to know. ...

Creating an Interactive Menu System with Nested Options in Angular 2

I have a JSON structure that I need to transform into a menu with sub-menus based on the value of the sub-menu_location field. Here's an example: { "data": [ { "menu_name": "Primary Operations", "enabled": true, "sub-menu_lo ...

Setting the value for datepicker and timepicker in ReactJS for individual rows

Can you please explain how to set a default value for the datepicker and timepicker in each row? I have successfully implemented the datepicker and timepicker functionalities in my code. In the home.js file, there is a state called additionalFields which ...

Guide to integrating the Roboto font into a webpack build for Material UI

How can I include Roboto fonts in my progressive web app, based on Material UI (React) and built with Webpack, without depending on Google servers and ensuring the fonts work offline? The installation page for Material UI just directs users to the Goog ...

The interfaces being used in the Redux store reducers are not properly implemented

My Redux store has been set up with 2 distinct "Slice" components. The first one is the appSlice: appSlice.ts import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import type { RootState } from "./store"; export interface CounterState { value ...

AWS Amplify deployment has revealed React source code

I recently tested the deployment of an app on AWS amplify and here are the steps I took: Started by creating a sample create-react-app, which I named deploy_test, Afterwards, I pushed the code to a GitHub repository, In the AWS Amplify console, I deployed ...

Changing from system mode to dark mode or light mode

Within my Next.js web application, I am implementing MUI to facilitate the transition between system, light, and dark modes. Persistence between sessions is achieved by storing the selected theme in local storage. The user has the option to change the them ...

Creative CSS spinners design

Seeking assistance to modify my spinner design. I want one end to be thicker and the other end to be thin. My attempts so far have been unsuccessful. <div id="data-loader"> <div class="loader"> <div class="blue"></div& ...

Transitioning the CSS background for a lightbox display

I am currently experimenting with creating an image that fades in along with its background when clicked using the :target selector. (Similar to Lightbox: , but done purely with CSS). Here is the HTML: <a href="#firstimg"><img src="img/thumb-3.j ...

Error: The window object is not defined in NextJS

I've encountered an issue while trying to build the app for production. The error message states: ReferenceError: window is not defined. I'm struggling to find a solution. FullCode: const [windowSize, setWindowSize] = useState<WindowInfo>( ...

Utilizing Flask to insert data into a MySQL database table

Hey there, I'm running into some trouble with inserting values into my database. While I can successfully log in using the same method on the sign-up page, I've tried various options without success. Below is my Python code: from flask import F ...