Alignment Problem with Select Menu (HTML/CSS)

I have previously inquired about a similar issue, but this time I am using different code.

My goal is to develop a dropdown menu. Within the main list, there are specific elements that contain dropdown lists (News and Team). These items seem to be shifted to the right for some reason. What I aim for is to align the dropdown items with their parent elements.

Any assistance on this matter would be greatly appreciated.

Thank you

http://codepen.io/DocRow10/pen/hjIkq

<body>
    <div id="container">
        <div id="banner" class="clearfix">

                    <img id="crest" src="images/cecc-logo.png" />
                    <h1>Test Website</h1>
        </div>
        <nav class="clearfix">
            <ul class="clearfix">
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">News</a>
                    <ul>
                        <li><a href="#">Social Events</a></li>
                    </ul>
                </li>
                <li><a href="#">Team</a>
                    <ul>
                        <li><a href="#">Players</a></li>
                        <li><a href="#">Fixtures/Results</a></li>
                        <li><a href="#">Statistics</a></li>
                    </ul>
                </li>
                <li><a href="#">Gallery</a></li>
                <li><a href="#">Contact</a></li>  
            </ul>
            <a href="#" id="pull">Menu</a>
        </nav>
        <main>

        </main>
        <footer>

        </footer>
    </div>

</body>

    body {
  background-color: rgb(200, 220, 255);
/* #455868 */

}

#container {
    height: 1000px;
    margin-left: auto;
    margin-right: auto;
}

#banner {
    width: 100%;
    text-align: center;

}

#crest {
    height: 150px;
    width: 180px;
    display: inline-block;
}

#banner h1 {

    display: inline-block;
}
/* Bat Colour rgb(38, 124, 196); */


@media only screen and (min-width : 480px) {


    #banner h1 {
        font-size: 30px;
        display: inline-block;
    }
}

@media only screen and (min-width : 768px) {
    #banner h1 {
        font-size: 36px;
        display: inline-block;
    }
}
@media only screen and (min-width : 980px) {
    #banner h1 {
        font-size: 47px;
        display: inline-block;
    }
}

nav {
    height: 40px;
    width: 90%;
    margin-left: auto;
    margin-right: auto;
    background-color: rgb(238, 0, 0);
    font-size: 13pt;
    font-family: neris;
    border-bottom: 2px solid #283744;
}

nav > ul {
    padding: 0;
    margin: 0 auto;
    width: 600px;
    height: 40px;
}

nav > ul > li {
    display: inline;
    float: left;
}

nav ul a {
    color: #fff;
    display: inline-block;
    width: 100px;
    text-align: center;
    text-decoration: none;
    line-height: 40px;
    text-shadow: 1px 1px 0px #283744;
}

nav li a {
    border-right: 1px solid #576979;
    box-sizing:border-box;
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
}
nav li:last-child a {
    border-right: 0;
}

nav a:hover, nav a:active {
    background-color: #8c99a4;
}

nav a#pull {
    display: none;
} 

nav ul li:hover ul {
    display: block;
}

nav ul ul {
    display: none;
    position: absolute;
}

nav ul ul li {
    display: block;
}

main {
    width: 90%;
    height: 200px;
    margin-right: auto;
    margin-left: auto;
    background-color: rgb(38, 124, 196);
}

footer {
    width: 90%;
    height: 50px;
    margin-right: auto;
    margin-left: auto;
    background-color: rgb(0, 0, 0);
}

Answer №1

Many elements on a webpage come with default padding values. For instance, all lists typically have padding-left. If you wish to modify this, consider the following:

Incorporate the following line into your CSS script:

ul {
   padding: 0;
}

Alternatively, you can assign a specific id or class for this menu and adjust the padding accordingly.

Answer №2

To ensure proper alignment of your second level ul, make sure to include the following code in your stylesheet:

nav ul ul {
    display: none;
    position: absolute;
    padding: 0;
}

The default left padding of 40px on ul elements may cause misalignment, so it is crucial to remove this padding for a seamless design.

Answer №3

I want to express my heartfelt gratitude for all the assistance provided in solving this issue. After some time, I finally managed to identify the root cause.

In the showcased codepen, there was a crucial detail that I overlooked: The absence of the CSS file for the Foundation Mobile-Responsive framework. This CSS file included styling rules that affected the ul tags by giving them a margin-left of 1.25em, causing the displacement to the right.

To resolve this issue, I made the following adjustment:

nav ul ul {
    display: none;
    position: absolute;
    padding: 0;
    margin: 0;
}

By adding a margin property, the problem was successfully rectified.

Once again, a sincere thank you to all those who contributed to finding a solution. I appreciate your support and apologize for any inconvenience caused.

Wishing everyone continued success and well-being.

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

Using PHP to generate an HTML table with clickable links that retrieve database elements to populate a subsequent page

Currently, my website allows users to select a serial number from a dropdown and submit it, which then populates multiple HTML tables on the display.php page with corresponding database elements. Now, I am looking to achieve the same result using a differe ...

Ways to establish a default search outcome in a search box

Looking to create a search bar with JavaScript and JSON to display default search results for visitors. Currently, the search bar only shows results after text is removed. How can I show predefined search results when the page is loaded? const search = ...

Having trouble connecting the app-route with iron-selector and iron-pages

Feeling frustrated with my code. The <app-route> is functioning correctly, but the frustrating part is that the <iron-pages> just won't apply the class="iron-selected" to any of its children! index.html <app-location route="{{route}}" ...

Updating the src attribute of an image using document.getElementByClassName along with the ngif directive

I am attempting to dynamically modify different icon images on page load using document.getElementsByClassName. The icons are used multiple times and their visibility is controlled by the ngIf directive based on user actions. <img class="viewlist_b ...

Utilizing Blurred Images in the Header

I want to create a blurred background image with text and buttons on top of it, but the blur effect is also affecting the text and buttons. I'm not sure how to keep them separate. header { background: url("street-238458.jpg") no-repeat center; ...

Having issues with column offsetting in Bootstrap v4.0.0-beta

While using Bootstrap 4 Beta (Bootstrap v4.0.0-beta), I encountered an issue with offsetting columns. Previously, I used offset-md-* and it worked fine. However, this feature has been removed in BS4 Beta as per the documentation. The new method suggested i ...

What is the process for uploading an HTML input file in segments?

Is it possible to upload the whole file at once like this: myInput.onchange = ({ target }) => { const file = target.files[0]; const formData = new FormData(); formData.append("fileData", file); // ...then I post "formData" ...

Incorporating dynamic content changes for enhanced user experience can be achieved more effectively with AngularJS

I am utilizing a REST service to retrieve information for a banner. The goal is to dynamically update the slider on the main page using this data. Currently, I am using $http.get to fetch the data, and then implementing interpolation with additional ng-if ...

Add a personalized header to the request sent from the <img/> element

Suppose you have a code snippet similar to this: <img src='images/whatever.jpj' width='' height=''/> Is there a way to set up custom headers for this specific request? I would be grateful for any guidance on this matt ...

The ng-controller directive is not functioning accurately

I attempted to execute the following basic HTML: <!DOCTYPE html> <html ng-app="tempApp"> <head> <script src="js_libs/angular/angular.min.js"></script> <script src="js_libs/angular/bootstrap.js"></script&g ...

How to make a div stick on horizontal scroll using CSS?

In my web application, there is a division that includes a form structured like the following: https://i.sstatic.net/ydEcn.png The table displaying the results beneath the form is wide, requiring horizontal scrolling to view it in its entirety. Is the ...

Overrides of variables are not always complete

After setting up my project with npm install to utilize sass overrides, I encountered an issue. Despite adjusting the $theme-colors, only part of the page reflects the change. https://i.sstatic.net/xjrsx.png I attempted the following: $theme-colors: ("p ...

What is the best way to merge 60 related jquery functions into a unified function?

I designed a webpage that serves as an extensive checklist. When you click on the edit button for a checklist item, a modal window opens up. This modal window contains a radio button to indicate whether any issues were found during the check. If "Yes" is s ...

Discovering and exchanging two div elements using jQuery

Currently tackling a responsive website design. When the screen is resized to mobile view, I must reorganize some div elements. Currently, here's how I'm handling it: $(window).resize(function() { var width = $(window).width(); if( width < ...

What is the method for emphasizing links in the navigation bar with Bootstrap 3?

I am currently working on applying custom CSS styles to the Bootstrap navbar in order to have the link text underlined when hovered over, with a fade-in effect as well. To see what I have accomplished so far, you can view it here: https://jsfiddle.net/xfd ...

Storing a div in a variable using localStorage and retrieving it: a step-by-step guide

This code snippet involves HTML and Javascript. In this scenario, there is a variable storing a div element from page 1. The goal is to pass this variable to page 2, which will be embedded in an iframe within the div of that variable. //Javascript for pa ...

Utilizing form values in a PHP function: a brief guide

Seeking guidance as a newcomer to PHP - I recently created an auto-complete text box using PHP, along with a submit button. However, I neglected to provide a form action. Below is the HTML form code that was used for the autocomplete textbox. This particu ...

Vue 3's Paged.js does not respond to requests for page breaks

Currently, I'm working on implementing page breaks in Vue.js 3. Despite my efforts and utilization of the specified CSS code, I am facing challenges with the ".page-break" class parameter. While I can successfully modify other elements like titlePage ...

Applying a class to a single div element

I am struggling with adding a class to a specific div only if it contains an image. <div class="large-6 columns check-Div"> <div class="custom-table"> <div class="text"> <?php echo $latestimage; ?> </div> ...

Building a Dynamic Web Widget with the Perfect Blend of HTML, JS,

While developing a javascript-based web widget, I am aiming to steer clear of using iframes and avoid relying on the page's CSS. It is infeasible for me to utilize custom CSS, as it defeats the purpose, and iframe integration would not present a user- ...