Center the ASP menu horizontally on the page

I'm having trouble centering the menu bar horizontally. The number of main menu items can change with each user login. Currently, the menu bar is starting around 30% from the left. I have attempted using display: inline-block and display: table for #menuContainer.

When there are 5 main menu items and I set the width of #menuContainer to 30%, it seems to be centered.

ASPX:

<div id="divMenu">
 <div id="menuContainer">
  <asp:Menu id ="menuBar" runat="server" Orientation="Horizontal" 
   IncludeStyleBlock="false">
    <item>
     <asp:MenuItem Text="Home"></asp:MenuItem>
     <asp:MenuItem Text="Folio">
       <asp:MenuItem Text="Nature"></asp:MenuItem>
       <asp:MenuItem Text="People">
         <asp:MenuItem Text="Tribe"></asp:MenuItem>
       </asp:MenuItem>    
     </asp:MenuItem>
     <asp:MenuItem Text="Contact"></asp:MenuItem>
    </items>
   </asp:Menu>
  </div>
 </div>

CSS:

#divMenu
{
position:fixed;
left:0;
top:7%;
z-index:2;
width:100%;
height:5%;
}
#menuContainer
{
width:50%;
margin:0 auto;
}
#menuBar
{
 position:fixed;
 top:5.3%;
}
#menuBar ul
{
list-style:none;
background-color:silver;
padding:0 5px;
}

RENDERED HTML:

<div id="divMenu">
  <div id="menuContainer">
    <a href="#menuBar_SkipLink"><img alt="Skip Navigation Links" src="/..sometext"   
     width="0" height="0" style="border-width:0px;" /></a>
    <div id="menuBar">
      <ul class="level1">
         <li><a class="level1" href="#" onclick="...">Home</a></li>
         <li><a class="popout level1" href="#" onclick="..">Folio</a>
             <ul class="level2">
                <li><a class="level2" href="#" href="#" onclick="..">Nature</a></li>
                <li><a class="level2" href="#" href="#" onclick="..">People</a>
                  <ul class="level3">
                   <li><a class="level3" href="#" onclick="..">Tribe</a></li>
                   </ul>
                </li>
             </ul>
          </li>
          <li><a class="level1" href="#" onclick="...">Contact</a></li>
      </ul>
</div><a id="menuBar_Skiplink"</a></div></div>

Answer №1

Check out this JSFiddle link

<div id="divMenu">
 <div class="menuContainer">
         <a>Item 1</a>
         <a>Item 2</a>
  </div><br><br>
 <div class="menuContainer">
         <a>Item 1</a>
         <a>Item 2</a>
         <a>Item 3</a>
  </div><br><br>
 <div class="menuContainer">
         <a>Item 1</a>
         <a>Item 2</a>
         <a>Item 3</a>
         <a>Item 4</a>
  </div><br><br>
 </div>

-

-- css --
#divMenu {position:fixed;text-align:center;left:0;right:0;top:7%;z-index:2;height:5%;}
.menuContainer {display:inline-block;margin:0 auto;background-color:silver;text-align:left;clear:both;}

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

Vue Template ref Error: Unable to access scrollHeight property of null object

I'm currently working on creating a responsive sidebar in Vue, and I encountered an issue after refactoring my project to remove the state.js file. The problem is related to the dropdown/collapse elements, and it's throwing a TypeError: Cannot re ...

Event delegation will be ineffective when the target element is nested within another element

After receiving a recommendation from my colleagues on Stackoverflow (mplungjan, Michel), I implemented the event delegation pattern for a comment list. It has been working well and I am quite excited about this approach. However, I have encountered an iss ...

How can I design a tooltip window using HTML, jQuery, or other elements to create a box-like effect?

As someone who is new to front end development, I am facing a challenge with my web app. The requirement is that when a user hovers over an image, I need a 'box' to open nearby and display a pie chart. Although I have managed to get the hover fu ...

Items outside the container element

I recently noticed an issue with my website, which is built using Bootstrap. The problem arises when users scroll down the page and encounter the fixed navigation menu. It appears that the menu items and logo are no longer contained within the designated ...

The amazing property of AngularJS - Scope

I have saved this HTML code in a file. Here is the HTML : <!-- checkbox 1 --> <input type="checkbox" name="checkbox1" id="checkbox-group1" ng-model="checkbox1" value="group1"> <input type="checkbox" name="checkbox1" id="checkbox-group2" ng ...

When PHP is connected to the database, Ajax remains inactive and does not perform any tasks

I am currently working on setting up a simple connection between JavaScript and my database using ajax and PHP. The goal is for JavaScript to receive a name from an HTML form, make changes to it, send it to PHP to check if the name already exists in the da ...

Implement a feature in JavaScript that highlights the current menu item

I'm currently developing a website at and have implemented a JavaScript feature to highlight the current menu item with an arrow. The issue I'm facing is that when users scroll through the page using the scrollbar instead of clicking on the men ...

Interactive email with a dynamic dropdown feature

I am currently working on creating an HTML email that can display data depending on the selection made from a dropdown menu within the email itself. Despite my research, I have not come across a suitable solution for this specific scenario. My current app ...

Tips for getting free jqgrid to display frozen column borders in the search toolbar

If the actions column has a caption of "Activity" or custom settings and is frozen, the free jqgrid will not display column borders for this column in the search toolbar. Vertical lines do not appear in the search toolbar: Is there a way to resolve this ...

Issue with calling a function to change the CSS color class of a button in Angular

Within my Angular code, I am attempting to set a CSS color for my button by calling a TypeScript function that will return the appropriate CSS class name. This is the code I have tried: <button style="height: 10%" class="getColor(days.date)">{{days ...

Tips for managing JavaScript errors

<ItemTemplate> <tr class="row"> <td style="width: 88%;"> <input id="hdnPackageProuctId" type="hidden" value='<%# Eval("ID")%>' /> <div style="float:left; margin-top:5px;height: ...

Despite implementing the necessary middleware, the CSS file still refuses to load

My CSS files are not loading properly. When I inspect the element (F12) and go to Networks, my CSS file is not visible. I have added the middleware: app.use(express.static(path.join(__dirname, '/public'))); and required the path above it. I ha ...

Transforming an image into a CSS-powered website menu button: Step-by-step guide

I am currently using images as button backgrounds, and I have programmed them to change when the button is clicked to give the impression that it is being pressed. However, I am looking to enhance the responsiveness of the page, so that the images also cha ...

Receive null from GetExternalLoginInfoAsync using OWIN in ExternalLoginCallback unless already authenticated through Google

Recently, I've been trying to set up external logins with OWIN in an MVC5 application using a Google account. When I am already logged into Google, clicking the Google button in my app works smoothly and redirects me to the registration page after gr ...

Tips on sending the total value of a form to a PHP script

Looking for help with a PHP script to calculate the sum of checked checkboxes with corresponding numeric values. For example, if checkbox 1 = 80; checkbox 2 = 21; and checkbox 3 = 15, and the user checks checkboxes 2 and 3, the PHP should output 36. I hav ...

the display window is not visible

After implementing the following asp.net server code, my page is being redirected without displaying the print window: ScriptManager.RegisterStartupScript(this, typeof(Page), "printGrid", "javascript:window.print();", true); Page.Response.Redirect(Page. ...

What sets apart the <script> tag with a type attribute from the standard <script> tag in HTML?

Similar Question: Is it necessary to include type=“text/javascript” in SCRIPT tags? While working on my HTML project, I noticed that the JavaScript code within script tags is evaluated even if the type attribute is not explicitly set to "j ...

Check to see if the ContentEditable div is currently focused

I'm struggling to determine if a contenteditable div has focus with my current code. Here is what I have so far: if ($("#journal-content:focus")) { alert("Has Focus"); } else { alert("Doesn't Have Focus"); } The issue I'm encounter ...

The background is set and the vertical scrolling overflow is enabled

My website has an image set as the background, with a fixed position and overflow-y to allow scrolling. However, I have encountered an issue where the height of the image is causing problems on certain displays and resolutions. To temporarily fix this pro ...

Troubles encountered when wrapping columns in bootstrap framework

I'm experimenting with a design that utilizes Bootstrap's grid system, but I'm experiencing some challenges with the content either wrapping or extending off-screen. What I want is to have a sidebar with fixed width (around 250px), and its a ...