Mini-navigation bar scrolling

I am trying to create a menu where I want to hide elements if the length of either class a or class b is larger than the entire container. I want to achieve a similar effect to what Facebook has. How can I make this happen? I have thought about one approach mentioned in the comment section, but I am unsure of what steps to take next.

$('.b').hide();
     $(".a").click(function(){
        $(".b").slideToggle(200);
    });

/*
$(document).ready(function(){ 
   
    var k = $("#container").length;
var n = $(".a").length;
    
    
if (n > k) {

} 
else {

}

});
*/
#container
{
    width: 200px;
    height: 500px;
    background-color: rgba(0, 0, 0, 0.3);
}

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

.a
{
    width: 200px;
    height: 100px;
    margin-bottom: 10px;
    background-color: black;
    cursor: pointer;
}

.b
{
    margin-bottom: 5px;
    padding: 0;
    list-style-type: none;  
    height: 100px;
    width: 200px;
    background-color: rgba(0, 0, 0, 0.6);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div id="container">
    <ul>
        <li class="a"></li>
            <ul>
                <li class="b"></li>
                <li class="b"></li>
                <li class="b"></li>
            </ul>
        <li class="a"></li>
        <li class="a"></li>
    </ul>
</div>

Answer №1

If you want the content in #container to have a scroll bar, simply add overflow-y: scroll; and adjust until it looks just right. Check out this interactive example.

Custom CSS Styles

#container {
    width: 200px;
    height: 500px;
    overflow-y: scroll;
    background-color: rgba(0, 0, 0, 0.3);
}
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
.a {
    width: 200px;
    height: 100px;
    margin-bottom: 10px;
    background-color: black;
    cursor: pointer;
}
.b {
    margin-bottom: 5px;
    padding: 0;
    list-style-type: none;
    height: 100px;
    width: 200px;
    background-color: rgba(0, 0, 0, 0.6);
}

HTML Structure

<div id="container">
    <ul>
        <li class="a"></li>
        <ul>
            <li class="b"></li>
            <li class="b"></li>
            <li class="b"></li>
        </ul>
        <li class="a"></li>
        <li class="a"></li>
    </ul>
</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

Activate Sparkline mini graph following successful Ajax response

With the code snippet below, I am able to fetch data from a MySQL database using Ajax and receive the result successfully during testing. However, my challenge lies in getting sparkline to render the graphs after the Ajax call is successful. Interestingl ...

Using CSS sprites to style text links

I've been attempting to incorporate an image with various icons for text links in an unordered list, but I can't seem to display just one icon with some space next to it for the text. The code I have so far is: http://jsfiddle.net/XyVtq/2/ This ...

Having trouble getting PostCSS nesting to work with CSS variables in Tailwind CSS and Next.js?

I've been attempting to utilize PostCSS nesting alongside CSS variables, but unfortunately the CSS variables are not being converted at all. Instead, I am seeing Invalid property value in the DOM for CSS Variables. The tailwind.css file I have inclu ...

Using JQuery, extract all images from the img tag and background images from an HTML page

I am seeking a way to extract all images present in an HTML page. I am interested in extracting images from the <img> tag source as well as from background elements within the HTML content. Is there a method to accomplish this task? ...

Getting the URL of a CSS background image in NodeJS and Express: A step-by-step guide

I've recently learned that using getComputedStyle in a Node environment is not possible due to it being a browser-specific behavior. Despite this, I am still interested in retrieving all background image URLs within Node and downloading them as shown ...

What is the best way to retrieve a row in ui-grid using data from a specific column?

I am currently utilizing the ui-grid feature provided by . I have been experimenting with various methods, but due to my recent introduction to Angular, I find the documentation quite perplexing. I have implemented a custom search tag system and my goal i ...

Changing the color of error messages when validating input with jQuery Validation and Bootstrap 5

Modified: I have implemented jquery-validation and bootstrap 5 to handle form validation and display error messages. Strangely, when I attempt to log in without entering an email and password, the input fields turn red (indicating an error) for both the em ...

Customizing colors in React Material UI

Can colors in Material UI be overridden without the use of JS? Is it possible to override colors using CSS alone? ...

Performance problems arising from use of Tailwind CSS drop-shadow class

Lately, I've been struggling to pinpoint the root cause of a drastic FPS drop in my application. The issue arises after using the app for some time, leading to a performance plunge down to around 10FPS. After investigating, I discovered that eliminati ...

dynamically assigning a style attribute based on the dimensions of an image retrieved from a URL

My aim is to determine whether or not I should use an image based on its dimensions. To achieve this, I came across a function on stack overflow that can retrieve the dimensions of an image just by using its URL. Here is the code snippet they provided: f ...

Troubleshooting: Vue.js Component template not displaying items with v-for loop

I recently implemented a method that calls an AJAX request to my API and the response that it returns is being assigned to an array. In the template section, I am using the v-for directive to display the data. Surprisingly, it only renders once after I mak ...

A guide on using jQuery to cycle through every row of every table on an HTML page

I am trying to figure out the correct syntax for nesting two loops within each other in jQuery. The first loop should iterate over each table in an HTML page that does not have any IDs or classes, while the second loop should go through each table row of t ...

How to alter the color of an inline SVG within an <img> element

Is it possible to change the color of an SVG image, icon, or logo within an inline HTML <img> tag using style="..."? Below is a snippet of my code featuring a button with a logo that I want to change the color of: <a href="#" ...

Create a datastring using a JSON object

When receiving data in JSON format from an AJAX call, the following code is used to parse it: var parsed=JSON.parse(data); An example output could look like this: {"confirm_type":"contract_action","job_id":12,"id":7} To generate a dynamic data string f ...

Using an image tag with dual quotes in Vue.js

I am currently working on a feature where users can upload an image and then have it displayed after the upload is complete. However, I am facing an issue where the response link of the image contains a double quote, and when I use the <img> tag to ...

Position the Bootstrap icon to float to the far right

My icon is always positioned to the right instead of beside the input field. Take a look at the image below: https://i.stack.imgur.com/Bb1eH.png The icon does not align next to the input field. This is my code snippet : <div class="form-horizontal"& ...

What is the best way to include specific script tags within the <head> and <body> sections when utilizing HtmlWebpackPlugin?

I am currently utilizing HtmlWebpackPlugin in order to create HTML files that include JavaScript. Now, I am interested in inserting custom scripts at various locations within the <head> and <body> tags For instance: How can I, Insert <s ...

Error: Unable to interpret the URL provided in /api/posts/1

When working on my next.js 13 app, I encountered an issue while trying to fetch individual blog data from a local MySQL database. In the src/blog/[id]/page.js file, I have the following component: const BlogPost = async ({ params }) => { const data ...

Featuring a visual arrangement of categorized images with AngularJS for an interactive display

As I work on developing a web application with Angular, my goal is to create a grid layout that organizes items by category. Each row will represent a different category. Below is an example of the code structure I have in place: <ion-item ng-repeat="i ...

Using JavaScript to assign one object to another object

I am facing an issue where I am trying to assign the local variable UgcItems to uploadedItems, but when I attempt to return the value, it shows as undefined. If I place the console.log inside the .getJSON function, then I get the expected value. However, t ...