activating hover states is prevented when using overflow:scroll

Visit the codepen page

I am attempting to set a max-height or height to a long list and make the rest scroll. I achieved this by using:

height:800px; overflow:scroll;

The issue I'm facing is that the "#subcategory" items stop displaying on hover when I apply overflow:scroll

Any suggestions would be welcome!

Basic HTML Structure

  <!-- Start Auto Transport -->
  <li id="topCategory"><a href="#">Auto Transport</a>
  <ul id="subContainer">
        <li id="subCategory"><a href="#">Auto Insurance</a></li>
        <li id="subCategory"><a href="#">Auto Payment</a></li>
        <li id="subCategory"><a href="#">Gas</a></li>
        <li id="subCategory"><a href="#">Parking</a></li>
        <li id="subCategory"><a href="#">Public Transportation</a></li>
        <li id="subCategory"><a href="#">Service Parts</a></li>
          <!-- add new becomes text field, user enters text then it becomes added as category -->
          <li class="hideNewCategory">
            <a class="mmNewCat" data-number="1" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
            <input id="mmCat1" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
          </li>
  </ul>
  </li>
  <!-- End Auto Transport -->


  <!-- Start Bills Utilities -->
  <li id="topCategory"><a href="#">Bills & Utilities</a>
    <ul id="subContainer">
        <li id="subCategory"><a href="#">Domain Names</a></li>
        <li id="subCategory"><a href="#">Fraud Protection</a></li>
        <li id="subCategory"><a href="#">Home Phone</a></li>
        <li id="subCategory"><a href="#">Hosting</a></li>
        <li id="subCategory"><a href="#">Mobile Phone</a></li>
        <li id="subCategory"><a href="#">Television</a></li>
        <li id="subCategory"><a href="#">Utilities</a></li>
        <!-- add new becomes text field, user enters text then it becomes added as category -->
          <li class="hideNewCategory">
            <a class="mmNewCat" data-number="2" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
            <input id="mmCat2" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
          </li>
    </ul>
  </li>
  <!-- End Bills Utilities -->

relevant CSS

ul li:hover #topContainer{
  display: block;
}

ul li a {
  display: block;
  color: $blue;
  text-decoration: none;
  font-family: verdana;
  font-size: 14px;
}

#topContainer{
  list-style: none;
  color: $blue;
  width: 260px;
  height: auto;
  background: $white;
  opacity: 0.9;
  position: absolute;
  z-index: 1000;
  height:800px;
  overflow:scroll;
}

#topCategory {
  float: none;
  width: auto;
  height: 20px;
    text-align: left;
  margin-left: 15px;
}

#topCategory a:hover {
  color: $white;
  background-color: $blue;
}

#topCategory:hover #subContainer {
  display: block;
}

#topCategory a {
  font-size: 16px;
  position: relative;
  bottom: 41px;
  margin-top: 46px;
  margin-left: -15px;
  padding: 20px 0 20px 20px;
  border-bottom:1px solid $grey-10;
}

#topCategory a:hover {
  color: $white;
}

#subContainer {
  list-style: none;
  color: $blue;
  display: none;
  font-size: 12px;
  min-width: 230px;
  width: 150px;
  height: auto;
  background: $white;
  opacity: 0.9;
  margin: -107px 0 0 245px;  position: absolute;
  z-index: 1000;
  white-space:nowrap;
}

#subContainer a{
  border-bottom:1px solid $grey-10;
  margin-top: 41px;
}

#subCategory {
  float: none;
  width: auto;
  height: 20px;
  text-align: left;
  margin-left: 10px;
}

#subCategory:hover {
  background: none;
}

.active {
  background: $white;
}

#subCategory {
    float: none;
    // hover length
    width:215px;
    // hover length
    text-align: left;
    height: 25px;
    margin-left: 15px;
    margin-right: -43px;
}

Answer №1

The subcategory should be defined as a class instead of an id for a more organized appearance.

.subcategory {

}

<div class="subcategory"></div>

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

Arranging Text and Images in HTML/CSS to Ensure Optimal Placement When the Window Size Changes

Hello fellow coders! I've recently started diving into the world of website development and I have a query regarding positioning elements and handling window resizing. Can anyone help me out? I'm trying to center an image, a message, and a passw ...

Discrepancy in alignment between Internet Explorer and Chrome when centering multiple <div> elements horizontally

I'm having trouble aligning multiple divs horizontally in my code. Here is the simple test code I am using. <div style="text-align: center;"> <div style="border:1px solid #000; display:inline-block;">Div 1</div> <div st ...

When using Javascript's querySelector, often times it returns null

Here is the HTML code I am working with: <button class="pop-btn"> Pop </button> While I was able to style this button using CSS, I encountered a problem when trying to select it in Javascript: const Population_div_Button=document. ...

Initiate Bootstrap 4 dropdown menus from the initial menu point

I need the dropdown menus to align with the position of the first dropdown. There are multiple dropdowns on the page. Check out the screenshot for reference. JSFiddel: https://jsfiddle.net/kfh9Lbep/ https://i.sstatic.net/hHAKz.png Any ideas on how to ac ...

React random marker position shifts when the screen size is adjusted

After displaying an image and adding a marker to it, I noticed that the marker's position changes when the screen size is adjusted. Why does this happen? And more importantly, how can I ensure that the marker stays in the same position relative to the ...

What is the best way to generate a specified number of rows with 3 columns in each row using jquery?

After spending 3 hours trying to create a boostrap 'card' with 3 identical cards per row, I unfortunately failed. Here is the code I attempted: $.getJSON("./listings.php", function(e) { $.each(e, function(i, e){ if (e.id != ...

What is the lowest opacity value allowed in CSS?

When adjusting the opacity value of a button in CSS, I have noticed that even when the opacity is reduced to 0.005, the button remains clickable to some extent. However, when reducing the value to 0.000000000000000000000000000000000001, the button becomes ...

The issue I am facing is that when I click on a checkbox, only one of them seems to respond

When I click the button, only the first checkbox event is being checked while the rest of them are not. Can someone please provide some guidance on how to fix this issue? $("#cascadeChange").click(function() { //alert("Clicked"); ...

In certain cases, webkit browsers may conceal LI A (display:block) elements

I have created a unique menu design that is based on the classic 'ul li' structure, but with 'a' elements set to display:block for precise positioning and sizing. There is also some transform:rotate applied, but this does not affect the ...

Is there a way I can finish animating these divs in a diagonal motion?

I successfully made the blue and red divs move diagonally and switch positions. Now I am looking to achieve the same effect with the green and pink divs using a similar function. I am unsure about setting the position of both divs to 0 and 350 for those p ...

What is the best way to incorporate padding into an Angular mat tooltip?

I've been attempting to enhance the appearance of the tooltip dialog window by adding padding. While adjusting the width and background color was successful, I'm encountering difficulties when it comes to styling the padding: https://i.sstatic.ne ...

Issue with drop-down menu functionality on mobile-friendly website

After deciding to revamp my website for responsiveness, I encountered an issue with the menu not displaying on smaller screens. Everything else is functioning correctly except for the drop-down menu! Here is the HTML code: <!doctype html> <html ...

What is the process of inserting elements into a nested list?

Just starting out with Python and looking for help. I have a list within a list and I need to add an element to the end of each sub-list. a = [ [0, 1 ,-1, 2, -2, 3, -3, 4, -4, -5, 5, 8], [0, 6 ,-6, 7, -7, 8, -8, 9, -9, -10, 10, 9] ] for i in a: b = ...

Changing the Appearance of the RStudio Editor

I am exploring options to customize an RStudio Editor Theme to personalize the colors. My current setup includes RStudio version 0.99.473 on Windows 10. After reviewing Any way to change colors in Rstudio to something other than default options?, which wa ...

How to use AngularJS to collapse various panels with unique content

Hey everyone, I'm working on developing a collapsible panel using Angular. The panel should consist of a header and body to display the content. The desired behavior is that when a button is clicked, the content collapses down, and clicking the same b ...

How can I use CSS to transform a "+" symbol to an "x"?

When I created an accordion using HTML, JS, and CSS, I encountered a problem. The "+" sign in the accordion does not rotate correctly as it should. Instead of rotating from the middle of the "+" sign, it rotates from the top. This is my HTML code: <di ...

Hover over to disable inline styling and restore default appearance

There are some unique elements (.worker) with inline styles that are dynamically generated through Perl. I want to change the background when hovering over them and then revert back to the original Perl-generated style. The only way to override the inline ...

Could somebody please clarify the purpose of Bootstrap's `_root.scss` file?

After reading through the Bootstrap introduction [1], I added the following code snippet to my .html file: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384- ...

Exploring anchor hover effects and navigating adjacent sibling elements

Consider this html structure: <p><a></a></p> <div><a><img></a></div> To hide all images inside a div after a p tag, you can use the following code: p + div {display:none;} However, attempting to sho ...

How can a Bootstrap card be designed with the image positioned at the top left, but adjusting based on different

When it comes to Bootstrap 4 cards with images, most have the image positioned at the top using .card-img-top. But what if you want the image to be at the left or at the top depending on the width? Currently, I have two types of cards - one with the image ...