I am having trouble getting my navigation menu to line up correctly within its designated container

I have included an image that illustrates the issue I am facing. My goal is to align the navigation menu with the navigation container so they appear seamless. The image highlights the "E-MAIL" element of the navigation menu and the yellow strip representing its container (as specified in the code below).

Despite my attempts with negative margins on the navigation container, I have not found a solution yet.

You can view the graphic here: http://jaylefler.com/webgraphic.png

<!DOCTYPE html>
    <html>
    <head>
        <title>css example</title>

    <style type="text/css">


    #logo {
        background-color: black;
        width: 100%;
        color: rgb(255,200,0);
    }

    #logo img {
        padding: 10px;
    }

    body {
        font-family: Arial, Helvetica, Verdana;
        margin: 0;
    }

    #contents {
        border: 2px solid black;
        border-radius: 15px;
        box-shadow: 6px 6px 4px 4px #000;
        width: 90%;
        min-height: 650px;
        margin: 0 5%;
        margin-top: 15px;
        padding: 15px;
    }

    #navMenu {
        width: 760px;
        height: 30px;
        background-color:rgb(255,200,0);
        border:1px #000 solid;
        font-weight:bold;
        margin-left: -2px;
    }

    #navMenu ul{
        margin:-1px 0 0 0;
        padding:0;
        line-height:32px;
    }

    #navMenu li{
        margin:0;
        padding:0;
        list-style:none;
        position:relative;
        background-color:rgb(255,200,0);
        float:left;
        border:1px #000 solid;
    }

    #navMenu ul li a{
        text-align:center;
        text-decoration:none;
        height:30px;
        width:150px;
        display:block;
        color:#000;
    }

    #navMenu ul ul{
        position:absolute;
        visibility:hidden;
        top: 31px;
        margin-left: -2px;  
    }

    #navMenu ul li:hover ul{
        visibility: visible;
    }

    #navMenu a:hover {
        background-color:#000;
        color:rgb(255,200,0);
    }

    .left_part {
        background:black;
    }

    .right_part {
       background:yellow;   
       float:right;
       white-space:nowrap;
       display:inline;
       text-overflow:ellipsis;
       overflow:hidden;
    }

    #navContainer {
        background-color:rgb(255,200,0);
        width:100%
        margin-top:-3x;
        padding:0;
        border:1px solid;
        height:31px;
        clear:left;

    }

    </style>

    </head>

    <body>

    <div id="logo">

        <div class="left_part">
            <img src="demo.gif">
        </div>

        <div class="right_part">

        </div>

    </div>


    <div id="navContainer">
        <div id="navMenu">
            <nav>
                <ul>
                    <li><a href="#">HOME</a></li>
                    <li><a href="#">PROFILE</a></li>
                    <li><a href="#">MANAGE SUB</a>
                    <ul>
                        <li><a href="#">VIEW TITLES</a></li>
                        <li><a href="#">ADD TITLE</a></li>
                        <li><a href="#">MODIFY TITLE</a></li>
                        <li><a href="#">REMOVE TITLE</a></li>
                    </ul>
                    </li>
                    <li><a href="#">NEW RELEASES</a></li>
                    <li><a href="#">E-MAIL</a></li>
                </ul>
            </nav>
        </div>
    </div>

    <div id="contents">

        <p>This is just some dummy text.   </p>

    </div>

    </body>
    </html>

Answer №1

#navmenu {
    width: 760px;
    height: 30px;
    background-color: #FFC800;
    border: 1px black solid;
    border-top: 0; /* REMOVING THE TOP BORDER */
    margin-left: -2px;
}
#navContainer {
    background-color:rgb(255,200,0);
    width:100%
    height: 30px; /* MATCHING THE HEIGHT */
    margin-top:-3x;
    padding:0;
    border:1px solid;
    height:31px;
    clear:left;

}

Answer №2

After performing a quick cleanup, I have removed the logo image part from the code. You can easily add that back in on your own.

Below is the simplified and corrected version of your code:

<!DOCTYPE html>
<html>
<head>
    <title>css example</title>

<style type="text/css">

body {
    font-family: Arial, Helvetica, Verdana;
    margin: 0;
    padding: 0;
}

#contents {
    border: 2px solid black;
    border-radius: 15px;
    box-shadow: 6px 6px 4px 4px #000;
    width: 90%;
    min-height: 650px;
    margin: 0 5%;
    margin-top: 15px;
    padding: 15px;
}

nav {
    width: 100%;
    height: 30px;
    background-color:rgb(255,200,0);
    border-bottom:1px solid #000;
}

nav ul{
    padding:0;
    margin: 0;
    overflow: hidden;
}

nav > ul{
    min-width: 755px;
}

nav ul li{
    float: left;
    margin:0;
    padding:0;
    list-style:none;
    background-color:rgb(255,200,0);
    border-right:1px solid #000;
}

nav ul li a{
    text-align:center;
    text-decoration:none;
    width:150px;
    height: 25px;
    padding-top: 5px;
    display:block;
    color:#000;
}

nav ul li ul{
    position:absolute;
    visibility:hidden;
    top: 31px;
    border-bottom: 1px solid #000;
    border-left: 1px solid #000;
    margin-left: -1px;  
}

nav ul li:hover ul{
    visibility: visible;
}
nav ul li ul li {
    float: none;
}

nav a:hover {
    background-color:#000;
    color:rgb(255,200,0);
}


</style>

</head>

<body>
<nav>
    <ul>
        <li><a href="#">HOME</a></li>
        <li><a href="#">PROFILE</a></li>
        <li><a href="#">MANAGE SUB</a>
        <ul>
            <li><a href="#">VIEW TITLES</a></li>
            <li><a href="#">ADD TITLE</a></li>
            <li><a href="#">MODIFY TITLE</a></li>
            <li><a href="#">REMOVE TITLE</a></li>
        </ul>
        </li>
        <li><a href="#">NEW RELEASES</a></li>
        <li><a href="#">E-MAIL</a></li>
    </ul>
</nav>

<div id="contents">

    <p>This is just some dummy text. </p>

</div>

</body>
</html>

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 Jquery to implement toggle feature with z-index integration

I am attempting to replicate the Toggle open/close div effect shown in the sample image below: https://i.sstatic.net/geAQa.png Css: .area1 { width: 50px; height: 200px; background: red; display: inline-block; z-index:99; } .area2 { ...

Share an image using only the publish_actions authorization

There are some apps I've come across that only request access to users_photos and publish_actions (not publish_stream or photo_upload). Surprisingly, they are able to upload photos without being approved for User Generated Photos (e.g. Instagram). Wh ...

Library written in JavaScript for extracting CSS that is relevant

Is there a JavaScript tool available that can extract the style information from HTML code? For instance, when given the following HTML snippet, it would output a style block containing all the computed styles applied to each of those elements? Input... ...

Select a random class from an array of classes in JavaScript

I have a collection of Classes: possibleEnemies: [ Slime, (currently only one available) ], I am trying to randomly pick one of them and assign it to a variable like this (all classes are derived from the Enemy class): this.enemy = new this.possibleEn ...

The screen should smoothly slide upwards when the keyboard pops up, ensuring the footer remains und

Hello! I am currently in the process of developing a mobile app using HTML, CSS, Bootstrap, and JavaScript. I have encountered a slight issue where the keyboard does not automatically pop up and move the screen up when the user taps on the textbox in the f ...

I can't seem to get my SCSS files to load properly on GitHub HTML pages, and I

Just starting out in the world of programming and decided to showcase my portfolio site on GitHub. While my index page is displaying correctly, I'm encountering issues with some images and all of my SCSS files not showing up. Any assistance or guidanc ...

What is the proper way to create a 'swiper' object in JavaScript?

I'm working on incorporating a horizontal timeline into my HTML page. I came across a template online that allows for a scrollable timeline. However, upon attempting to load the page, I encountered the error message "ReferenceError: Swiper not defined ...

Utilizing DataTable in Angular 2: A Step-by-Step Guide

I am struggling to implement the DataTable in my Angular 2 application. It seems like adding a script tag directly into templates is not supported in Angular 2. Can anyone guide me on how to make this work? I have a feeling that I need to make some adjustm ...

What could be the reason for the clone function not duplicating the data within the table

Recently, I utilized jQuery's clone method to duplicate and add an HTML table. The rows and cells of the table were added using jQuery. However, despite using clone, it only replicated the headers and CSS, not the appended data. This raises the ques ...

The 'Access denied' error in JavaScript occurs when attempting to display deployed images on a generated HTML page within a Java web application

My Java web application, which deploys HTML pages through an EAR/WAR file on a JBoss server, has been functioning without issues for some time now. However, recently I've received numerous reports from users about images not displaying. Upon enabling ...

Hidden Div on Google Maps no longer concealing

Since early December, the Google map on my site has been working perfectly. However, the other night, I noticed that the map now defaults to open when entering the site and cannot be closed. Strangely, all my Google maps are behaving this way even though n ...

What is the reason behind the _set.all function not working in the template?

I have a scenario where I have three interconnected models: GroupRequirementType --> GroupRequirement --> Requirement. When trying to display all requirements in the template, only GroupRequirementType objects are being shown. It appears that there m ...

Datatables jQuery provides the ability to dynamically assign array index values to the 'sClass' property

Consider this code snippet: let dataSet = [ ['1', 'Safari','Mac OS X','13.1','A','N/A'], ['2', 'Chrome','Windows 10','90','B','N/A&a ...

Chrome displaying elements out of alignment

Anyone have any insights into why my webpage elements are displaying differently in Chrome compared to IE? It's driving me crazy! Here's a screenshot of how it looks in Chrome: https://i.sstatic.net/xAlEi.jpg And here's how it appears in IE ...

Is there a way to use JavaScript to rearrange the order of my div elements?

If I have 4 divs with id="div1", "div2", and so on, is there a way to rearrange them to display as 2, 3, 1, 4 using Javascript? I am specifically looking for a solution using Javascript only, as I am a beginner and trying to learn more about it. Please p ...

Submit the scaled-down form image to the server

When attempting to upload a resized image to the server, an error stating "Required MultipartFile parameter 'file' is not present" occurs. Interestingly, this error only appears when trying to upload the resized image, as uploading the original f ...

Tips for inserting data into a form using javascript

I am attempting to include POST inputs in a form using an Onclick function. After confirming the information is correct with Javascript, I want to add additional information, such as IdCrono, before submitting the form via Javascript form.submit(). Current ...

Using HTML: What is the best way to match the width of children elements to the width of the

Is there a way to make a child element on my HTML page fill the entire browser window, even when resizing? I want it to stay enlarged and maintain its size as the browser window is resized after loading. I'm unsure if I need to move this object outsi ...

How can I display an image from PHP on another page?

I need to display multiple images from a database on the index.php page interface. <?php while($row = $result->fetch_assoc()) { ?> <table border="1" width="702" height="149" align="center"> <tr> <td width="148"><img sr ...

Display all event date markers, even if some dates are missing

Using the FullCalendar plugin has been a great experience for me. I have managed to successfully read data from a JSON object with the following code: function press1() { var employees = { events: [] }; ...