``How can I align a menu bar to the center of the page

Creating a navigation bar for my website and aiming to center it. Below are the style and HTML files I'm using:

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
...
<html>
<head>
<meta charset='utf-8'>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
 ...


</body>

</html>

Answer №1

To adjust the alignment of the navigation menu items, first remove the line float: none; from the li element within the CSS code. Next, set the property text-align:center; to the parent element.

#navigationMenu > ul > li
{
    float: none;
}

#navigationMenu > ul
{
    text-align: center;
}

Example

Answer №2

Check out this snippet utilizing Flexbox-

 #cssmenu > ul {
     background: transparent url("images/bg.png") repeat scroll 0% 0%;
     box-shadow: 0px -3px 0px rgba(0, 0, 0, 0.05) inset;
     justify-content: center;
     /*new*/
     -webkit-flex-align: center;
     -ms-flex-align: center;
     -webkit-align-items: center;
     align-items: center;
     -ms-flex-pack: center;
     display: -webkit-box;
     /* OLD - iOS 6-, Safari 3.1-6 */
     display: -moz-box;
     /* OLD - Firefox 19- (buggy but mostly works) */
     display: -ms-flexbox;
     /* TWEENER - IE 10 */
     display: -webkit-flex;
     /* NEW - Chrome */
     display: flex;
     /* NEW, Spec - Opera 12.1, Firefox 20+ */
     text-align:center;
 }

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

Are you struggling with organizing fullcalendar events? Feeling overwhelmed by a challenging layout? Check out the image

Take a look at this mockup I have, and please excuse the chocolate smudges: From what I've observed in the HTML generated by fullcalendar, it seems impossible to achieve this layout. (It doesn't separate each day individually but instead arrange ...

Employing the include functionality within PHP

Currently, I am in the process of developing an eCommerce website and have my own host/domain. To ensure security, I understand that it is advisable to store PHP files in a location separate from public_html. The index.html file is located in /home/user/pu ...

I'm attempting to create a dropdown menu, but I'm struggling to keep it open when I hover over an option

Seeking assistance as a beginner in coding. I am struggling with creating a dropdown menu option on my website. The issue is that the menu closes whenever I attempt to move my mouse to select other options. It seems to work fine when using the run option h ...

Using Bootstrap 4 in HTML, you can customize the size of the file input type and button to

In my HTML project using Bootstrap 4, I have created an input field consisting of both an input bar and a button. While I managed to set the size of the button to "lg" (large), I am struggling to do the same for the input bar. This is the code snippet I ...

Single input results in array output

I have a pair of items in this array list. $.each(data.recalls,function(i) { var recall = data.recalls[i].nnaId; var description = data.recalls[i].remedyDescription; console.log(recall); console.log(description); $('textarea[name= ...

Using jQuery to Convert CSV Data into an HTML Table

I've been exploring the incredible jquery.csvtotable.js plugin for converting csv files to html tables. One question that has been on my mind is how can I allow users to select a .csv file using a browse button that isn't a server-side control? ...

Exploring IndexedDB with Multi-dimensional Relationships

How do you manage many-to-many relationships in IndexedDB systems? For instance, let's consider a scenario where there is a Blog object to represent a blog post and a Tag object for tagging the posts. A single Blog can have multiple tags, and each ta ...

Is it possible for a video embedded in a PDF to play when displayed in html?

Here's my dilemma! Is it possible for a video inserted in a PDF to play when displayed in HTML using any available viewers (such as jquery, javascript, or flash) for viewing PDFs in HTML or HTML5...? After scouring the internet, I could not find any ...

In the world of web design, IE6 has a peculiar quirk where it still displays

This example is created to showcase a specific problem. In between two paragraphs, there's a div element with its height and line-height set to 0, along with margins at 0 as well. Ideally, the paragraphs should be right next to each other without any ...

Is your webpage slow to respond after a page-refresh? (Delayed HTML rendering causing lag)

Whenever I adjust the screen size to that of a phone or any device smaller than 768px, the search bar doesn't display in its proper position until the page is refreshed. It should be correctly placed right from the start. Furthermore, when I resize th ...

The LinkedIn API: Creating a Customized User Interface Experience

I'm experimenting with dynamically populating the data-id attribute with a public URL fetched from LinkedIn search results. Assuming I can retrieve the public profile URL, when I use the script directly on the page (not through JavaScript), it works. ...

Generating distinct identification numbers for each element in an array, regardless of how many times it is invoked on a page

I'm currently working on a website where I have the store's 'open hours' displayed in three different locations within one page. They appear in the header, body, and footer sections. To simplify updates, I decided to use PHP to pull thi ...

The .woff font file was not found on the Azure Node.js web app, resulting in a

I have a collection of fonts stored in my wwwroot directory, as displayed on the console of my Node.js application: https://i.sstatic.net/O0ss4.png These fonts are used in my css like so: @font-face { font-family: myFont; src: url(resources/font/ ...

Trouble with CSS Columns When Resizing Screen

I am currently struggling with a div that contains icons and text next to them. The issue arises when the window is resized smaller, causing the images and text to overlap and appear messy. Here is how it appears in full screen: https://i.sstatic.net/fLPy ...

unable to trigger Javascript using HTML form submission (listener malfunctioning)

My goal is to display the results of a user query submitted through a search bar on my website. However, I'm facing an issue with the HTML form not calling the necessary JavaScript file. Below is the HTML snippet containing the form: I tried incorpor ...

Having trouble with CSS transitions not showing up correctly in Chrome. Any suggestions on how to resolve this issue?

While working on a static website, I attempted to apply a background-color transition to a button. Despite reviewing my code multiple times, I discovered that the issue was not with my coding. It seems like the browser is having trouble displaying CSS tran ...

Learn the process of displaying and concealing elements when hovering over the parent element with Javascript

I am facing a challenge with my containing div that has a 'h1' title and a 'p' description inside it. My goal is to have the 'description paragraph' hidden while the 'title' is visible when the page loads, and to hav ...

How to Use CSS to Perfectly Align Form Elements in the Center of

No matter what I try, I just can't seem to get these form elements centered on the page using CSS. Here is my code snippet: http://jsfiddle.net/VJLst/1/ <style> #divQuizFillBlank { margin-left: auto; margin-right: auto; } #textQuizFill ...

The rows-per-page menu option in Vuetify suddenly vanishes

I'm currently working on incorporating a v-data-table inside a v-card, you can view the code in this CodePen snippet: https://codepen.io/benwasin97/pen/eYveZGL <v-data-table :headers="headers" :items="items" ...

Position the Form in the center of the page using Flexbox and Material UI styling

I am currently attempting to center align a button on the page. In addition, I plan to include a form in that same area, so I require a container or box that is positioned exactly in the middle of the page. Despite specifying a maximum height and width of ...