Struggling with aligning buttons in a horizontal navigation bar

I have been struggling to center the buttons on my navigation bar for quite some time now, despite my efforts searching through Google (I'm still a beginner in CSS).

Below is the code I have for the navbar (excluding my numerous unsuccessful attempts).

CSS:

#navigation
{
    list-style-type: none;
    background: #222222;
    overflow: hidden;
    width: 1150px;
    margin: 0;
    padding: 0;
    display:inline-block;
    margin-left: 0 auto;
    margin-right: 0 auto;
}

#navigation li
{
    border-right: solid 1px #ca0002;
    height: 35px;
    display: inline-block;
    margin: 0 auto;
}

#navigation li a:link, #navigation li a:visited
{
    text-decoration: none;  
    display: block;
    height: 35px;
    color: #fff;
    line-height: 35px;
    padding: 0 20px 0 20px;
    border-right: solid 1px #990000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
}

#navigation li a:hover
{
    background: #990000;
    color: #fff;
}

#navigation li.first
{
    border-left: solid 1px #ca0002;
}

Answer №1

Even without any prior knowledge of HTML, I took the initiative to create the necessary code and make use of your unique IDs.

Please refer to this functional JSFiddle demonstration:

DEMO LINK

Within your navigation div, I made some modifications:

    height: auto; 
    text-align:center;

I also removed some unnecessary CSS rules for a cleaner layout.

This adjustment will result in the navigation tabs being centered within the div.

I hope you find this information helpful!

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

What is the manual way to activate Ratchet's push feature?

I am facing an issue with a link that triggers a search function. Currently, the link is working as expected. However, I am having trouble getting the search to be executed by pressing the 'enter' button. Here is my code snippet: $('#sea ...

What is the best way to dynamically validate the fields and generate an array?

Currently in my Angular application, I've successfully implemented a pivot table using pivot.js. Now, I am faced with the task of loading all the indexes from elastic search whenever the user switches the index. Once the index is changed, the corresp ...

The Open Graph share debugger encounters a situation where it scrapes through an empty

Having trouble setting up Open Graph meta tags for a website? Even though the tags appear in the source when accessed through a browser, they don't show up in the OG debugger. The website I'm currently working on is located at spurafrika-org.ver ...

Adding a see-through Bootstrap Navbar to a Fullpage.js website: A step-by-step guide

I am trying to incorporate a transparent Bootstrap Navbar into my page that is using fullpage.js. The desired outcome is for the navbar to stay on top of the page without affecting the layout of the website content. I have referenced an example here, but ...

Utilizing Ajax to dynamically update the content of a div element

As a newcomer to Ajax, I am trying to use xmlhttprequest to dynamically change the content of a div by fetching HTML from different URLs. However, my code doesn't seem to be working as expected. Can someone help me identify what I might be doing wrong ...

How to optimize form fields in Bootstrap by utilizing the size/maxlength attributes in HTML inputs

When I attempted to utilize html5's form size/maxlength with bootstrap, I encountered an intriguing issue. The .form-control class in bootstrap overrides the size, but if removed, the input loses its styling. Check out the code pen here: http://code ...

Utilizing HTML5 and JQuery for Drag and Drop functionality: Moving an image to populate a linked webpage within an iframe upon dropping

Looking to add a drag and drop feature to my project. The left pane will contain tiles that act as images, while the right pane will display iframes. My goal is to drag a tile from the left pane and drop it onto an iframe on the right pane. The twist is th ...

Having difficulty altering the div color in real-time using VueJS

I'm currently in the process of building an application with Bootstrap and VueJS. My goal is to create a folder structure similar to Google Drive, where I want to make a div stand out in blue once it's selected. Below is the code snippet: ex ...

A guide on updating the appearance of a list of comma-separated tags using HTML, CSS, and jQuery

Is there a way to replicate the functionality of the tag section on this website for creating question entries? How can this be achieved? ...

Incorporating URL parameters into an HTML form using JavaScript or jQuery

I need to pass variables in the URL to populate an HTML and Liquid form and then submit it. Here is an example URL: http://www.example.com/[email protected] &customer_password=123456 I came across this question which is somewhat related to what ...

Ways to adjust the select element to match the width of its current option

As I work on building a form, I'm looking for a way to make the select element adjust its width based on the length of its current option. Essentially, I want the select element to expand or contract depending on the width of its longest option. I&ap ...

Issue with Wordpress Submenu Items not Displaying

I've included sub menu items in my primary navigation, but they're not visible at all? I've examined the css and haven't found any code that would hide the sub menu. ul.art-hmenu { display: inline-block; vertical-align: midd ...

Issues encountered with java applet functionality when incorporated into an HTML document

I'm facing a simple issue with my "Hello World" applet not converting into HTML as expected. Even though I have provided the necessary code and base to upload the file, the HTML is showing an error that resembles commands from an operating system ter ...

How can you use jQuery to display an image when hovering over text?

Looking for a tutorial or script that displays an image when hovering over HTML text with the mouse? ...

Error: Attempting to access the 'main' property of an undefined object - React dilemma

For my React webpage, I decided to create a theme using createMuiTheme from material-ui, and here is the palette I defined: palette: { primary: { main: "#333333" }, secondary: { main: "#727171" }, background: { paper: " ...

Steps for transforming numerous HTML tables into a pandas dataframe with the help of a personalized method

I've been facing a challenge in converting multiple HTML tables into a pandas dataframe. I created a function to achieve this, but it's returning an empty list [] instead of the desired pandas dataframe. Here is my current approach: Gathering al ...

Is it possible to permanently alter HTML values with JavaScript?

Can a html value be permanently modified using javascript? I am trying to edit a local file. Below are the codes I'm using: function switchPic(){ top.topPage.activeDef = top.topPage.document.getElementById('h1'); top.topPage.activeDef. ...

Maximizing the potential of Angular forms through native FormData

Currently, I am revisiting an older project that still uses traditional methods for form submission. The HTML includes a form element with defined method and action. My goal is to submit the form in the old-fashioned way using the action attribute to post ...

Generating PDFs with multiple pages using android.graphics.pdf

Currently, I am facing an issue while attempting to generate a PDF using android.graphics.pdf. The problem arises when dealing with multiple pages in the document. While I can provide android.graphics.pdf with HTML content that could be converted into a PD ...

Heading and paragraph text within the same row

I'm currently facing a challenge while working on the personal portfolio webpage project for freecodecamp. Everything looks good except for one issue. Although I have managed to center align my heading and paragraph text as intended, the paragraph te ...