The presence of the target tag remains unchanged when a media query is used

Hello, I have a question regarding a specific issue in my code. I am trying to use a media query to make a tag disappear when the width of the window is less than 1200px, but it's not working as expected. I believe it might be related to inheritance. Can you please advise me on how to solve this problem?

This pertains to the NaviSearch.jsx file where I want to hide the top tag

import React from "react";
import "../navi.css";
import pencil from "./images/pencil.png";
import { Link } from "react-router-dom";


function NaviRecent (props) {
  return (
    <Link to="/login" style={{textDecoration : 'none'}}>
      <button id="NaviRecent">
        <img src={pencil} id="NaviRecentImage"/>
        <span id="NaviRecentText">최근강의</span>
      </button>
    </Link>
  );
}

export default NaviRecent;

The following snippet is from the CSS file, focusing only on relevant parts:

#Navi {
  position: sticky;
  background-color: #fff;
  width: 100%;
  height: 64px;
  top: -1px;
  z-index: 5;
  box-shadow: 0 2px 4px 0 hsl(0deg 0% 81% / 50%);
  width: 1263.330;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}


#NaviRecent {
  border: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  position: relative;
  right: 20px;
  width: 100px;
  height: 30px;
  padding: 8px;
  background: #00c471;
  color: #fff;
  border-radius: 4px;
}

#NaviHiddenLogo {
  display: none;
}

#NaviRecentText {
  box-sizing: border-box;
  color: white;
  cursor: pointer;
  font-family: Pretendard,-apple-system,BlinkMacSystemFont,system-ui,Roboto,Helvetica Neue,Segoe UI,Apple SD Gothic Neo,Noto Sans KR,Malgun Gothic,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,sans-serif;
  font-size: 16px;
  font-weight: 600;
  margin-left: 4px;
}

#NaviRecentImage {
  width: 15px;
  height: 15px;
}


@media screen and (max-width: 1020px) {

  #NaviRecent {
    display: none;
  }


}

Answer №1

It's important to encapsulate the content in a specific tag, such as:

import React from "react";
import "../navi.css";
import pencil from "./images/pencil.png";
import { BrowserRouter as Router, Link } from "react-router-dom";

function NaviRecent(props) {
  return (
    <Router>
      <Link to="/login" style={{ textDecoration: "none" }}>
        <button id="NaviRecent">
          <img src={pencil} id="NaviRecentImage"/>
          <span id="NaviRecentText">최근강의</span>
        </button>
      </Link>

    </Router>
  );
}

export default NaviRecent;

Please note that in your CSS file, the max-width is set to 1020px and not 1200px as mentioned in your statement. I hope this information proves useful.

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

What could be causing the padding of my anchor element to extend outside the boundaries of its parent list

In the provided images, it is evident that the <li> element is failing to expand and is disregarding the padding of the parent element.</p> <p><a href="https://i.stack.imgur.com/4ZH65.png" rel="nofollow noreferrer"></a></p& ...

designing the border at the bottom of the existing menu selection

I am trying to enhance the look of my current-menu-item div by adding a border at the bottom. It seems simple enough to achieve this by simply including the border in the div. However, I'm facing an issue with the width and position of the border. Ide ...

Encountering an error in React when attempting to convert a class component to a function

As I've been converting my class components to functions, I encountered a hook error related to my export default. Although I believe it's a simple issue, I can't seem to find the solution I need. The following code is where the error occur ...

The function cannot be applied to the size of the map within the action payload

Is there a way to replace the for loop with the map method? The data structure for book.pages is in the format [{},{},{}] I tried using the size method and included this line console.log("book.pages.map.size();--->", book.pages.map.si ...

Using JavaScript to dynamically load Cascading Style Sheets based on the current

I am trying to dynamically load different CSS files based on the current date (season). I attempted to tweak an image script that I found on Stack Overflow, but it didn't yield the desired result. Could someone please guide me on where I might be ma ...

Troubleshooting image alignment problem within a flexbox display

Is there a way to align the two images so that the bottom right of the first image meets the top left of the second image? I'm struggling to figure out a solution, especially considering different browser sizes. Any advice or suggestions? .flexbox ...

Endless re-renders induced by React-Table

While experimenting with a component that includes a table, I decided to give the react-table package a shot. The large component below is triggering endless calls to getRowModel. Additionally, there is a useEffect present to track re-renders unrelated to ...

Getting some clarity on how to structure a project using Node.js, Express.js, and React.js

I am in the process of developing a website for online shopping purposes, essentially an e-commerce platform. However, I am facing a dilemma where create-react-app sets up its own Node.js server to communicate with my backend (which handles MySQL queries) ...

The reactivity of the state in useReducer seems to be inadequate

I have been thinking about creating a React store similar to Vuex. My idea involves having a wrapper component that takes an object of values and uses useContext to provide an object back with a state and set for each key in the object. For instance, by w ...

Customize each Picker.Item element in React Native with unique styles

How can I style individual Picker.Items beyond just changing the text color? Additionally, what other props can be used for a Picker.Item? I am aware of "key", "value", "label", and "color". Are there any additional props available? I want to customize o ...

What is the reason for next-redux-wrapper double hydrating in the logger?

I am encountering difficulties while using next-redux-wrapper with nextjs and I need some clarification on the concept of Hydrate between server and client. Recently, I have started learning nextjs with next-redux-wrapper and redux-toolkit packages. After ...

Instructions on integrating iframe into Slides on material-auto-rotating-carousel

Looking to swap out the carousel slide image with a loom video. Any ideas on how to replace the media img with an iframe in material-auto-rotating-carousel? const AutoRotatingCarouselModal = ({ handleOpen, setHandleOpen, isMobile }) => { return ( ...

Updating the status of a checkbox array within the reducer to reflect changes made in the user interface

I've implemented something similar in React: const CheckboxItems = (t) => [ { checked: true, value: 'itemsCancelled', id: 'checkBoxItemsCancelled', labelText: t('cancellations.checkBoxItemsCancelled&apos ...

Utilize Sass @extend to incorporate imported CSS files in the build process

In my development setup, I have a global CSS file that houses all of the generic CSS styles. My goal is to extend the classes from this global CSS file in any of my SCSS files. However, when I attempt to do so, I encounter an error stating that the .xyz c ...

The Type {children: Element; } is distinct and does not share any properties with type IntrinsicAttributes

I am encountering an issue in my React application where I am unable to nest components within other components. The error is occurring in both the Header component and the Search component. Specifically, I am receiving the following error in the Header co ...

Here's a unique version: "Utilizing the onChange event of a MaterialUI Select type TextField to invoke a function."

I am currently working on creating a Select type JTextField using the MaterialUI package. I want to make sure that when the onChange event is triggered, it calls a specific function. To achieve this, I have developed a component called Select, which is es ...

Utilizing Reactjs in combination with Azure services

I am currently facing an issue with my webApp created using Nodejs 8.1. After uploading my code via a zip file, I successfully ran npm install and start in the kudu command line debug console. Despite these steps, my website is still not visible. It's ...

The error message TS2322 in MUI v5 states that the property 'fullWidth' is not found in the type 'IntrinsicAttributes & { theme: Theme; } & { children?: ReactNode; }'

As a user of MUI v5, I have implemented a straightforward FormControl as seen below. It is important to note that the property fullWidth is supported according to the official documentation. import React, { PropsWithChildren } from 'react' import ...

What is the best way to define a React Component that has been imported from a library?

In my React project, I am utilizing the `material-ui` library and attempting to integrate Flow into the codebase. Here is a sample snippet: import Paper from 'material-ui/Paper'; type Props = { ruleName: string, rules: Object[], actions: ...

Managing Multiple Actions in Redux

What happens in redux when multiple actions are dispatched simultaneously to the same object in the store? For instance, if there are two different data streams being subscribed to and each time new data is received, a handler function is executed. This h ...