Ensure that the hover effect remains on the element that emerges from it

I am facing an issue with a list where each item has a title. Upon hovering over the title, an info box appears but disappears when moving the cursor to the box itself.

The requirement is for the box to remain visible even when the cursor moves from the title to the box. How can this be achieved?

ul {
margin:0;
padding:0;
list-style: none;
}

ul li + .box {
  opacity: 0;
  visibility: hidden;
  max-height: 0;
}
    
ul li:hover + .box {
  opacity: 1;
  visibility: visible;
  min-height: 200px;
}

.box {
  background-color: #ccc;
  padding: 10px;
  text-align: right;
  border-radius: 6px;
}
<ul class="nav">
  <li class="pt pt1 active" data-cont="r1">
      <p>إصدار رخصة استثمار للمستثمر الأجنبي</p>
  </li>
  <div class="box">
      <div class="steps">
          <div>
              <p>تضاف قيمة 10,000ر.س للاشتراك في خدمات مراكز علاقات المستثمرين بوزارة الاستثمار في السنة الأولى و 60,000 ر.س في السنوات التالية / سنة </p>
          </div>
          <div>
              <p>هذا الإجراء يتطلب إنشاء حساب جديد في حال عدم وجوده</p>
          </div>

          <div>
              <p>هذا الإجراء مؤتمت</p>
          </div>
          <div>
              <p>هذا الإجراء يتطلب الدفع</p>
          </div>
      </div>
  </div>
</ul>

Answer №1

To solve the issue, we need to adjust the hierarchy of elements.

  1. Place the box inside the li
  2. Show the list item and hide the embedded box initially
  3. On hover over the li, display the embedded box by setting its visibility to visible

ul {
  margin:0;
  padding:0;
  list-style: none;
}

ul li:hover > .box {
opacity: 1;
    visibility: visible;
    min-height: 200px;
}

.box {
  opacity: 0;
  visibility: hidden;
  max-height: 0;
  background-color: #ccc;
  padding: 10px;
  text-align: right;
  border-radius: 6px;
}
<ul class="nav">
  <li class="pt pt1 active" data-cont="r1">
      <p>Issueing an Investment License for Foreign Investors</p>
      <div class="box">
          <div class="steps">
              <div>
                  <p>An amount of 10,000 SAR is required for subscribing to services at the Ministry of Investment Investor Relations Centers in the first year, and 60,000 SAR in the subsequent years/year.</p>
              </div>
              <div>
                  <p>This process requires creating a new account if not already existent.</p>
              </div>

              <div>
                  <p>This process is automated.</p>
              </div>
              <div>
                  <p>This process involves payment.</p>
              </div>
          </div>
      </div>
      <li>
</ul>

Answer №2

Hopefully, this solution resolves your issue.

ul{
margin:0;
padding:0;
list-style: none;
}
ul li .box {
opacity: 0;
    visibility: hidden;
    max-height: 0;
    }
    
ul li:hover .box {
opacity: 1;
    visibility: visible;
    min-height: 200px;
}

.box {
background-color: #ccc;
padding: 10px;
text-align: right;
border-radius: 6px;
}
<ul class="nav">
                            <li class="pt pt1 active" data-cont="r1">
                                <p>Granting an Investment License to Foreign Investors</p>
                                <div class="box">
                                <div class="steps">
                                    <div>
                                        <p>A fee of 10,000 SAR is required for the first year subscription to Investor Relations Centers services at the Ministry of Investment and 60,000 SAR in subsequent years / per annum</p>
                                    </div>
                                    <div>
                                        <p>This procedure necessitates creating a new account if not already existing</p>
                                    </div>

                                    <div>
                                        <p>This process is automated</p>
                                    </div>
                                    <div>
                                        <p>This process requires payment</p>
                                    </div>
                                </div>
                            </div>
                            </li>
                            
                  </ul>

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

Utilizing AngularJS to Implement Gradient Effects Using the ng-style Directive

Having trouble setting gradients using the angular js ng-style directive. I can successfully set normal colors using the code below: <span ng-style="{'background-color': slidercolor}">works</span> However, when trying to set a gradi ...

What is the method for positioning the cursor at the beginning of a center-aligned placeholder within a contenteditable element?

Here is the code snippet I am working with: HTML: <div class="title" contenteditable="true" placeholder="Title"></div> CSS: .title { width: 500px; margin: 0 auto; text-align: center; } [contenteditable=true]:empty:before{ conte ...

What steps should I take to successfully integrate my Dojo DataGrid into a Dojo ContentPane that is nested within a Dojo TabContainer?

It seems that the issue arises from having different settings for parseOnLoad in the separate widgets. I have experimented with both true and false values but without success. To troubleshoot, I created three web pages - two containing TabContainer and Dat ...

The functionality of displaying and hiding elements in HTML using jQuery is not functioning as expected

When I implemented the .toggle() functionality in jQuery on the content, I encountered a problem where clicking on the "read more" button caused the text link to disappear and the first paragraph to become invisible. Below is the jQuery code snippet: $( ...

Vue.js - Problem with loading image on screen

Although I have experience with React, I am currently facing the challenge of using Vue for a code assessment for the first time. My struggle lies in creating a reusable image component with WAI-ARIA accessibility. Despite my efforts, I cannot get the imag ...

Turn off the whole DIV container and its contents once the button is clicked

Here's an example of the HTML markup: <div id="picing-selection" class="disableMe"> <a class="upgradeSub" value="@ViewBag.Id"> Upgrade <i class="fa fa-money"></i> </a> </div> The onclick event is d ...

Even when assertExist is set to true in casperjs, the element cannot be located

I am currently encountering a problem with casperjs in my application. Here are the steps I am taking: 1) First, I am performing an assertion to check if the element exists. casper.then(function() { this.test.assertExists( { type: ' ...

Loop through individual divs containing radio buttons and check them one by one with a slight delay

I have implemented HTML tabs using radio buttons, similar to the demo showcased at https://css-tricks.com/examples/CSSTabs/radio.php. Here's the basic markup: <div class="tab"> <input type="radio"> <p>Content displayed when radio bu ...

Layer images of the same size in a seamless overlap on top of another image

As a novice web developer, I am aiming to stack two images perfectly on top of each other in my project. The application I am working on checks the correctness of user inputted answers by displaying either a checkmark or an "X" mark accordingly. To achieve ...

How to fix issue with uibModal not showing on full screen in AngularJS using HTML5

Having some trouble creating a uibModal in angularjs 1.6; my modal doesn't seem to be appearing on the entire screen as expected. What could potentially be causing this issue? ...

JS receiving a reference to an undefined variable from Flask

I referenced this helpful post on Stack Overflow to transfer data from Flask to a JS file. Flask: @app.route('/') def home(): content = "Hello" return render_template('index.html', content=content) HTML <head> ...

Tips for populating a textfield with data from a <select> dropdown using javascript

Is there a way to populate a textfield with data automatically based on information provided in the tab, utilizing JavaScript? Additionally, is it possible to prevent the filled data from being edited? The textfield should be able to dynamically fill data ...

Can you use logical AND in Selenium XPath to combine multiple contains() filters?

My objective is to identify a specific element using Selenium: <a class="ABC" href="#" data-test-id="XXX|YYY|ZZZ"> There are various elements on the page with attributes matching "ABC", "XXX", " ...

Maintaining fixed position for cursor events in CSS

Here is a simple popup I created using tailwindcss to display project descriptions. Take a look at the code snippet below: // Code snippet here... I am facing an issue where both the container (outer div) and the first inner div have the same click event. ...

Issues with utilizing jQuery AJAX for form submissions

I am currently customizing a webpage to fit the specific requirements of a client using a template. The page contains two contact forms which are being validated and sent to a PHP file via AJAX. One of the forms is standard, while the other one has been mo ...

JavaFX, a versatile container capable of smoothly transitioning between two panes

Looking for a JavaFX container in my Desktop Application that can display a listview with flexible dimensions and transition to gridpane on row selection. The gridpane will show details of the selected row, and clicking the back button will revert to the ...

The webpage is not displaying any results despite using .innerHTML with Ajax

I am currently developing a web application that displays query results using the Google Books API. While my code is functioning, I am encountering an issue where the .innerHTML method does not show any results on the HTML page. Below is the HTML code bein ...

Tips for employing Flex-grow alongside the behavior of "justify-content: start"

I am working with a flex container setup like this: .container { display: flex; flex-flow: row wrap; justify-content: start; width: 100%; } .item { border: 1px solid red; flex: 1 1 33%; height: 100px; } <div class="container"> <d ...

How to transform a hyperlink into a clickable element within an absolutely positioned container

I'm currently working on a photo gallery project and using magnific popup to create it. However, I ran into an issue with the hover event on the images that displays an icon when it's hovered over, indicating that it can be clicked to view more. ...

Question About jQuery and CSS3

Can someone suggest an effective method for modifying CSS3 with jQuery? I was thinking of using a selector like this: $("#con_back").css('-webkit-border-top-right-radius','0px'); $("#con_back").css('border-top-right-radius', ...