Navigation bar set to align in the center

I'm struggling to align the navigation bar I've designed in the center of the page.

Here is the HTML Code:

<div class="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Mr. A</a></li>
<li><a href="#">Intro</a>
    <ul>
        <li><a href="#">Daily Agenda</a></li>
        <li><a href="#">Handouts</a></li>
        <li><a href="#">Student Work</a></li>
    </ul>
</li>
<li><a href="#">Digital Design</a>
    <ul>
        <li><a href="#">Daily Agenda</a></li>
        <li><a href="#">Handouts</a></li>
        <li><a href="#">Student Work</a></li>
    </ul>
</li>
<li><a href="#">Web Design</a>
    <ul>
        <li><a href="#">Daily Agenda</a></li>
        <li><a href="#">Handouts</a></li>
        <li><a href="#">Student Work</a></li>
    </ul>
</li>
<li><a href="#">AP Computer Science</a>
    <ul>
        <li><a href="#">Daily Agenda</a></li>
        <li><a href="#">Handouts</a></li>
    </ul>
</li>
<li><a href="#">FBLA</a>
    <ul>
        <li><a href="#">Membership</a></li>
        <li><a href="#">Competitions</a></li>
        <li><a href="#">Conferences</a></li>

    </ul>
</li>
</ul>
</div> 


</body>

This is the CSS Code:

html {
    background-color:#2f2f4f;
}
div {
    position:relative;
}

.menu {
    position:absolute;
}

.menu ul {
    padding:0;
    margin:0;
    line-height:30px;
}

.menu li {
    position:relative;
    float:left;
    list-style:none;
    border-bottom-style:solid;
    border-top-style:solid;
    border-color:#c5b358;
    border-width:1px;
}

.menu ul ul {
    position:absolute;
    visibility:hidden;
    padding:0;
    margin:0;
}

.menu ul li a {
    text-align:center;
    font:"Georgia", serif;
    font-size:18px;
    color:#c5b358;
    width:250px;
    height:50px;
    display:table-cell;
    text-decoration:none;
    vertical-align:middle;
}

.menu ul li:hover {
    background-color:#2f4f2f;
    text-decoration:none;
}

.menu ul li:hover ul {
    visibility:visible;
    z-index:1;
}

.menu ul li:hover ul li a {
    background:#2f4f2f;
    z-index:1;
    border-bottom:none;
    opacity:0.9;
    text-decoration:none;
}

.menu ul li ul li:hover {
    background:#2f4f2f;
    opacity:0.8;
    text-decoration:underline;
}

I have tried several options but nothing seems to be working. As someone new to web design, it's been a challenge getting to this point.

Answer №1

After carefully considering your inquiry, I have made adjustments to your css code in order to achieve the desired outcome. Please review the updated code snippet below:

Revised CSS

.menu ul {
    text-align:center;  /* Included */
}

.menu li {
    /*float:left;   Removed */
    display:inline-block; /* Added */
}

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

Navigation isn't aligning correctly on the right side

I am having trouble with my navigation menu not aligning properly to the right. <div class="logo"> <h2><i class="icon-reorder"></i> Frosty</h2> </div> <div class="nav"> <a href="#">Home</a> </div& ...

Issues arise with the functionality of Zurb Foundation 5 tabs

Utilizing the tabs feature in ZURB Foundation 5, I've noticed that clicking on a tab changes the hash in the URL. However, I actually want to prevent this behavior as I rely on the hash for managing page loads. Although I attempted to use preventDef ...

Is there a way to verify if an element has a focused child element using JavaScript?

Currently, I am in the process of eliminating all jQuery from my codebase. In the past, I have been using the following snippet: if ($(selector).find(':focus').length === 0) { // focus is outside of my element } else { // focus is inside ...

Adding a JSON array to HTML using JavaScript

Looking to incorporate JSON Array data into an HTML list with Headings/Subheadings using JavaScript. I experimented with two methods - one involving jQuery and the other mostly vanilla JS. The initial attempt (link here: http://jsfiddle.net/myu3jwcn/6/) b ...

Automatically expand a child node in the tree menu

Hey there! I've got a tree menu that I'm working with. I'm looking to have a specific node in the tree menu automatically open by default. Essentially, I want a particular node to be open when the page is refreshed. For instance, in this e ...

dropdown navigation menu with an image slider positioned ahead

I'm facing an issue with my image carousel using Flickity where the dropdown menu is getting hidden behind it. I have attempted to adjust the z-index property, but even with !important added, it doesn't seem to resolve the problem. I've been ...

What is the best way to display a particular JavaScript variable in an HTML document?

Is there a way to display the value of a Javascript variable in an HTML form, such as showing it on the screen? Below is my JavaScript code: <script type="text/javascript"> var howLongIsThis = myPlayer.duration(); </script> The variable howL ...

Mastering @media queries to dynamically alter widths in prop styled components

I have a unique component that utilizes an object with its props for styling. const CustomSection = ({ sectionDescription, }) => { return ( <Text {...sectionDescription} content={intl.formatMessage({ id: &apos ...

JavaScript Magic: Hide Div when Clicking Away

I need a solution where clicking outside of the My DIV with the ID Container_ID will hide all elements within the Container by setting their style to display: none;. Currently, the JavaScript code I am using partially achieves this functionality, but it al ...

How can we consistently center a window using a grid layout while keeping the elements off-center?

I'm trying to achieve a grid container that always stays centered while the elements with fixed width float left, even when breaking. In my example, the alignment is off and not centered. Can this be fixed with CSS only or do I need to use JavaScript? ...

What is the best way to insert a horizontal line in the middle of a line and include additional content using Vue.js?

I am working on a Login component and trying to center the content like this image. I have tried using horizontal lines but it's not working as expected. Check out my desired output here: [Output 2]. Can someone help me achieve this with simple HTML a ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Updating the contents of one specific div without affecting all other divs with the same class

Below is the HTML code snippet in question: <a class="btn test-btn test-btn-1"> <span>Content 1</span> </a> This particular code block appears multiple times on the page. The number at the end of test-btn- is dynamically generat ...

What might be the reason behind Chrome occasionally not updating the page when I resize the browser window?

Currently, I am in the process of developing a responsive design site prototype. Everything is going smoothly except for one peculiar issue that only seems to occur in Chrome. Sometimes, when expanding the window, the browser appears to get stuck between s ...

XAMPP's main directory

I have been struggling with this dilemma for quite some time, tirelessly searching for a solution. <img src="/images/test.jpg" /> This code snippet fetches an image from the root path, particularly in my case when it's live on a LAMP server. ...

Connecting to a different HTML file functions smoothly on a local server, but encounters difficulties when uploaded to a web server

Here is the structure of my folders: updated /public twitter.html /styles styles.css /views index.html server.js package.json I have an index.html file that is linked to twitter.html. In the .js file, I am using Express and Node.js to link them ...

Creating a custom form to generate a unique URL on a website

For instance, users on a platform like Craigslist can fill out a form specifying their requirements. Upon submission, the platform automatically generates a new URL hosted on its website. I am unsure of how this process works or what it is called. Can an ...

Assign a new class to the anchor tag that has a distinct ID named "link"

I want to add the CSS class "active" to the anchor tag that contains the ID currently active in the URL. Here's what I've tried, but I'm unable to get window.location.hash to function properly. $( "a[href=' + window.location.hash + &ap ...

Preserve HTML element states upon refreshing the page

On my webpage, I have draggable and resizable DIVs that I want to save the state of so they remain the same after a page refresh. This functionality is seen in features like Facebook chat where open windows remain open even after refreshing the page. Can ...

Issues with form inputs alignment in Bootstrap 4 styling

Check out this sample jsFiddle I created, using the html directly from my website. The css for bootstrap 4 is included, which I compiled using sass in addition to my custom css. Everything seems to align perfectly on all screen sizes, except for small dis ...