I am looking to optimize my CSS and jQuery code for a dropdown menu

I have the following code that is currently functioning properly for a dropdown menu, but I need to make some modifications to the CSS and jQuery.

I am looking to increase the size of the main box and decrease the width of the first row of icons.

However, when attempting to reduce the width, it affects the entire box rather than just the row of icons.

Please provide guidance. FIDDLE LINK http://fiddle.jshell.net/6pLPn/

Code:

<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1.0">

    </head>
    <body>
        <div class="header">
            <div class="logo">
                JQUERY DEMO
            </div>
            <ul class="nav">
                <li class="nav-link">

                </li>
            </ul>
        </div>

        <!-- Clickable Nav -->
        <div class="click-nav">
            <ul class="no-js">
                <li>
                    <a class="clicker"><img src="img/i-1.png" alt="Icon">Profile</a>
                    <ul>
                        <li><a href="#"><img src="img/i-2.png" alt="Icon">Dashboard</a></li>
                        <li><a href="#"><img src="img/i-3.png" alt="Icon">Settings</a></li>
                        <li><a href="#"><img src="img/i-4.png" alt="Icon">Privacy</a></li>
                        <li><a href="#"><img src="img/i-5.png" alt="Icon">Help</a></li>
                        <li><a href="#"><img src="img/i-6.png" alt="Icon">Sign out</a></li>
                    </ul>
                </li>
            </ul>
        </div>
        <!-- /Clickable Nav -->

        <!-- jQuery -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script>
        $(function() {
            // Clickable Dropdown
            $('.click-nav > ul').toggleClass('no-js js');
            $('.click-nav .js ul').hide();
            $('.click-nav .js').click(function(e) {
                $('.click-nav .js ul').slideToggle(200);
                $('.clicker').toggleClass('active');
                e.stopPropagation();
            });
            $(document).click(function() {
                 if ($('.click-nav .js ul').is(':visible')) {
                     $('.click-nav .js ul', this).slideUp();
                     $('.clicker').removeClass('active');
                 }
             });
         });
         </script>




     </body>
 </html>
 

Answer №1

The container div <div class="click-nav"> determines the width of all elements within it, with a set width of 200px in the CSS.

By setting the <a> tags inside the <li> items to display: block, they expand to fill the width of their parent container.

To reduce the size of the 'first icon row', you can target it using the .clicker class.

.clicker {
    width: 100px; /* or adjust as needed */
}

To increase the width of the 'main box', simply apply a larger width value to .click-nav ul li ul in the existing CSS code. For example:

.click-nav ul li ul {
    width: 250px; /* or adjust with percentage values */
}

Check out the updated fiddle here.

Does this address your concern? Feel free to provide more details if needed for further assistance.

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

Methods for incorporating external javascript.php files into CodeIgniter 2.1.3

Let's kick off this topic by discussing the following: I've discovered that it is possible to use PHP with external Javascript, as shown here. This leads me to believe that there could be a way to echo JavaScript within a file named javascript. ...

The emission from Socket.io is originating from the recipient's browser without being transmitted to the sender's browser

Hey there, I'm fairly new to socket.io and not completely sure if what I'm doing is the standard way, but everything seems to be working fine so I guess it's okay. I've been working on a chat application where messages are stored in a d ...

From structured CSS to streamlined LESS syntax

Being a UX designer, my goal is to streamline my workflow. I aim to transition from HTML to well-structured CSS to LESS as efficiently as possible. The concept is to input HTML, generate CSS, compile it to LESS, style it, and then recompile it back to CSS ...

Vuetify's scrolling list feature allows for smooth navigation through a list

Check out my Vuetify code snippet that utilizes a list: <v-list> <v-list-tile v-for="user in users" :key="user.id" avatar @click="" > <v-list-tile-content> < ...

Failure of window marker to trigger click event in jquery-bing-maps

I'm encountering an issue where clicking on links within Window markers on Bing Maps redirects me to a new page instead of triggering a JavaScript event as intended. $('.single_address').on('click', function (evt) { alert(&apo ...

Guidelines for storing information in a database utilizing jQuery and JSON within an asp.net framework

I've been developing an application that utilizes jQuery and JSON to store data in a database. Here is the script function I have written: <script type="text/javascript"> function test() { $(document).ready(function () { var Email = document.ge ...

Node.js application with decoupled Redis client

In my node.js app, I am utilizing Redis for user caching. Once a user logs in, their information is cached and accessed on subsequent requests to determine their access level. This allows the client to receive personalized information and views based on th ...

Outlook not adding padding to button in HTML email

https://i.stack.imgur.com/vMgGS.png Is there a way to apply the same padding to the border as seen on the button above? Adding the border directly to the td element seems like a solution, but it is not feasible due to the presence of border-radius in anot ...

Encountering an issue while trying to launch an Angular application on localhost. Vendor.js resource failed to load

Whenever I compile the code, it runs successfully. However, when I try to serve the application using 'node --max-old-space-size=8192', even though it compiles without any errors, when I open the app in a browser, it returns an error saying "Cann ...

Using the 'client-side rendering' and runtime environment variables in Next.js with the App Router

In the documentation for next.js, it's mentioned that runtime environment variables can be utilized on dynamically rendered pages. The test scenario being discussed involves a Next.js 14 project with an app router. On the page below, the environment ...

What is the method for transferring the input value from a prompt to a function?

I'm currently working on developing a hangman game with react and js. I encountered an issue where after clicking the Guess word button, I intended to use a prompt box for users to input their guess of the full word. However, when I tried entering a w ...

Issue with absolute positioning in IE6 and IE7 not functioning correctly

I recently created a website for a friend that involves absolute positioning within a relative positioned div. After testing it in various browsers using Browserlabs, I found that it works well except for IE6 & IE7. Despite searching online for solut ...

Leverage a JavaScript function to manipulate the behavior of the browser's back button

Is there a way to trigger the Javascript function "backPrev(-1)" when the back button of the browser is clicked? Appreciate any help, thank you. ...

The Ag Grid Cell Render feature is not available

I have been working on creating my own cell renderer by referring to this example https://www.ag-grid.com/javascript-data-grid/cell-rendering/, but I am running into an issue when using TypeScript. When I define a class that implements the ICellRenderer in ...

Check the File Format (not just the Extension) prior to Uploading

When uploading a file within an HTML form, you can validate the extension using JQuery's Validation plugin: <form enctype="multipart/form-data" id="form-id"> <input type="file" name="file-id" id="file-id" /> </form> To validate ...

Ways to dynamically trigger a function in the componentDidMount lifecycle method?

Let's consider something interesting: componentDidMount() { const { currentUserId, userList } = this.props; //I receive these values from the mapStateToProps function in Redux; //they are not standard props. Mousetrap.bind([' ...

The auto-complete feature in Bootstrap tagsinput is malfunctioning

<script type="text/javascript"> $(function () { $('#input-tagautocomplete').tagsinput({ typeahead: { source: function (term, process) { items = []; map = {}; var url = ...

Using the power of HTML5, store data locally on

I am curious about the possibility of using local storage on a different page. I want to track clicks made on one page and display it on another, but I'm not sure how to go about it or if it's even feasible. Any help you can provide would be grea ...

Enhancing the Mario gaming experience with a bespoke Typescript camera feature

I am working on creating an educational Mario game without the use of PhaserJS or any other engine. Currently, I am faced with the challenge of implementing a camera that can follow Mario as he moves. As it stands, Mario can walk off the screen in one di ...

applying a margin to the cover div

I am currently working on a #cover element with the following CSS styling: #cover { background-color: #FFFFFF; height: 100%; opacity: 0.4; position: fixed; width: 100%; z-index: 9000; } The goal is to have it cover the entire visi ...