Why is my navigation bar not centered like the rest of the elements on the page?

Just trying to make everything centered and clean. Everything seems to be, apart from my nav bar at the top which seems to stick to the right?

I can't figure out why?

Thank you

html ..............


<div id="nav">

    <ul>
        <li><a href="#landing">Home</a></li>
        <li><a href="#music">Music</a></li>
        <li><a href="#about">About</a></li>
            <li>Musician</li>
        <li><a href="#instagram">Instagram</a></li>
        <li><a href="#twitter">Twitter</a></li>
        <li><a href="#contact">Contact</a></li>
    </ul>

</div>

                <!-- BELOW THE NAV  -->

<div id="landing">

<br><br><br><p>More content</p>


</div>

............

CSS

.............

body { font-family: 'Source Code Pro', monospace; color: white;

background-color: black;
margin: 0 auto;
max-width: 100%;
text-align: center;


}

div#container {

margin: 0 auto;

}

div#nav {

position: fixed;
vertical-align: top;

display: inline-block;

}

li {

display: inline;

}

div#landing {

background-image: url('rose1.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 100%;
margin: 0 auto;

}

Not sure why the nav is floating to the right?

Answer №1

Check out this solution:

section#navigation {
    position: fixed;
    align-items: top;
    display: block;
    margin: 0 auto;
    top: 0;
    left: 0;
    right: 0;
}

Answer №2

Just updated your code with some CSS tweaks. Hopefully, this will be beneficial to you. Thank you.

Firstly, delete display: inline-block; and insert width: 100%; into div#nav.

div#nav {
    position: fixed;
    vertical-align: top;
    width: 100%;
}

Additionally, remove the default padding-left from ul.

ul {
    padding-left: 0;
}

body { 
    font-family: 'Source Code Pro', monospace; color: white;
    background-color: black;
    margin: 0 auto;
    max-width: 100%;
    text-align: center;
}

div#container {
    margin: 0 auto;
}

div#nav {
    position: fixed;
    vertical-align: top;
    width: 100%;
}

ul {
    padding-left: 0;
}

li {
    display: inline;
}

div#landing {
    background-image: url('rose1.png');
    background-size:cover;
    background-position:center;
    background-repeat:no-repeat;
    height: 100%;
    margin: 0 auto;
}
<div id="nav">

        <ul>
            <li><a href="#landing">Home</a></li>
            <li><a href="#music">Music</a></li>
            <li><a href="#about">About</a></li>
                <li>Musician</li>
            <li><a href="#instagram">Instagram</a></li>
            <li><a href="#twitter">Twitter</a></li>
            <li><a href="#contact">Contact</a></li>
        </ul>

    </div>

                    <!-- BELOW THE NAV  -->

<div id="landing">

    <br><br><br> <p>more content</p>


</div>

Answer №3

To adjust the alignment of div#nav, simply delete the position property from the CSS block:

div#nav {
    vertical-align: top;
    display: inline-block;
}

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

Enhance Your YouTube Comment Section with CSS Styling

I am brand new to css html and I'm attempting to create a comment display system similar to that of YouTube using only CSS. My goal is to have an image of the commenter displayed, followed by their username and comment text listed beside it. So far, I ...

Multiple columns contained within a span

I'm trying to create a panel that displays a list of values with corresponding labels. The requirement is for each label to be positioned above its respective value and aligned to the left. The layout should resemble the following: Label 1 Lab ...

Adding a margin to each page using the @page feature in CSS

I am currently working on a project where I have a dynamically generated HTML page that needs to be saved as a PDF. The issue I am facing is related to the page border, which needs to appear at the edge of the page when printed. To achieve this, I have set ...

CKeditor does not accept special characters or diacritics in keywords

Recently, I came across a helpful code snippet for CKeditor that counts and ranks the most used words in a textarea. This feature is invaluable for generating SEO-keywords suggestions while writing articles. However, there is an issue with non-English char ...

Getting the value from a textarea when submitting a form: The ultimate guide

I have a challenge with using textarea to capture book descriptions because textarea does not have a "value" attribute. How can I pass the value to the bean? However, the method below to capture the value does not appear to be working <textarea cols=" ...

Displaying a div on the click of an image within a for loop using JavaScript

Currently, my website has a blog page that only showcases each individual blog post's photo and title. This is achieved through the use of a FOR loop (shown below). I am interested in implementing a feature where clicking on a blog post's photo o ...

Having trouble getting the edits in my SCSS file to reflect in the HTML

After downloading a theme, I attempted to edit the background of the "navbar_fixed" in the <header class="main_menu_area navbar_fixed"> .scss code for custom CSS. However, despite my efforts, the changes made in the .scss file do not reflect in the H ...

Combining D3.js tooltip positioning with CSS overflow styling

I am encountering an issue with displaying tooltips in D3 when combined with CSS overflow. Is there a solution available for this particular problem? CSS code: #chart1 { overflow-x: auto; overflow-y: hidden; max-width: 800px; max-height: 22 ...

The concept of dynamic inheritance within Struts2's Tiles plugin adds a new

I am currently utilizing the Struts2 framework in conjunction with the tiles 2.0.6 plugin for my web application. Within my webapp, there is a primary "base" layout that comprises of a header, a footer, and the main page content: <definition name="shar ...

Switching videos upon clicking buttons

Hey there! I've got an interesting challenge for you. I have four mp4 videos featuring a cartoon character performing various emotes. My goal is to create a toggle switch that, when activated, will display the first video (intro) along with three butt ...

Developing a user-friendly widget for a website that is not optimized for mobile devices

Here's the backstory: I'm currently in the process of creating a mobile-friendly widget for my clients. Unfortunately, they have web pages that are not optimized for mobile devices, and it doesn't seem like that will change anytime soon. Th ...

Supported video formats in various web browsers

Are there detailed records of video codec compatibility across various desktop and mobile web browsers? ...

Designing a search form to browse through the database by entering a specific title

I am currently working on designing a form to perform database searches for specific titles. However, I have encountered an issue where nothing happens when I try to search, possibly due to a problem with connecting to the database. The link to the appli ...

The HTML5 webpage is failing to send a JQuery Ajax request

I am encountering an issue with my Ajax setup on a HTML page. The call to a web service does not seem to be working as intended, and I suspect that the ajax call is not even reaching the web service at all. The problem arises when I click the button, an e ...

Discovering elements using Selenium in a JavaScript popup box

The issue at hand is rather straightforward. I am faced with the task of clicking on an element within a popup that has been dynamically generated by JavaScript code. The challenge arises as the page is solely accessible in Internet Explorer and the elemen ...

a:hover CSS style altering the behavior of buttons with images in a web browser

Earlier I attempted to ask this question from my phone, but it ended up being overly convoluted and confusing. Therefore, I have decided to start fresh after locating a working PC. Unfortunately, due to the sensitive nature of the project, I am unable to p ...

New Feature in Bootstrap4: Navigation Bar Alignment Shift to the Left

I need help aligning my links to the right side of the page I attempted to use mr-auto but it was not effective <body> <nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top mr-auto mt-2 mt-lg-0"> <a class="navbar-brand" hre ...

Carousel-Owl, glide through two items simultaneously

I am currently in the process of developing a slider using the beta version of Owl-Carousel 2, but I am encountering several issues. My goal is to configure the owlCarousel to function as follows: It should scroll through 2 items at a time while displayin ...

Adjust the spacing between the title and other elements in an R Shiny application

How do I modify the font and size of a title, as well as add some spacing between the title and other elements? navbar <- navbarPage( Title = "Intervals", tabPanel("Data Import", sidebarLayout(sidebarPanel(fi ...

Unable to engage with any items on the display when the Material UI (MUI) Select Menu is active

In my web application, I am utilizing Material UI's Select component. Upon using it, I encountered a restriction where the user is unable to interact with anything else on the screen while the Select menu is open. This includes the inability to click ...