What is the best way to adjust the positioning of my hyperlinks in a CSS drop-down menu to be centered on

I have implemented a dropdown menu on an asp.net webform using an external style sheet and html hyperlinks. I am currently working on getting the menu to align in the center of the webpage, where the rest of the content is already centered. Take a look at the code snippet below:

/*Menu System Styles*/
.container {
    overflow: hidden;
    background-color: #0176C5;
    font-family: 'Tahoma', Geneva, sans-serif;
    text-align:center; 
}

.container a {
    float: left;
    font-size: 16px;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    display:inline-block;
}

.dropdown {
    float: left;
    overflow: hidden;
}

.dropdown .dropbtn {
    font-size: 16px;    
    border: none;
    outline: none;
    color: white;
    padding: 14px 16px;
    background-color: inherit;
}

.container a:hover, .dropdown:hover .dropbtn {
    background-color: #2ad32d;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {
    background-color: #ddd;
}

.dropdown:hover .dropdown-content {
    display: block;
}
            <div class="container">
                <a href="home.aspx">Home</a>
                <div class="dropdown">
                    <button class="dropbtn">About Us</button>
                    <div class="dropdown-content">
                        <a href="#">Our Mission and Values</a>
                        <a href="LocalProjects.aspx">Local Projects</a>
                        <a href="NationalProjects.aspx">National & Worldwide Projects</a>
                    </div>
                </div>
                <div class="dropdown">
                    <button class="dropbtn">News & Events</button>
                    <div class="dropdown-content">
                        <a href="#">Recent News</a>
                        <a href="Events.aspx">Upcoming Events</a>
                    </div>
                </div>
                <div class="dropdown">
                    <button class="dropbtn">Prayer</button>
                    <div class="dropdown-content">
                        <a href="DiocesanPrayer.aspx">Diocesan Prayer Circle</a>
                        <a href="Prayer.aspx">Wave of Prayer</a>
                        <a href="IrelandPrayer.aspx">All Ireland Prayer Cycle</a>
                    </div>
                </div>
                <a href="home.aspx">Find a Branch</a>
                <a href="home.aspx">Contact Us</a>
                <a href="home.aspx">Resources</a>
                <a href="home.aspx">130 Celebration</a>
            </div>

Answer №1

Thank you for sharing your CSS code. Here are the modifications I have made.

/*Updated Menu System Styles*/
.container {
    overflow: hidden;
    background-color: #0176C5;
    font-family: 'Tahoma', Geneva, sans-serif;
    text-align:center; 
}

.container a {
    font-size: 16px;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    display:inline-block;
    vertical-align:top;
}

.dropdown {
    display:inline-block;
}

.dropdown .dropbtn {
    font-size: 16px;    
    border: none;
    outline: none;
    color: white;
    padding: 14px 16px;
    background-color: inherit;
}

.container a:hover, .dropdown:hover .dropbtn {
    background-color: #2ad32d;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {
    background-color: #ddd;
}

.dropdown:hover .dropdown-content {
    display: block;
}
<div class="container">
                <a href="home.aspx">Home</a>
                <div class="dropdown">
                    <button class="dropbtn">About Us</button>
                    <div class="dropdown-content">
                        <a href="#">Our Mission and Values</a>
                        <a href="LocalProjects.aspx">Local Projects</a>
                        <a href="NationalProjects.aspx">National & Worldwide Projects</a>
                    </div>
                </div>
                <div class="dropdown">
                    <button class="dropbtn">News & Events</button>
                    <div class="dropdown-content">
                        <a href="#">Recent News</a>
                        <a href="Events.aspx">Upcoming Events</a>
                    </div>
                </div>
                <div class="dropdown">
                    <button class="dropbtn">Prayer</button>
                    <div class="dropdown-content">
                        <a href="DiocesanPrayer.aspx">Diocesan Prayer Circle</a>
                        <a href="Prayer.aspx">Wave of Prayer</a>
                        <a href="IrelandPrayer.aspx">All Ireland Prayer Cycle</a>
                    </div>
                </div>
                <a href="home.aspx">Find a Branch</a>
                <a href="home.aspx">Contact Us</a>
                <a href="home.aspx">Resources</a>
                <a href="home.aspx">130 Celebration</a>
            </div>

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

In my database, I have two tables: Table1 and Table2. To better illustrate my issue, I have included a picture for reference

https://i.stack.imgur.com/GQAMy.jpg I am facing a challenge with joining two tables, table1 and table2, in MySQL. I need assistance in creating the resultant table as shown in the attached picture. Your help in solving this issue would be greatly appreci ...

I am seeking clarification on whether I have session access to the session cookie in order to retrieve the ID each time

I have a requirement to store certain non-sensitive state data such as language and layout preferences. I am curious about the performance comparison between using session storage and cookies. Does the session constantly read the session ID cookie to acc ...

Inventory with complete rationalization

I'm in the process of creating a basic HTML list where the text within the list items is fully justified. Here is the list that I want to justify: <p style="text-align: center;"><strong>Attention Restoration Theory</strong> ...

Stop Opera browser from enhancing HTML5 fields

Currently, I am utilizing numerous inputs with HTML5 types (like 'date' or 'time') through the jQuery Tools library. Certain browsers, such as Opera, have the capability to automatically identify these types and convert them accordingly ...

I'm not entirely sure how JQuery processes the .each() function and the (this) keyword

I'm still learning JQuery and trying to figure it out. Can you help me understand what's going wrong with my code below? I have multiple content blocks with classes .acc-0, acc-1, and so on. I want to show and hide the .plans-breakdown when the ...

Issue with CSS hover effect not being detected in IE 7 on a div element

Need some help with a top navigation setup for a website where I have a div inside an li element. Encountering issues in IE 7 where there are "holes" in the box causing the drop down to disappear when the user is still interacting with it. Initially trie ...

The canvas texture is not properly aligning with the SphereMesh

I have been experimenting with THREE.js and recently tried using a <canvas> element as a THREE.Texture. After finally successfully mapping the object to the mesh, I noticed that the texture was not wrapping around the SphereGeometry as expected; inst ...

Prompting Javascript Alert prior to redirection in ASP.NET

My current code is set up to display a message in an update panel while updating: string jv = "alert('Time OutAlert');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true); It's working well in displaying the me ...

Implementing a feature to display various validation messages in the MVC5 view

On my view, there is a textbox for entering an email address and a submit button. @using (Html.BeginForm("FindMyDetail", "ResetPassword", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) { @Html.AntiForgeryToken() <h4 ...

How can I display a nested div when the parent div's v-if condition is not met?

In my project, I am utilizing Laravel 6 in combination with Vue.js 2. To iterate through users and showcase their information within div elements, I am using a for loop outlined below. The Category names are stored in user.pivot.demo2, and the users are ...

Executing a function should be delayed until all necessary information is obtained from the REST Api

I want to create a chart showing data for each month over the course of 12 months. The data for each month will be retrieved from a REST API. Here is my approach: $.getJSON(link, function(data){ // store data in a variable } Repeat this process 12 t ...

Error occurs when including in EF Core

I've been working on developing an application in ASP.NET Core 7, which includes a PostgreSQL database and utilizes EF Core for managing the data. Currently, I'm facing an issue when trying to retrieve a user along with their associated data. pu ...

Selenium WebDriver is struggling to locate an element using link text

I'm currently facing a challenge in selecting an element that contains an anchor within a paragraph inside a div. The HTML structure I am working with is as follows: <a class="item" ng-href="#/catalog/90d9650a36988e5d0136988f03ab000f/category/DATA ...

Tips for renaming property names during JSON serialization in asp.Net

In my MVC Web API Controller, there is a method that I have exposed: [HttpPost] public JsonResult<CustomClass> Details(RequestClass request) { var encoding = Encoding.GetEncoding("iso-8859-1"); var settings = new ...

Looking for assistance in determining a solution for progress bar implementation

Currently, I am developing a simple application using web technologies like HTML, CSS, and jQuery Mobile. This app enables me to create goals and save them to a listview using the <li> element. Every <li> representing a goal will have an assoc ...

access your notes by logging in as a member

After creating a website where users can register and login with their username/password, I encountered an issue. Once logged in, they are able to create their own notes but there seems to be a problem with allowing them to view their notes on a separate p ...

What is the method to alter the color of the browse button?

I am currently utilizing a custom file input feature from Bootstrap: https://i.sstatic.net/ybCYl.png Is there a way to modify the color of the "Browse" button? My attempts so far: Added a color tag to custom-file-input Added a color tag to custom-file- ...

What is the reason for ASP.Net MVC client side validation not activating when the input is located outside the form element, but is connected through the form="formid" attribute?

ASP.Net 8.0 MVC is the framework I am currently utilizing... The Model includes a Required attribute for the ScenarioName property... Upon wrapping all elements within the form tag and clicking the submit button, client side validation functions properly! ...

Streaming video to multiple clients concurrently using NodeJS

We are currently facing an issue with serving a video stream. Due to the fact that HTML5 video tag does not support udp to multicast, we have been attempting to repurpose an existing ffmpeg stream and broadcast it to multiple responses. Unfortunately, thi ...

Transforming jQuery into vanilla JavaScript in order to create a customized dropdown select functionality

I am struggling with converting jQuery code to pure JavaScript for a custom select element. https://codepen.io/PeterGeller/pen/wksIF After referencing the CodePen example, I attempted to implement it with 3 select elements. const select = document.get ...