I am having trouble centering my navigation links on the page

I've tried everything, but I just can't seem to center my navigation bar properly. I'm new to HTML/CSS and struggling with this issue. If you have any suggestions on how to fix it, I would really appreciate your help!

Check out the image of the problem https://i.sstatic.net/AYzxz.jpg

Snippet from my HTML CODE:

    <title>Neon Angels</title>
</head>

<body class="fix">
    <div id="wrapper">

         <div class="section black" id="section1">
              <h2 id="welcome">The Neon Angels Welcome You!
                  <img src="wingslogo.svg" alt="" id="top">
                  <img src="wingslogo.svg" alt="" id="top2">
             </h2>
             <p>
                  <img src="wings.jpg" alt="wings" width="750" id="wings">
             </p>

             <ul class="nav">
                  <li><a href="#section2" style="text-decoration:none">About Us</a></li>
                  <li><a href="#section3" style="text-decoration:none">Painting with Light</a></li>
                  <li><a href="#section4" style="text-decoration:none">Portraits</a></li>
                  <li><a href="#section5" style="text-decoration:none">Nature</a></li>
                  <li><a href="#section6" style="text-decoration:none">Contact Us</a></li>
             </ul>

            <div class="mouse">
                <div class="mouse-icon">
                   <span class="mouse-wheel"></span>
                </div>
           </div>
       </div>
    </div>
</body>
</html>

CSS CODE:

.nav{
    padding-left: 250px;
    padding-right: 250px;
    margin-left: 500px;
    width: 1000px;
    list-style: none;
}

.black ul li{
    display:inline;
    color:#aaa;
    float:left;
}
.black ul li a{
    padding:0px 10px; 
    color:#f0f0f0;
}
.black ul li a:hover{
    text-decoration: none;
    color: #80F9FF;
    font-style: normal;
    font-weight: 400;
    font-family: aguafina-script;
}

#wrapper{
    width: 100%;
    margin: 0 auto;
}

Answer №1

Consider updating your .nav to the following design:

.nav {
  list-style: none;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
} 

Check out this playful demonstration: http://codepen.io/antibland/pen/MyZprK

Answer №2

Here is a helpful code snippet

.menu{
display:flex;
justify-content:center;
width: 1000px;
list-style: none;
}

Answer №3

The reason is that the <li> items are utilizing float: left. If you eliminate this property, then text-align: center will function correctly! Avoid excessive width, margin, and padding on <nav> as it detracts from the appearance on smaller screens!

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

[Tech Issue] encountering app crash upon running npm start command in terminal

My code and the package.json are provided below. I have reviewed similar issues, but the error codes I encountered differ from mine. How can I prevent crashing and successfully run the app? The goal is to have a local site that opens a home page allowing ...

Manipulate HTML elements using JavaScript when a key is being held down

I'm currently developing a simple game using vueJS for the frontend. I have successfully created all the necessary objects and now my goal is to enable their movement when a key is pressed. However, I am facing an issue where the object only moves on ...

What's the solution for aligning these progress bars side by side if floating them doesn't produce the desired result?

I am looking to place two progress bars next to each other, but I have tried using float: left and inline-block without success. I am open to a solution using flex, but I believe there must be a simple fix for this issue. Here is a link to the fiddle for ...

Is it possible to link click and onchange events?

My code includes a function that updates an empty array and displays content in two separate HTML elements each time a radio button is selected from a select list. The content is displayed in a div and a ul element. Additionally, I want to display more rad ...

The battle between Hover, Focus, and Blur modes intensifies

My goal is to implement 4 different effects on an element: When hovering over the element. When moving away from the element. When focusing on the element. When blurred. However, I'm encountering a conflict where when I focus on the element, the ...

Why isn't this code for hiding the animation and displaying it not functioning properly?

Why isn't this animation from display none to block working properly? The initial code appears as follows, and it functions correctly: $(".box_outer").stop().animate({top: '25px' , opacity: 1}, 100); When I add display: none; to the class ...

Having trouble with Select2 functionality within a modal in Bootstrap version 4.6.0?

I've recently started working with bootstrap 4 and I'm already on the lookout for alternatives to solve this issue. Both select2 elements are functioning normally but when I place them inside @include() in the modal tab-content, they behave diffe ...

Having trouble getting my jQuery fade in effect to work

I am having an issue with the fade in / fade out effect using jQuery. The Menu is rendering perfectly and functioning properly, but there is no delay or fade when hovering over the menu items. I'm not receiving any errors, but the expected behavior is ...

Adding DIV classes and IDs to my stylesheet

This is the code that I added to my Stylesheet: .friend { border:4px dashed 008000; } .enemy { border:2px dashed 008000; } .family { border:2px dashed 008000; } #archnemesis { border:4px solid 008000; } * { border:4px ...

Is there a way to automatically redirect my page after clicking the submit button?

I'm having trouble with the code below. I want it to redirect to NHGSignin.php if 'new horizon gurukul' is entered. When I click the Next button, it's supposed to take me there but it's not working as expected. Can anyone help me f ...

Tips for programmatically relocating the slider handle in HTML 5 range input without relying on Jquery UI

INQUIRY: I am facing an issue with an HTML5 range input slider in my project. When I try to change the value of the slider using jQuery, the handle's position remains unchanged. While I am aware that this can be resolved using the .slider() method in ...

I have to define a specific identifier in Django so that I can easily incorporate it into Bootstrap later on

I am working on creating a portfolio in Django. I have a section in my HTML code that connects to my jobs list in Django using {% for ... %} in order to display images, summaries, and titles of my projects. However, there is an ID within this div that refe ...

The high chart data is failing to load

I am brand new to highchart and have just started learning how to create a simple pie chart in HTML. Unfortunately, I am having trouble getting it to work properly. Everything seems correct to me, but for some reason, the highchart is not populating. Here ...

Display each div one at a time

I am working on a script that should reveal my divs step by step. However, the current code only shows all the divs at once when clicked. How can I modify it to detect each individual div and unveil them one by one? For example, on the 1st click => expa ...

Access a particular html tag as a value within an object

Recently, I've been working on AngularJS version 1.6 and am faced with an API containing multiple objects structured similar to the example below: { "description": " <p><a href=\"url">link</a>text</p><p><a href ...

Deciphering HTML with the Eyes

So, I find myself in a bit of a bind trying to come up with a title for this question. I have stumbled upon some HTML files that seem so complex, they could only have been crafted by the one and only Lord Lucifer himself. These files contain segments like ...

How to align two images side by side using CSS: Centering both images side by

Struggling to center two images side by side? Despite efforts, the images always end up stacked vertically. Any tips on achieving the desired side-by-side alignment? Thank you! HTML code <a href="mailto:<a href="/cdn-cgi/l/email-protection" class= ...

Display a message indicating unavailability when no events are scheduled and adjust the background color in FullCalendar

In one of my projects, I am utilizing jQuery FullCalendar to schedule appointments for doctors. The doctors should be able to specify their availability between 9 AM - 5 PM on weekdays. If this is not set, the background color of the spans of time not boo ...

The URL is not being updated despite changes in document.location hash

I have created a script that toggles (show/hide) between different DIVs on the page (highlighted below in the various boxes =). However, I am facing an issue with updating the URL string when switching between different DIVs. For instance, if I navigate t ...

Using JavaScript to store CSS style properties in an array

In the midst of building a React-datagrid project, I am streamlining CSS properties for an array. However, there seems to be redundant CSS properties that I would like to consolidate into an array format. let _columns = []; let commonStyle = {"width":"20 ...