What is causing the issue with CSS properties and media queries not being effective on specific elements?

I have been experimenting with React and SCSS to create a portfolio page. Although I am familiar with these tools, I recently encountered issues where certain style changes were not reflecting in the browser.

One specific problem involved styling the header element with a nested nav element. Despite adjusting the 'color' property for the h4 and li elements in my code, nothing seemed to change. There are no errors in my SCSS file, and I've tried different browsers and cleared caches to no avail. This roadblock is hindering my progress on this project.

//Here is the react code

export default function Header() {
    return (
        <>
        <header>
            <nav>
                <h4 className="color">
                    <NavLink to='/'>Chidera</NavLink>
                </h4>

                <ul class="nav-links">
                    <li><NavLink to='/'> Home</NavLink></li>
                    <li><NavLink to='portfolio'> Portfolio</NavLink></li>
                    
                </ul>

                <div class="burger">
                    <div class="line1"></div>
                    <div class="line2"></div>
                    <div class="line3"></div>
                </div>
            </nav>
        </header>
        <Outlet/>
        </>
    )
}

//SCSS code

 header {
        width: 100%;
        height: 10vh;
        display: grid;
        place-items: center;

        nav {
            width: 80%;
            height: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;

            h4 {
                font-size: 1.2rem;
                color: gold;
                font-style: italic;
                background-color: #48ff00;
            }

            ul {
                display: flex;
                justify-content: space-between;
                align-items: center;
                width: 40%;
                color: white;
                padding: 0 1rem;

                li {
                    color: white;
                    background-color: #1906cc;
                }
            }

            .burger {
                cursor: pointer;
                display: none;

                div {
                    width: 25px;
                    height: 3px;
                    background-color: rgb(221, 168, 90);
                    margin: 5px;
                    transition: all 0.3s ease;
                }
            }
        }
        
    }

I also noticed that some media queries weren't working as expected, such as displaying the burger element when the device width is below 800px. This issue persists even though there are no errors in my SCSS code. It seems strange that changing the background color of the main element worked, but toggling the visibility of the burger did not, despite following the same nesting structure as in the React component.

@media screen and (max-width: 768px) {
    main {
        background-color: pink; //works
    }
    .burger {
        display: block; //does nothing
    }
}

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

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

The developer's tools indicate that the color property has been recognized in the second image, yet the changes do not appear on the actual page. Additionally, while the main background color successfully changed, the burger element remains invisible.

I hope this issue isn't related to SCSS, as I prefer not to revert back to plain CSS. Your assistance is greatly appreciated.

Thank you.

Answer №1

NavLink and Link from 'react-router-dom' come with their own default styles that cannot be overridden by the CSS properties of h4 and li. To directly modify the styling of NavLink and Link, you will need to target them specifically.

The first step is to remove the color property from h4 and li elements:

<h4 className="color">
     <NavLink to="/" className="colorGold">Chidera</NavLink>
 </h4>

CSS

.colorGold {
  color: gold;
}

Styling for the li element:

<ul className="nav-links">
      <li>
           <NavLink to="/" className="listColor">Home</NavLink>
      </li>
      <li>
           <NavLink to="/portfolio" className="listColor">Portfolio</NavLink>
      </li>
</ul>

CSS

.listColor {
  color: white;
}

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

css determining the width through calculation

I am facing a challenge with a math problem. My content box is 700 pixels wide, and my hentry (inside content) is 100% wide with padding of 10 pixels. This causes the hentry to be wider than the content, resulting in an overflow... Does anyone have a so ...

Unable to edit the current value of an input component in ReactJS

I need to implement a search feature for a list of items using ReactJS. You can view the project on JSBIN. The issue I am facing is that when I input 'mi' in the search box to filter by ID, the filtration works correctly but the input value does ...

What are the best practices for integrating Firebase authentication pre-made UI in Next JS?

As someone new to React and NextJS, I am eager to implement an authentication service for my NextJS web application in order to manage user accounts efficiently. I am particularly interested in utilizing a familiar user login solution that offers a compre ...

Avoid wrapping elements

Is there a foolproof method or best practice to prevent an HTMLElement from wrapping? Specifically, I'm referring to elements with relative positioning. One possible solution could be using absolute elements and adjusting their left position based on ...

I am attempting to import the navbar component and use it, but I continue to receive a warning that it is not being used

I am trying to import the navbar component and use it, but for some reason it is not showing up when I try to use it and I am still getting a warning that I never used it. Can someone help me figure out why? //navbar.js import React from 'react' ...

Choose all the items that share a specific hue?

How can I target all elements with a specific color? I need to update all text that has a color of #1a0dab to #00b0f4. ...

Guide to customizing action button color on MatSnackbar?

Currently, I am encountering an issue with the snackbar in my Angular 9 project. Despite adding CSS styles to both the component.scss file and the global style.scss file, the action button on the snackbar displays the same background and text color. In an ...

Excessive content spilling over into the footer area due to an integrated forum feature within

We have integrated a Muut forum into our website, and it is working well when embedded in a coding block within the page's body. However, there is an issue where the sidebar of the forum gains extra features when logged in as an admin. This causes the ...

Is it better to import and use useState and useEffect, or is it acceptable to utilize React.useState and React.useEffect instead?

When I'm implementing hooks for state, effect, context, etc, this is my usual approach: import React, { useState, useEffect, useContext } from 'react'; However, I recently discovered that the following also works perfectly fine: import Re ...

Custom React components are not designed to handle multiple onClick events simultaneously

One of my custom button components looks like this: export const Button = ({ children, onClick, className, ...props }: IButton) { const [selected, setSelected] = React.useState('primary') const handleSelected = () => { setSele ...

Struggling to set up a full-page video background in Next.js, only to end up with a frustrating blank

I need assistance with implementing a full-page video background on the homepage of my Nextjs application. Currently, all I see is white space where the content should be displayed. As a newcomer to Nextjs, I believe I may have overlooked something obviou ...

Safari not fully supporting CSS translate functionality

When I click a button on my app, an element slides into view and then slides out when I click the button again. This is achieved using a combination of CSS and JS. It works perfectly in Chrome and Firefox, but only partially in Safari. In Safari, the elem ...

Get rid of all the formatting on an HTML button or submit

Is there a method to entirely eliminate the styling of a button in Internet Explorer? I am utilizing a CSS sprite for my button and everything appears fine. However, when I click on the button, it shifts slightly upwards which distorts its appearance. Are ...

Placement Mismatch of Radio Button in Form.Check Component of React-Bootstrap

Recently, I've been working on implementing a payment method feature where users can choose their preferred payment option using radio buttons. However, there seems to be an issue with the alignment of the button. Below is the code snippet I have so ...

What is the most effective way to store data in React Native - by caching or using local storage

I am integrating an external country API to fetch all country details. Considering that the country data is not expected to change frequently, my goal is to minimize API calls by allowing each user to access the API only once a day. If a user opens the ap ...

React Native displaying identical path

Is there a way to dynamically change routes in React Native when a button is pressed? Inside my SplashContainer component, I have the following method: handleToSignUp = () => { console.log("Running handleToSignUp") this.props.navigator.push({ ...

Conceal a Column within the Material UI Data Grid

I have managed to hide the id on the columns but it is still visible in the filter. Is there a way to also hide it from there? CLICK HERE const userColumns = [ { field: "id", hide: true }, { field: "name", headerNa ...

Using a 90% zoom level in the browser does not trigger any media queries

When addressing the width of a specific class, I utilized CSS media queries as shown below: @media (max-width:1920px) { .slides { width: 860px; } } @media (max-width:1500px) { .slides { width: 852px; } } @media (max-width:1 ...

Css shaky letters transformation

[SOLUTION] To resolve this issue, you can utilize the will-change CSS property that enforces GPU rendering: will-change: transform; [ORIGINAL QUESTION] After extensive searching on the internet, I have yet to find a solution to a seemingly simple prob ...

jQuery function to automatically close any other opened divs when a new div is opened

I have multiple elements that reveal a div when clicked. The issue is that if all elements are clicked, all divs open instead of just the one that was clicked. This is my jQuery code: <script> $(document).ready(function() { $('.servicemark ...