React does not support having two :focus selectors on a single JSX element

I'm working with a React script that includes a specific element. I want to apply more than one :focus-within selector in CSS, but for some reason only the dropdown selector is being expressed when I focus on the element. Here's the code: React JS:

return (
    <div>
      <div className="blind"></div>
      <div className="menufocus" tabIndex={0}>
        <div className="menuicon">
          <FontAwesomeIcon icon={solid("bars")} />
        </div>
        <div className="dropdown">
          <div className="dropitem">HOME</div>
          <div className="dropitem">ABOUT</div>
          <div className="dropitem">NEWS</div>
          <div className="dropitem">ICONHOLDERS</div>
        </div>
      </div>
    </div>
  );

CSS:

  display: flex;
  align-items: flex-end;
  width: fit-content;
  height: fit-content;
  max-height: 1vh;
  transition: max-height 1s;
  overflow: hidden;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: flex-end;
  justify-content: flex-start;
  color: white;
}

.blind {
  z-index: 1001;
  opacity: 0.7;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0px;
  left: 0px;
  background-color: black;
  display: none;
  transition: all 1s;
}
.menufocus {
  z-index: 1002;
  position: absolute;
  top: 0px;
  right: 0px;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: flex-end;
  align-items: flex-end;
  width: fit-content;
  height: fit-content;
}

.menufocus:focus-within .dropdown {
  max-height: 18vh;
}
.menufocus:focus-within .blind {
  display: block;
}

Thank you!

Answer №1

As stated in the official documentation:

The :focus-within CSS pseudo-class selects an element if the element itself or any of its descendants are in focus. Essentially, it targets an element that either matches the :focus pseudo-class directly or has a descendant matching :focus. This includes descendants within shadow trees.

In simple terms, the .menufocus element is only seeking for its children to be focused, and your .blind is signaling to this requirement. Just ensure that it becomes a child of the .menufocus.

Answer №2

Hey there, I've returned, the navigation menu was closed but when you click on the burger icon (those 3 bars), the output should resemble this with a noticeable blur effect in the background.

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

How can I use CSS to conceal the controls for an HTML5 video?

Seeking advice on how to hide and show controls on an HTML5 video section. I currently have a setup where clicking on the video div opens a modal that plays the video in a larger size. The code for opening the modal and playing the video is working fine. ...

Encountering a browserify error while utilizing browserify-rails, react-rails, and material-ui in the

Here is a snippet of code from my gemfile: gem 'react-rails' gem "browserify-rails" source 'https://rails-assets.org' do gem 'rails-assets-material-ui' I am trying to combine react-rails and browserify-rails. Additionally ...

Label text will not be wrapped in front of the label (bootstrap)

I'm struggling with some css coding. I want the text to wrap so the label is positioned on the middle right of the box, similar to this example: . However, currently it looks like this: http://jsfiddle.net/yuvemL1z/ and the label ends up being pushed ...

The entire framework remains concealed as the anchor component becomes immeasurable

Within a fixed-width paragraph, I have an anchor tag. The CSS for the p tag includes the properties text-overflow: ellipsis and overflow:hidden. However, when the anchor tag's content overflows (e.g., it contains a long string), the right outline is n ...

The paths of youngsters and the application of conditional styling

Here is the scenario I am dealing with: <div class="parent"> <div class"routeA"> <div class="header"> <li></li> <li class="p-highlight"></li& ...

Tips for modifying environment variables for development and production stages

I am looking to deploy a React app along with a Node server on Heroku. It seems that using create-react-app should allow me to determine if I'm in development or production by using process.env.NODE_ENV. However, I always seem to get "development" ev ...

The JavaScript code appears to be missing or failing to execute on the website

Encountering a console error while trying to integrate jQuery into my website. The JavaScript file is throwing an error in the console that says: Uncaught ReferenceError: $ is not defined catergory.js:1 Even after following the suggested steps in this an ...

How to change the background color of a slider using jQuery

As a newcomer to web programming, I am currently working on incorporating a slider into my website using jQuery. My goal is to change the background color of the slider to red when the value is less than 5 and green when it exceeds 5. Can this be achieved ...

The changes made in the CSS file are not reflected in the browser

Recently, I encountered a strange issue with my new server where the CSS changes were not reflecting in the browser. Despite trying to refresh and clear the cache, the problem persisted. To investigate further, I used FileZilla to check if the updated CSS ...

Encountering CORS Issue and Unexpected Port Conflict Post npm run build and npm start in MERN Application

Currently, I am working on a MERN stack application and have encountered two key challenges. To begin with, despite setting up my application to operate on port 5000 in production, it persists in running on port 3000 after executing npm run build and npm s ...

Mobile browsers experiencing issues with playing HTML5 videos

Having trouble with HTML5 Video not working on my mobile device? I've encountered several issues when trying to load videos on my mobile browsers. When I attempted to remove controls, the video wouldn't show up on the mobile browser at all. Addin ...

Using React and Typescript, implement an Ant Design Table that includes a Dropdown column. This column should pass

Next Row: { title: "Adventure", render: (item: ToDoItem) => { //<- this item return ( <Dropdown overlay={menu}> <Button> Explore <DownOutlined /> </Button> </Dropdown&g ...

Steps for integrating a valid SSL certificate into a Reactjs application

After completing my ReactJS app for my website, I am now ready to launch it in production mode. The only hurdle I face is getting it to work under https mode. This app was developed using create-react-app in a local environment and has since been deployed ...

Pass the ID and content of a textarea element by utilizing the AJAX post method and incorporating SweetAlert version 2 for a seamless and

function solveTheIssue(id) { promptUser({ title: "Share your complaint", input: "textarea", showCancelButton: true, confirmButtonColor: "#DD8B11", confirmButtonText: "Yes, submit it!", ...

The nested CSS grid is failing to show its nested elements on the page

Having trouble with a nested CSS GRID - the child grid items are not appearing correctly despite multiple checks on the markup. The first grid row should span three columns, as it does, and is set to display:grid with 2 child grid items. However, the chil ...

Assistance needed with CSS floating properties

Despite seeing many inquiries about float, I still can't pinpoint what's causing my issue. My objective is simple: GREETINGS FRIEND I aim for it to align just to the left of the unordered list. Referencing this solution, I attempted adding cl ...

retrieve the height value of a div element using AngularJS

I'm having trouble retrieving the updated height of a div using AngularJS. It seems to only provide the initial value and does not update as expected: vm.summaryHeight = $(".history-log-container").height(); console.log(vm.summaryHeight);//always dis ...

Adaptable layout - transitioning from a two-column design to a single-column layout

I'm facing an issue with two divs that are floated left to appear inline <div class==".container" style="width: 100%"> <div class="leftColumn" style="width: 50%; float:left"> test </div> <div class="rightColu ...

Is there a way for me to prioritize the sidebar over the main content on the page

My theme is efficient and visually appealing, but there's one issue with the mobile layout - it displays the sidebar after the content. How can I rearrange this in my theme so that the sidebar appears before the content? Thanks for your help! ...

Remove the ability to select from the dropped list item

Here is the HTML and Javascript code I used to enable drag and drop functionality for list items from one div to another: HTML: <div class="listArea"> <h4> Drag and Drop list in Green Area: </h4> <ul class="unstyle"> & ...