What is causing my navbar's 'ol' element to have a wider width than the

Hello, I have a navigation bar with a dropdown menu using ol. However, when I hover over the list items, the width of the list exceeds that of the ol element. I believe this is due to the white-space: nowrap CSS property, but I want the text in the dropdown list to be displayed on a single line. How can I achieve this?

    <!DOCTYPE html>
    <html>
    <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
        $(document).ready(function(){
            $("#nav ol li").hover(function(){
                $(this).find("ol").show();   //mouseover
            },
            function(){  //mouseout
                $(this).find("ol").hide();
            });
        });
    </script>
    </head>
    <body>
    <div class="wrapper">
            <div id="header">

            </div>
            <div id="nav">
                <ol>
                    <li><a href="#">Home</a></li>
                    <li>
                    <a href="#"> SHUJIN </a>
                        <ol>
                            <li><a href="manga_demo.php"> SHUJIN Episode 1</a></li>
                            <li style="border:none;"><a href="manga_demo2.php"> SHUJIN Episode 2 </a></li>
                        </ol>
                    </li>
                    <li><a href="#">Contact Us</a></li>
                </ol>
            </div>
      </body>
      </html>

CSS

body
        {
            margin:0px; padding:0px;
            background: url("../assets/grey.jpg") no-repeat center center fixed; 
          -webkit-background-size: cover;
          -moz-background-size: cover;
          -o-background-size: cover;
          background-size: cover;
        }
        .wrapper
        {
            margin:auto;padding:0px;width:70%;
        }
        #header     
        {
            margin:0px;padding:0px;width:100%;height:100px;float:left;
            background: #99d6ff;
            background-image: url(""); /* fallback */
            background-image: url(""), linear-gradient(#99d6ff, #006bb3); /* W3C */

            background-blend-mode: multiply;
            /*background-position: 10% 50%; มีsize 100% so this will not work*/
            background-size: 100%;
            background-repeat: no-repeat;

            -webkit-box-shadow: 0px 0px 0px 2px #000000;
           -moz-box-shadow: 0px 0px 8px 0px #000000;
            box-shadow: 0px 0px 8px 0px #000000;

        } 
        #nav{margin:0px;padding:0px;width:100%;float:left;
        background: #80ffe5; /* For browsers that do not support gradients */
        background: -webkit-linear-gradient(#80ffe5, #00b38f); /* For Safari 5.1 to 6.0 */
        background: -o-linear-gradient(#80ffe5, #00b38f); /* For Opera 11.1 to 12.0 */
        background: -moz-linear-gradient(#80ffe5, #00b38f); /* For Firefox 3.6 to 15 */
        background: linear-gradient(#80ffe5,#00b38f); /* Standard syntax */

        -moz-box-shadow: 2px 2px 3px #888, -2px 2px 3px #888;
            -webkit-box-shadow: 2px 2px 3px #888, -2px 2px 3px #888;
            box-shadow: 2px 2px 3px #888, -2px 0px 3px #888;


    }
        #nav ol{list-style:none;margin:0px;padding:0px;}
        #nav ol li{display:block;padding:6px 10px;float:left;position:relative;}
        #nav ol a{display:block;padding:5px 10px;color:#000;text-decoration:none; white-space: nowrap;text-align:center;}
        #nav ol a:hover{color:green;}

        #nav ol li:hover{background:lightgreen;
        -webkit-transition: background-color 0.5s ease-out;
        -moz-transition: background-color 0.5s ease-out;
        -o-transition: background-color 0.5s ease-out;
        transition: background-color 0.5s ease-out;
        }
        #nav ol li ol li:hover{background:lightgreen;
        -webkit-transition: background-color 0.5s ease-out;
        -moz-transition: background-color 0.5s ease-out;
        -o-transition: background-color 0.5s ease-out;
        transition: background-color 0.5s ease-out;   
        }
            #nav ol ol{position:absolute;top:35px;left:0px;display:none;z-index: 1;
                background: #80ffe5; /* For browsers that do not support gradients */
                background: -webkit-linear-gradient(#80ffe5, #00b38f); /* For Safari 5.1 to 6.0 */
                background: -o-linear-gradient(#80ffe5, #00b38f); /* For Opera 11.1 to 12.0 */
                background: -moz-linear-gradient(#80ffe5, #00b38f); /* For Firefox 3.6 to 15 */
                background: linear-gradient(#80ffe5,#00b38f); /* Standard syntax */
            }
                #nav ol ol li{border-bottom:solid 1px lightgrey;width:100%;}

Answer №1

One reason for this issue could be the lack of the box-sizing:border-box property in the class #nav ol li. You can try adding it like this:

#nav ol li {
    display: block;
    padding: 6px 10px;
    float: left;
    position: relative;
    box-sizing: border-box;
}

To learn more about box-sizing, click here.

Answer №2

Greetings! Here is a CSS snippet for you to use:

*{margin:0px; padding:0px; box-sizing: border-box;}

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

Encase the event handler within JQuery

Here's an example of inputs with OnBlur event handlers: <input name="abc" tabIndex="5" class="datetime" onblur="if (CheckMode(this))__doPostBack('abc',''); else return false;" /> Now, in JQuery Form ready function, I want ...

Address Book on Rails

Hello, I'm relatively new to this and would be grateful for any assistance. My goal is to utilize the data saved by a user in their address book, and then offer them the option to use that address for delivery. Below is my Address controller: class A ...

Utilizing Kendo for Dynamic HTML Element Connection

Currently, I am facing a situation where I have three HTML elements. The first is a textbox labeled shipToAddress, the second is another textbox called deliverToAddress, and finally, there is a checkbox named sameAsShipToAddress. In the background, there ...

Having difficulties with JavaScript's if statements

I'm facing an issue with my JavaScript code that is meant to modify the value of a price variable and then display the updated price. The problem arises when I have multiple select options, as the price only reflects the ID of the last statement. Here ...

The .change() function is only executing once and not triggered by multiple clicks

I have a JavaScript file that runs automatically through an HTML script. The issue I am facing is with the putToggleCall() function, which should be triggered every time one of the toggles is clicked. However, it only executes once, even before the docum ...

Having trouble figuring out how to load images into a div based on the current page location?

Looking for a solution to my problem - I have a navigation bar with a fixed div (A) on the far right side. The nav bar remains at the top of the page. There are 6 sections in the body of the page, each being 1200px tall divs. What I want is for a different ...

Get tailored components from a table using Selenium in Python

Currently, I am facing an issue with my code while attempting to extract specific data from a table on a device's web server. The error seems to be related to finding a particular element in a column of the table using what appears to be an invalid ex ...

Is there a method in CSS animations that allows for endlessly repeating successive animations in a specified sequence?

While working with CSS animations, I encountered a challenge of making two animations occur successively and repeat infinitely without merging keyframes. Is there a way to achieve this using only CSS? If not, how can I accomplish it using JavaScript? I a ...

Java Function for Cleaning HTML Id Attributes

Looking for a more elegant solution to sanitize HTML ID attributes? /** * * HTML 4 Specification * ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number * of letters, digits ([0-9]), hyphens ("-"), underscores (" ...

AngularJS radio buttons can now be selected as multiple options

Currently, I am in the process of learning angular and have implemented a radio button feature in my program. However, I have encountered a perplexing issue that I cannot seem to explain. <!DOCTYPE html> <html> <head> <meta ch ...

issues encountered with sending a multidimensional array using ajax, specifically with the index[0]

I'm struggling with sending a multidimensional array from PHP to Javascript/jQuery, encountering a peculiar issue. Upon transmitting index 0 through json_encode($array);, the desired response format is successfully received by the client: [[0,0],[1, ...

Ensure that you provide two arguments when calling the $.ajax success function

I'm facing a little issue. I'm trying to send two variables from PHP to the $.ajax success function Here's my JS code: $.ajax({ type:"POST", url:path, data: "value="+info, success:function(data, data1) { if(dat ...

Is a table cell's border considered as part of its content?

A discrepancy is observed in the rendering of a document on Firefox and Chrome browsers: <!DOCTYPE html> <html> <head> <title>Testing table rendering</title> <style> table { ...

How to adjust animation timing for various elements during a CSS 3D flip with a delay?

Here is a CSS flip setup that I have been working on in this fiddle: http://jsfiddle.net/6r82fzk6/ The Goal: I am trying to achieve a slower transition for the back element compared to everything else. The idea is to have the child element of the back fac ...

Using Jquery to implement autocomplete functionality by iterating over each item with the .each

I have been attempting to implement autocomplete using the .each() function. I am referring to the documentation on http://jqueryui.com/autocomplete/. You can view my attempt in this FIDDLE link where it is currently not functioning as expected. The scen ...

adding html to the end of a JQUERY AJAX request

I've been doing some research online to figure out if what I'm trying to do is possible, but I'm still unsure. Can I add the HTML for a modal at the end of the script, all within the AJAX Success call? Here's the code that I've att ...

Problem with datepicker interface not aligning properly with Bootstrap grid

I am encountering a challenge with aligning the input controls in my UI design. Specifically, I am trying to create rectangular borders/containers around each set of input controls and looking for a way to achieve this using Booststrap. For reference, y ...

Solid white border encasing the full page

While I know there have been similar questions asked before, I believe mine is unique because I haven't found a solution anywhere. Recently, I started a new project in React. I decided to remove App.css and index.css, and created a single component wh ...

Issues with styling classes using global SCSS in React are causing unexpected behavior

Currently, I am working on a React project that includes the use of SASS for styling purposes. While implementing modular CSS in my components, I have encountered an issue with applying styles from a main.scss file in my Layout.js component. The unique a ...

Tips for retrieving data from a JSON file

How can I extract two values from JSON data returned by a jQuery/AJAX request and use them in output without necessarily storing them in variables? Here is the jQuery AJAX statement: $.ajax({ url: "proposemarriage_backend.php", type: 'POST&a ...