Attempting to align navigation bar in the middle of the page

I'm facing some issues with centering the navigation bar on my website. I attempted to use a wrapper div to center it, but unfortunately, it didn't work out as expected. The only thing that seems to be working within that div is adjusting the left margin. Below is the HTML code:

body {
  background: #bf5c71 url('body-bg.jpg');
}
.clearfix:after {
  display: inline-block;
  clear: both;
  align-content: center;
}
/*----- Menu Outline -----*/

.menu-wrap {
  box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
  -webkit-box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
  display: inline-block;
  margin: 0px auto;
}
.menu {
  display: inline-block;
  margin: auto;
}
.menu li {
  margin-top: 0px;
  margin-right: 0px;
  margin-left: 0px;
  margin-bottom: 0px;
  list-style: none;
  font-family: 'Century Gothic';
}
.menu a {
  transition: all linear 0.15s;
  color: #FF283B;
}
.menu li:hover > a,
.menu .current-item > a {
  color: #F5F5F5;
}
.menu .arrow {
  font-size: 11px;
  line-height: 0%;
}
/*----- Top Level -----*/

.menu > ul > li {
  float: left;
  display: inline-block;
  position: relative;
  font-size: 18px;
}
.menu > ul > li > a {
  padding-top: 2px;
  padding-right: 2px;
  padding-left: 2px;
  padding-bottom: 2px;
  display: inline-block;
  text-shadow: 0px 0px 0px rgba(0, 0, 0, 0.00);
}
.menu > ul > li:hover > a,
.menu > ul > .current-item > a {
  background: F5F5F5;
}
/*----- Bottom Level -----*/

.menu li:hover .sub-menu {
  z-index: 1;
  opacity: 1;
}
.sub-menu {
  width: 100%;
  padding: 3px 0px;
  position: absolute;
  top: 100%;
  left: 0px;
  z-index: -1;
  opacity: 0;
  transition: opacity linear 0.15s;
  box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.0);
  background: 0;
}
.sub-menu li {
  display: inline-block;
  font-size: 16px;
}
.sub-menu li a {
  padding-top: 10px;
  padding-right: 20px;
  padding-left: 20px;
  padding-bottom: 5px;
  display: inline-block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
  background: #FF283B;
}
img {
  border: thin solid #FF283B;
  margin-left: 5%;
}
h3 {
  margin-top: 3%;
  font-size: 24px;
}
.wrapper {
  display: inline-block;
  margin: 0px auto;
}
<div class="wrapper">
  <div class="menu-wrap">
    <nav class="menu">
      <ul class="clearfix">
        <li>
          <div align="center"><a href="index.html">Home</a></a>
          </div>
        </li>
        <li>
          <div align="center"><a href="#">Projects <span class="arrow">&#9660;</span></a>
            <ul class="sub-menu">
              <li><a href="iap.html">Image Adaptation</a>
              </li>
              <li><a href="sonic.html">Sonic Memory</a>
              </li>
              <li><a href="documentary.html">Documentary Video</a>
              </li>
            </ul>
          </div>
        </li>
        <li>
          <div align="center"><a href="resume.html">Resume</a>
          </div>
        </li>
        <li>
          <div align="center"><a href="about.html">About</a>
          </div>
        </li>
        <li>
          <div align="center"><a href="contact.html">Contact</a>
          </div>
        </li>
      </ul>
    </nav>
  </div>
</div>

The only workaround I've found so far is shifting the bar to the left using margin-left.

Website: tylerbr.com

Answer №1

That should suffice:

  .content {
    align-content: center;
  }

Answer №2

To ensure your menu displays correctly, adjust the width and set the display property to "block"

Below is the section of code that needs modification

.menu-wrap {
    box-shadow: 0 0 0 rgba(255, 255, 255, 0) inset;
    display: block;
    margin: auto;
    width: 880px;
}

Answer №3

One way to enhance the appearance of your navbar is by setting it to 100% width and centering the menu text. This can be achieved by applying the following CSS:

.menu-wrap {
    box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
    -webkit-box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
    display: inline-block;
    margin: 0px auto;
    width: 100%;
}

.menu {
    width: 100%;
    display: inline-block;
    text-align: center;
}

Answer №4

If you're seeking the style with margin: 0 auto, check out this code snippet for a clear understanding:

<style>
.wrapper{
    width:100%;
    height: 30px;
    background: black;
}
.centered_div{
    width: 200px;
    background: red;
    margin:0 auto;
}
</style>
<div class="wrapper">
    <div class="centered_div">
        test
    </div>
</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

These coding languages are becoming more popular; however, the <p> tag is nowhere to be found in the slid

Inspect and Fix the Code: Missing p tag when clicked HTML Slide up/down <div class="slideme" class="center"> <h1>Hello,</h1> <p>Can you see Me</p> </div> <but ...

In ASP.NET MVC, use CSS styling specifically for Partial Views by encapsulating the styles within a `<style scoped>` tag

A new HTML attribute has emerged, known as scoped, however, it is currently only supported by Firefox. This attribute allows you to declare internal styles solely for the parent element. I am curious if it is feasible to replicate this functionality in AS ...

Remove the bottom border from the active tab by utilizing the <div> and <a> elements

I am facing an issue with a tabbed menu on my webpage. While the menu is functioning correctly, I am struggling to remove the bottom border from the active tab. You can view all of my test code here. While I have come across solutions using <ul> an ...

Is it possible to add a border to both the tbody and td

I currently have a table that is organized with tbody elements to group rows together. In order to create a grid-like structure, I applied borders to each individual td element within the tbody. However, I also desire to show that the tbodies themselves ar ...

Obtain the value of a range using JQuery

I made an attempt to retrieve the value of JQuery's range slider when it changes. Here is how I tried: On the HTML/PHP page: <div class="total"> <label for="">Total</label> <p><span class="monthrc"></span ...

Harnessing the power of JavaScript functions to display an image when clicked

Looking for help with making an image appear when clicking on one of three images? Despite trying different approaches, the desired result is still not achieved. I'm aware of using if else statements but exploring other methods. Any insights on what m ...

In order to activate the VScode Tailwind CSS Intellisense plugin, I have discovered that I need to insert a space before

I recently followed the installation guide for using Tailwind with Next.js Here is a snippet from my tailwind.config.js file: /** @type {import('tailwindcss').Config} */ module.exports = { content: [ "./app/**/*.{js,ts,jsx,tsx}", ...

Switching the background image when hovering over a list element

Looking at the screenshot, it's clear that there is an unordered list with a background image set on the div. What I am trying to achieve is to have the background image change whenever I hover over a list item. Each list item should trigger a differe ...

A specific class has no border on its left side

Is there a way to use CSS to disable the left border to the right of a cell with a specific class? In the scenario shown in this image, the right border appears double due to the combination of the "selected" class border and the default gray border. I wo ...

Exploring the world of web scraping by using Python to loop through HTML elements

Created a Python script to extract information from the website regarding its asset listings. So far, I have successfully retrieved the name of the first coin "Bitcoin," but I'm unable to get the ticker. With 27 pages on the site, each containing 40 ...

What is the reason for the error message saying "The prefix 'h' for the element 'h:head' is not bound"?

Below is the xhtml code I have created: <html> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/> </h:head> <h:body> <view> <h:form> <br/> ...

I am struggling to increase the width of my input bar and center-align it

Below is the CSS class I've created to ensure that all elements remain centered on the user's screen. container: { display: "flex", position: "absolute", top: 0, left: 0, height: "100%&qu ...

I tried moving the onchange(this) function from HTML to JavaScript, but I seem to have missed a parameter. The code ends

I'm currently building a website for a fictional ice cream shop to enhance my JavaScript skills. function hideAAndB() { var pickupDiv = document.getElementById("pickupDiv"); var deliveryDiv = document.getElementById("deliveryDiv"); pickupDi ...

Having trouble triggering the onclick event on a dynamically created table using JavaScript

I am facing an issue with adding a table programmatically that has an onclick event triggering a specific JavaScript function using the row's id for editing purposes. Unfortunately, the function is not being called as expected. I have attempted to mod ...

Updating the text box's font color to its original black shade

I have a form that includes dynamic text boxes fetching data from the backend. When a user clicks on a text box, the color of the text changes. Upon form submission, a confirmation message is displayed and I want the text box color to revert back to black. ...

Tips for executing a Python function from JavaScript, receiving input from an HTML text box

Currently, I am facing an issue with passing input from an HTML text box to a JavaScript variable. Once the input is stored in the JavaScript variable, it needs to be passed to a Python function for execution. Can someone provide assistance with this pro ...

Implementing a Javascript solution to eliminate the # from a URL for seamless operation without #

I am currently using the pagepiling jQuery plugin for sliding pages with anchors and it is functioning perfectly. However, I would like to have it run without displaying the '#' in the URL when clicking on a link like this: www.mysite.com/#aboutm ...

What is the process for ensuring that an image is set as the submit button in an HTML form on IE 7?

My HTML form is designed with an action on a PHP script, and the submit button displays a custom image instead of the default grey. While this code works perfectly in Chrome, it fails to function properly in Internet Explorer 7. Do you have any suggestions ...

The NG8002 error has occurred, as it is not possible to connect to 'matDatepicker' because it is not a recognized attribute of 'input'

I've come across an issue while working on my Angular 15 application with Angular Material. I'm trying to incorporate a date picker, but after adding the code snippet below, I encountered an error. <mat-form-field appearance="outline" ...

Tips for accessing a local file on a website through HTML - easy steps to follow!

Is it possible to open a local (jpg or pdf) file from a random website that is not under my control? I have tried editing the HTML code of a site in Chrome by replacing existing links with ones linking to my local file, but when I click on them, nothing ha ...