Element is not resizing to fit its content

Check out the Fiddle

Important Note: The menu transitions may not work properly in this fiddle, making navigation a bit tricky. This issue is specific to jsfiddle and does not affect the actual website implementation.

In the demonstration provided on my website, there seems to be an issue with the width of the sub-sub-menu. Despite many attempts, I have been unsuccessful in finding a solution that allows the sub-sub-menu to expand according to its contents.

I have tried several approaches over a period of time but unfortunately none of them have worked as intended.

HTML

<div id="nav">
            <ul id="nav-menu" class="menu"><li id="menu-item-20816" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20816 first-child"><a>Casters</a>
<ul class="sub-menu">
    <li id="menu-item-16927" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-16927 first-child"><a href="http://www.casterconcepts.com/all-casters/">All Casters</a></li>
    ...
        ... (Content shortened for clarity)
    ...
        <li id="menu-item-12168" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12168 last-child"><a href="http://www.casterconcepts.com/company/value-added-services/">Value Added Services</a></li>
</ul>                        </div>

CSS

#nav{
  /* CSS styles go here */
}
...
... (CSS rules omitted for brevity)
...
#nav .has-children-left:after{
  border-right: 10px solid rgba(255,255,255,0.2);
  border-left: none;
  right: auto;
  left: 1px;
}

Answer №1

To achieve a one-line display for items in the sub-menu, apply the following style to .sub-menu

.sub-menu {
    white-space: nowrap;
}

With this CSS rule, all content will be displayed on a single line and the ul element will automatically adjust its size accordingly. Check out the live demonstration here.

Answer №2

Within the code snippet below, you will notice a specific height set for the li elements:

#nav ul ul li {
   height:30px;
}

To enhance flexibility, consider replacing height with min-height:

#nav ul ul li {
   min-height:30px;
}

Be sure to check out the corresponding demo at http://jsfiddle.net/36Y37/2/

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

Reasons why this task cannot be accomplished using PHP

<?php if(isset($row['status']) && $row['status'] == "pending") { ?> <span class="pending">Pending</span> <?php } ?> Parse error: syntax error, unexpected T_IF in C:\Program Files\EasyPHP-5.3.6 ...

Struggling with HTML and Javascript in your Chrome Extension project?

Currently, I am working on developing a Chrome extension. The code runs smoothly when I test it as a regular HTML page. However, when I utilize the browser action, the enable/disable button does not function properly. Pressing enable should switch it to di ...

Why is it that this JavaScript isn't working as intended in the popup form?

</br> s_foot"> * use ajax.jquery as control event. like $("#save").click(function(){.....}); <script type="text/javascript>" var wp; var position; var pid; var product_name; var production_date; In this script, I am attempting to re ...

Do you know the term for when JavaScript is utilized to display specific sections of a png image?

Imagine you have an image file in the format of a PNG which includes various icons intended for use on a website. How can JavaScript be utilized to choose and showcase a specific icon from that image? It's a technique I've observed in practice, b ...

Picture is not appearing on web browser within Node application

Recently, while working with Visual Studio Code, I decided to incorporate an image into my Node project. After downloading the image from the internet and placing it in the directory, I renamed it to 'file_2.jpeg'. I then included <img src = " ...

Disabling a button until all textfield fields are completed: A Step-by-Step Guide

My modal contains a table with the following code structure. <div> <Table> <tbody> {props.data.map((p) => <> <tr> <th> STC </th> ...

Tips for choosing the initial paragraph within a div that has a designated class (CSS 2)

I have a <div> that contains multiple <p> elements, and I want to apply specific styling only to the first <p> within each <div> with a unique class called cnt. Please take note that this question may seem similar to others on SO, ...

Enhancing a video tag with a mysterious dark mask

I'm looking for a way to darken a video in my hero section to make it easier to see the white menu items that are getting lost in the brightness. Any tips on how to achieve this using CSS or Bootstrap? <template> <section class="se ...

Preventing HTML form from being resubmitted upon page refresh after submission

I am facing an issue with my HTML form. Whenever I click submit, the form data is sent to the same php page. However, after submitting, when I refresh the page, the web browser shows a re-submission dialog. How can I prevent the form from submitting again ...

Knockout Table Sorter not refreshing data on update

I'm currently working on a code that updates a table every 5 seconds. I have implemented a table sorter with Knockout.js, however I am facing an issue where the data is being appended to previous data instead of updating it. Below is the code snippe ...

Creating void placeholders in a repeated loop

Suppose we have the data array stored in "$my_array". Below is an example of the expected output based on this data. Please note that due to restrictions, I am unable to modify the way data is inserted into the database. Hence, I need to create empty colu ...

JavaScript - Troubleshooting issues with numbers displaying as NaN and objects being undefined

I am currently working on developing a comment generator for a specific program, and I have encountered an issue involving numbers. Initially, when performing the necessary calculations using the code block below, I received an object undefined error: tot ...

The Flex-Direction property set to column is not applying correctly within a @media query

I'm still in the process of learning how to code, so please bear with me. I am attempting to create a navigation bar that, on desktop, will be displayed horizontally on the right side of the screen. However, when viewing on a device smaller than 800px ...

swapclass and initial padding

Firstly, I am not fluent in English. Secondly, my issue pertains to "toggleClass". I am a newbie to jQuery and JavaScript, and here is my code snippet: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.mi ...

Creating a dynamic calendar text box with JavaScript: a step-by-step guide

I am trying to dynamically add a calendar text box on each click of a link. While I have tested some codes, it seems that the functionality only works for the first declaration and not for subsequent ones. Here's the code snippet I have been working ...

Loop through every list item within each unordered list using JQuery

I am currently using a loop to iterate through each li element and search for specific content within it. If the content matches certain criteria, I add a class to that li element. However, the issue I am facing is that there are multiple UL elements in th ...

Challenge with Bootstrap Popover: Unable to Capture Button Click Event inside Popover

First of all, here's a link to the problem on jsfiddle: jsfiddle.net The issue I'm facing is with a popover that contains html content including a button with the class "click_me". I've set up jQuery to listen for a click on this button and ...

Enhance Your Website with WordPress and Facebook Integration (requires understanding of PHP)

I was able to retrieve the number of Facebook comments using this function: <?php function fb_comment_count() { global $post; $url = get_permalink($post->ID); $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url) ...

ng-bind stops updating after entering text into input field

I am a newcomer to AngularJS and I have encountered an issue that I am struggling to resolve. Although I found a similar question on stackoverflow, the solution provided did not work for me. The problem I am facing is that when I input text into any of the ...

What is the reason behind IE's decision to reduce the size of password boxes compared to text

Take a look at the uncomplicated form right below. You'll notice that it consists of a text box positioned above a password box. In older versions of Internet Explorer like 7 and 8, as well as possibly in other browsers, you might observe that the tex ...