What is the best way to achieve a transparent background for an element?

Having trouble making elements transparent in the background for mobile view with React.

I've attempted adding background-color and background with a value of transparent to various classes, but it's not working as intended. Any suggestions on how to resolve this?

Check out the standard view here: https://i.sstatic.net/tdJL9.png

And the mobile view here: https://i.sstatic.net/uzXOw.png

Here's the JavaScript code:

export const NavBar = () => {
  return (
    <nav className="flex custom-nav">
      <ul className="nav-list flex">
        <li><a href="#">Home</a></li>
        <li><a href="#">Skills</a></li>
        <li><a href="#">Projects</a></li>
      </ul>
      <span className="social-icon-list">
          <a href="#"><img className="social-icon" src={socialIcon1} 
          alt=""/></a>
          <a href="#"><img className="social-icon" src={socialIcon2} 
           alt=""/></a>
        </span>
      <button>Let's Connect</button>
    </nav>
  );
}

CSS for the JavaScript file:

* {
    font-family: Centra, sans-serif;
    margin: 0;
    padding: 0;
}

// Additional CSS rules ...

@media (max-width: 44em) {
    .custom-nav {
        position: fixed;
        inset: 0 0 0 30%;
        background: aqua;
        flex-direction: column;
        justify-content: start;
        align-items: center;
        padding: 0;
        margin: 0;
    }

    // Additional media query rules ...
}

CSS for the entire application:

* {
    background-color: #262626;
}

Answer №1

The issue lies within the following code snippet:

* {
    background-color: #262626;
}

This code sets the background color for absolutely everything, so you will need to override it for each element individually.

If you want a uniform background, it is best to set it on your root element only. Typically, using html or body as containers works well:

body {
    background-color: #262626;
}

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

waiting for udp response in node.js using express

Currently, I am diving into the world of node.js programming and have encountered a challenge. While working with express, I came across an issue. When a POST request is made, it triggers a radius authentication process over UDP using the dgram module. Ho ...

Is there a way in CSS to apply multiple colors to individual letters within a word?

Is it possible to add random colors to every pixel of a letter or multiple colors to a letter using CSS? Check out this example. ...

React component failing to render even when event is triggered

For my latest project, I am creating a blog using react, next.js, and json-server. The blog is coming along nicely with dynamically loaded blog posts and UI elements. However, I've hit a roadblock when it comes to loading comments dynamically. The sp ...

How can I ensure that Redux-saga waits for API calls to resolve instead of returning promises continuously? Is there a way to make "yield call" wait for API calls to complete?

Where I'm initiating the API request: function fetchCharacter(value){ return axios.get(`https://www.breakingbadapi.com/api/characters?name=${value}`) .then(res=>{ console.log(res.data) }) .cat ...

How do I stop Bootstrap from taking over my custom navbar design?

My website's navbar stopped working after adding Bootstrap to my HTML pages. I suspect that Bootstrap is overriding my custom CSS. Here is the code for my navbar: .navbar { overflow: hidden; !important; background-color: #333; !important; } .. ...

When using React, it is common to nest multiple map or filter functions inside each other for

Is it possible to execute a map or filter within another map function? I am working with JSON data that contains a menu structure. My goal is to iterate through the JSON and check if the first level has any children. If there are child elements, I want t ...

Customize the appearance of a React component depending on its unique identifier

After creating a simple TODO app with drag and drop functionality, I am now looking to apply a line-through CSS style to any task added or dragged into the second column of my app. What is the best way to target these tasks using their unique ID: <div c ...

Experience a login page similar to Google's with a fully functional back button

I'm currently working on a login page that requires the user to enter their username and have it validated before proceeding. Once the username is confirmed as valid, a new input field for password entry should appear. However, I'm facing an issu ...

Executing a callback in Node.js after a loop is complete

As a newcomer to Node, I have been facing difficulties with the asynchronous nature of the platform while attempting to append data in a for loop of API calls. function emotionsAPI(data, next){ for(let url in data) { if(data.hasOwnProperty(url ...

Is there a way to specify this component without it being nested within the parent element?

So I have this component nested within another one const selectColumn = useMemo<ColumnDef<Person>[]>( () => [ { id: "select", header: ({ table }) => ( <IndeterminateCheckbox {.. ...

Angular 7: Finding the variance between array elements

How can I subtract the values from the first 3 rows of the table? The formula is TVA Collectée - TVA Déductible - TVA Déductible/immo If the result is positive, it should be displayed in the box labeled TVA à Payer. If it's negative, it should g ...

List of shapes and text items

I'm encountering some challenges with my list of shapes - could it be that I am approaching it the wrong way? I could use some guidance on what I am trying to accomplish. Check out My Fiddle CSS: #circle { height: 120px; width: 120px; b ...

The Next.js React app is constantly loading without any interruptions

Just diving into Next.js and attempting to transform a single HTML page into a Next.js website in order to integrate sanity. Managed to import all necessary assets, but stuck with the persistent preloader issue. After inspecting elements, noticed that a fi ...

Guide to linking two variables in Vue.js

I'm working on a project that combines Laravel with Vue. Right now, I'm passing data from the controller to the view in two variables - users and user_data. How can I link these two variables together and display them using v-for? These two tabl ...

Guidelines on fetching API data in React JS

When attempting to retrieve data from the OpenWeather API, I encountered an issue. The API's response is expected to be in JSON format, but instead, I received an error message: SyntaxError: Unexpected token < in JSON at position 0 useEffect(() =& ...

The frosting glass effect blur filter is malfunctioning, resulting in no blurring effect and affecting the content

I need help achieving a background photo with a div in front, featuring a blurry dark background with white text. Currently, the setup shows a dark background without blur and dark text. Can someone please assist me? #section0 { background-color: light ...

Comprehending the inner workings of the reduce() method

After spending hours reading and watching videos to understand the reduce function, I finally had a breakthrough. It wasn't until I took a break, made some food, and came back to my computer that it all clicked. Now, I confidently grasp how the reduce ...

How to trigger a JavaScript function using a button click

I've been struggling to figure out why my JavaScript code isn't functioning properly within Ionic. Can anyone guide me on how to store a number in a variable, display that variable, and increment it when a button is clicked? I have successfully ...

Touchwipe incorporation - single-page website script

Today has been dedicated to troubleshooting and searching for a solution regarding the integration of TouchWipe () on a custom one-page-site script based on Parallax that I found perfect for my latest project (). The script itself performs beautifully wit ...

Transitioning authentication from passport-jwt to passport-google-oauth20

My frontend uses React and the backend is powered by Node/Express. I have implemented two Passport strategies: JWT Google Some users log in with email/password and are authenticated using passport.Authenticate('jwt', {session:false}) , while ot ...