Items vanish when hovering over them

Creating nested links in the sidebar navigation bar with CSS has been a challenge for me. While hovering over main links, I can see the sub-links being displayed. However, when I try to hover/click on the children of the sub-links, they disappear.

Note: My experience with SCSS/CSS is very limited, and I'm experimenting with adding some styling to a React app.

Code Sandbox:

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

HTML Page


import "./styles/style.css";

function App() {
  return (
    <>
      <header>
        <nav>
          <div className="logo">
            <h1>Logo</h1>
          </div>
          <div className="nav__links" >
            <ul >
              <li><a>Link1</a></li>
              <li><a>Link2</a></li>
              <li><a>Link3</a></li>
            </ul>
          </div>
          <div className="burger">
            <button>
              <div className="line1"></div>
              <div className="line2"></div>
              <div className="line3"></div>
            </button>
          </div>
        </nav>
      </header>
      <div className="main-content-with-side-bar">
        <div className="side-bar">
          <ul>
            <!-- Nested links -->
          </ul>
        </div>
        <div>
          <!-- Lorem Ipsum content -->
        </div>
      </div>
      <footer>
        <div></div>
      </footer>
    </>
  );
}

export default App;

SCSS


@import "variable";
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
header {
  // Styles
}
// More SCSS styles

Answer №1

Based on personal experience, I recommend reducing the distance between the two elements without testing any code. Sometimes when you hover from one element to another, there might be a gap where the hover effect is lost. Ensure that both elements have hover and focus functions enabled. Alternatively, you can utilize setTimeOut() on the hovered element to allow for a smoother transition from one element to the next. The first suggestion tends to be the most straightforward solution.

Answer №2

The disappearance occurs when the mouse goes beyond the hover area. To fix this, simply expand the hover area.

To implement this change, insert the following code snippet into your styles.css file:

ul li :hover::after {
  content: " ";
  width: 100px;
  height: 20px;
  position: absolute;
}

You can view and test the updated code in the Code Sandbox here: https://codesandbox.io/s/naughty-gates-qtgyb?file=/src/styles.css

Answer №3

Whenever you attempt to click on the children of sub links, they vanish due to the left margin assigned to .sub-submenu. To fix this issue, consider reducing the left margin and increasing the width of the sub links.

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

Error: AsyncPipe received an invalid argument of type '[object Object]'. This has caused an error due to an invalid pipe argument

I'm currently working on developing a contact management system that includes CRUD operations using Angular 8 and Spring Boot. Every feature is functioning correctly except for the search functionality. My goal is to search for data based on a specifi ...

Implementing recursive functionality in a React component responsible for rendering a dynamic form

Hello to all members of the Stack Overflow community! Presently, I am in the process of creating a dynamic form that adapts based on the object provided, and it seems to handle various scenarios effectively. However, when dealing with a nested objec ...

Storing API request results in local storage with React does not automatically cache them

I want to create a basic component using react that can fetch an image from an API and save it for future requests within the application. However, I'm facing an issue where the component renders every time it's used, resulting in multiple API ca ...

Offering various language options on a website determined by the URL

I've been contemplating how to add multi-language support to my personal website, which I developed using ExpressJS and NodeJS with EJS as the template engine. Currently, the website is only available in English, but I want to add a German version as ...

Error: The PDFJS variable is not recognized when trying to load a PDF file

I've been experimenting with pdf.js to load PDFs into a web application in order to extract information in real-time. However, I keep encountering an error even with a simple example. I've attempted enclosing the code in $(document).ready() as a ...

Can TypeScript automatically deduce keys from a changing object structure?

My goal here is to implement intellisense/autocomplete for an object created from an array, similar to an Action Creator for Redux. The array consists of strings (string[]) that can be transformed into an object with a specific shape { [string]: string }. ...

Presentation: Positioning Next Buttons Beside Slide Images While Maintaining Responsiveness

I am facing a challenge with my slideshow project. The slideshow consists of images and text on each slide, along with previous and next buttons that are aligned within the parent container. I am trying to align these buttons at the midpoint of each image ...

When using jQuery with a large selectbox, you may encounter the error message: "Uncaught RangeError: Maximum

My select box works fine in IE and Mozilla, but throws an uncaught rangeError in Chrome when choosing the "Others" option to display a second select box with over 10k options. How can I diagnose and resolve this issue? <!DOCTYPE html> ...

Collaborate on sharing CSS and TypeScript code between multiple projects to

I am looking for a solution to efficiently share CSS and TS code across multiple Angular projects. Simply copy-pasting the code is not an ideal option. Is there a better way to achieve this? ...

Conceal and reveal buttons at the same location on an HTML webpage

There are 3 buttons on my custom page called page.php: <input type="submit" value="Btn 1" id="btn1"> <input type="submit" value="Btn 2" id="btn2" onClick="action();> <input type="submit" value="Btn 3" id="btn3" onClick="action();> ...

How can I adjust the size of my elements to be responsive in pixels

While browsing through Quora and Facebook feeds, I noticed the fixed size of user display pictures: width: 40px; height: 40px; Even when resizing the browser window for a responsive design, these pictures maintain their size at 40px x 40px. What other f ...

Using dynamic loading in NextJS, how can one access the ReactQuill Ref?

Currently facing an interesting issue. I am making use of NextJS for its server-side rendering abilities and incorporating ReactQuill as a rich-text editor. To work around ReactQuill's connection to the DOM, I am dynamically importing it. However, thi ...

What is the best way to link PostgreSQL with a React frontend using restify?

Login.js This is a Reactjs login page that requires moving to the next page after successful authentication. The database being used is postgreSQL with a table named 'user' for storing usernames and passwords. The development requirements inc ...

Developing a dynamic slideshow using JSON data

I received a JSON response from a server with the following structure: { "value_1": "a", "value_2": "b", "pagination": { "titles": [ "Title 1", ...

Hover function not functioning properly

I can't figure out why this hover effect isn't working, there doesn't seem to be a negative z-index or anything like that. At most, it just flashes on hover; .menu{ border-radius: 50%; width: 100px; height: 100px; background: white; box-sha ...

Customized icons for Contact Form 7 on your Wordpress website

Currently, I am in the process of customizing a contact form by incorporating placeholder icons and text using the 'Contact Form 7' plugin within Wordpress. This particular contact form is situated on a website that I am constructing with the &ap ...

Generating a clickable link for the URL included in a tweet message

As someone who is just starting out in coding, I could really use some help. Currently, I am using node.js to fetch tweet text and displaying it using html. I would like to add a hyperlink for the URLs within the text. For example: #Times #News Ukrainians ...

Top solution for preventing text selection and image downloading exclusively on mobile devices

My plan is to use the following code to accomplish a specific goal: -webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none; -webkit-tap-highlight-color:rgba(0,0,0,0); I& ...

"Exploring the world of CSS3: Arrow shapes and animated effects

Looking at the image provided, my task is to create and animate it. I was considering using CSS3 border-radius instead of an actual image. Below are the HTML and CSS code that I have so far. The animation I envision involves the arrow gradually appearing ...

Determine whether it is SSR or not

I have developed a versatile package designed for compatibility with both CRA and NextJS environments. Within this package, there is a crucial component that configures attributes on body, html, and title tags. To achieve this functionality, I initially ...