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

I'm currently working with ReactJS and attempting to retrieve JSON data from a REST API in JIRA, but I'm facing challenges in achieving this

I've been struggling for hours trying to understand why I am unable to access and transfer data in my array from the JSON data in JIRA using the REST API. Basically, I am attempting to retrieve the JSON data from the JIRA website via URL with Basic Au ...

To show the selected value in a radio button in a React JS Material UI design, simply click on the radio button to display the corresponding value

Exploring the world of React JS and Material UI design, I find myself in need of something similar to what's shown below. My goal is to have the value 1 displayed inside the selected radio button upon clicking it. So far, I've managed to implem ...

Form fields do not pass validation when accessed via mobile devices

ISSUE: Successful form validation and async requests on desktop, but not functioning properly on mobile devices. TECHNOLOGY USED: Implemented nextjs, formik, and yup for the solution. DESCRIPTION: Developed a user-friendly form submission site that oper ...

I encountered an issue after initiating my React app with the command "npx create-react-app my-app" as running npm start resulted in an ELIFECYCLE error. How should I proceed to resolve

I've been working my way through the official React tutorial and decided to use my own text editor instead of the suggested one. I followed all the instructions until it came time to create my app using "npx create-react-app my-app". However, when I t ...

Bring in an asynchronous function from another file to the component

Experiencing difficulties with learning NextJs, particularly async await for fetching data from Shopify. In my file library.js, all queries are stored: const domain = process.env.API_URL const storefrontAccessToken = process.env.ACCESS_TOKEN async funct ...

The onSubmit function in Formik fails to execute if there are no input values present

I am currently working on building a form using Next.js, TypeScript, and the Formik + Yup libraries. I've encountered two scenarios: one where an input field is visible and Formik captures the value, and another where the input is not visible and the ...

Having difficulties in setting up a new application with the "create-react-native-app" command

Up until today, I have never faced any problems while using the "create-react-native-app" cli command to create react-native apps. However, a new issue arose when it did not generate the usual ios and android files but only the node_modules, package-lock.j ...

Incorporating a TypeScript module into a JavaScript module within a React application

I'm encountering an issue with my React app that was created using create-react-app. I recently added a Typescript module to the project, which is necessary for functionality reasons. Although it will remain in Typescript, I made sure to install all t ...

Is it a bug that using addClass or toggleClass with JQuery inside a click method does not seem to be functioning properly?

This appears to be a simple issue, yet it is not functioning correctly. I managed to make it work by placing the .normal class above the .highlight class, despite only adjusting the position and not altering the style. This lack of logic is puzzling. Sin ...

Utilize MUI styles on elements that are not originally styled by MUI

I am working on a Gatsby application that utilizes MUI v5 and allows users to input custom markup. I want the user-entered markup to have the same base styles as the corresponding Typography elements (as shown below). How can I make this happen? It is wor ...

Material-UI's Select component does not support using a Fragment as a child element. It is recommended to provide an array of elements instead

Dealing with Material UI, I encountered an issue: index.js:1 Material-UI: the Select component is not accepting a Fragment as a child. It's recommended to provide an array instead. Here is my code snippet: import { Container, Grid, Select, MenuItem ...

Updating React Form State with Redux Props

I have a custom component that receives data from its parent using Redux. This component is responsible for managing a multistep form, allowing users to go back and update input fields in previous steps. However, I'm facing an issue with clearing out ...

The JQuery code is failing to remove the dynamically added field when the delete icon is clicked

Information: I am currently navigating the world of programming and attempting to build a To-Do List feature. When the create list button is clicked, a dynamically generated div with the class 'wrap' is created. This div contains two nested divs: ...

Columns in Bootstrap4 housing elements positioned absolutely

Recently, I've been developing a game that involves using absolute positioning for certain elements. This is necessary for creating moving animations where elements need to slide around and overlap to achieve a specific effect. As I focus on optimizi ...

What is the best approach to animating a specified quantity of divs with CSS and javascript?

How neat is this code snippet: <div class="container"> <div class="box fade-in one"> look at me fade in </div> <div class="box fade-in two"> Oh hi! i can fade too! </div> <div class="box fade-in three"& ...

Is there a peculiar issue with CSS float:right in IE9?

These are the styles I'm using: For the parent container: div.musicContainer { width:820px; height:54px; margin-bottom:20px; } And for the child containers: div.hardcorePlayer { width:400px; float:left; border:n ...

Ways to customize the appearance of a search box

I am looking to revamp the appearance of a search bar that currently looks like this: <div class="searchbase input-group animated trans" id="searchbase"> <input type="text" placeholder="<?php _e(_l('Searching...'));?>" class=" ...

Error: Invalid hook calls detected in React using Material-UI components

Hey there! I'm relatively new to the world of React and I've been tackling an issue with implementing the SimpleBottomNavigation component. Unfortunately, I keep running into an error message that says: "Uncaught Error: Invalid hook call. Ho ...

utilize a Node module in React

After installing react-awesome-query-builder from branch antd-3, I encountered an error upon importing it in my React file. The error message reads: import {Query, Builder, Utils as QbUtils} from 'react-awesome-query-builder'; Error : Failed to ...

How can I connect the box using the Interactive Picture jQuery tool?

When using the Interactive picture jQuery, I have the following code snippet within my document: jQuery(document).ready(function(){ $( "#iPicture6" ).iPicture({ animation: true, animationBg: "bgblack", animationType: "ltr-slide ...