Struggling to properly align the navigation element in the header

Currently, I am gaining experience by working on websites but I have encountered an issue with a specific element. It seems that the id headerInner and the class navLogo are displaying at 1200 x 0 pixels when inspected. My goal is to place all the links and the logo in a box, centered within the header. However, the result is not as expected:

https://i.sstatic.net/EABd9.png

Here is the HTML code snippet:

<body>
<header>
    <div id="headerInner">
        <nav class="navLogo">
            <a href="#" id="menuIcon"></a>
            <ul>
                <li>
                    <a class="current" href="index.html">Home</a>
                </li>
                <li>
                    <a href="studio.html">Studio</a>
                </li>
                <li>
                    <a class="navLogo" href="index.html"><img 
                     src="img/navBanner.png"></a>
                </li>
                <li>
                    <a href="live.html">Live</a>
                </li>
                <li>
                    <a href="contact.html">Contact</a>
                </li>
            </ul>
        </nav>
    </div>
</header>

And here is the relevant CSS code:

header {
  margin: 0 auto;
  border-bottom-right-radius: 50px;
  border-bottom-left-radius: 50px; 
  background-color: #a30101;
  width: 95%;
  height: 86px;
}

#headerInner {
  max-width: 1200px;
  margin: 0 auto;
}

#logo {
  margin: 20px;
  float: left;
  width: 200px;
  height: 60px;
  background: url(img/logo.png) no-repeat center;
}

nav {
  margin: 0 auto;
  padding: 0;
}

.navLogo {
  margin: 0 auto;
}

#menuIcon {
  display: hidden;
  width: 40px;
  height: 40px;
  background: url(img/nav.png) center;
}

a:hover#menuIcon {
  border-radius: 4px 4px 0 0;
}

ul {
  list-style-type: none;
}

nav ul li {
  font-family: 'Alegreya', sans-serif;
  font-size: 150%;
  display: inline-block;
  float: left;
  padding: 10px;
}

Answer №1

Place the ul element within the div.menu-container as shown below:

<div class="menu-container">
  <ul>
   [...]
 </ul>
</div>

Next, apply some styling to it:

.menu-container {
 text-align: center;
}

ul {
 display: inline-block;
 margin: 0;
 padding: 0;
}

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

What causes larger breakpoints to collapse earlier than smaller breakpoints?

Compare the following two code snippets that use bootstrap: a) <div class="row"> <div class="col-lg-4" style="background-color:blue;">First</div> <div class="col-lg-8" style="background-color:red;">Second</div> </di ...

The website content is not visible on Internet Explorer version 10

Issue with Internet Explorer 10 I recently completed a new website for our company: . However, I am encountering some challenges with the site when viewed on IE 10 on Windows 7. For some reason, a large portion of the text is not displaying properly in IE ...

Adjusting the height of a link to match the available space within a navbar using Bootstrap 4

I'm facing an issue with my navbar: <nav class="navbar navbar-light bg-light"> <span class="navbar-brand mb-0 h1>Brand</span> <a>I wanna grow</a> </nav> My goal is to have the link inside the navbar expand to ...

Challenges Faced When Implementing Dropdown Navigation Bars

Whenever the screen width is less than 576px, I notice that the menu icon on my website shifts its position along with the title (FOOD, LLC). How can I resolve this issue? Website: ...

Is there a method to incorporate HTML5 <keygen> functionality within MS Internet Explorer?

The HTML5 specification has brought back Netscape's idea of the <keygen> tag, which is used to securely generate a pair of keys. This tag has been widely adopted by browser vendors such as FireFox, Safari, Chrome and Opera. However, there is al ...

Adjust the button's width as the text changes to create a dynamic animation

I'm trying to create an animation effect where the width of a button changes whenever the text inside it is updated. I've attempted using useRef on the button itself to grab its clientWidth and then applying that value to a CSS variable in order ...

Elevate the value of a particular element's variable through the execution of a function

By using a for loop, I was able to generate a variable number of divs that change their background color individually when hovered over with the mouse. Now, I want to implement a function that will decrease the brightness of each div by 10% every time it i ...

Is it possible to make changes to my sass file using the Chrome dev tool's element tab?

Within my project, I have a Sass file where I set the sourcemappath using node-sass for compiling. By mapping my .css file on my system, any changes made through the source panel are automatically saved to the disk and compiled back by node-sass. However, ...

Is there a way to remove background-color for a:focus?

When working with Twitter Bootstrap, I encountered a challenge. The background-color properties set for navigation items on the :focus state were causing an issue for a specific navigation element that needed have its own styling. Imagine a scenario where ...

React CSS modules are a powerful tool for styling components in

Having some difficulty with css modules in react, I am unsure how to utilize react modules dynamically. import classnames from 'classnames' import styles from './hover.module.css /// /// const [flashElements,setFlashElements]=useState(elemen ...

Want to learn the process of closing a modal using Javascript?

I am working on implementing 6 different modals, each featuring an exit button named 'modal-box__exit-button'. I have attempted to use JavaScript to close the modals when the exit button is clicked, but it seems like my code may have some errors. ...

Tips for vertically centering text within a panel using Bootstrap 3

I am facing an issue where I have an image and a description inside a panel panel-default. The image is floated to the left while the description is on the right side. The image has the img-responsive class so that it adjusts according to the panel body w ...

Selecting a language by clicking on it

I recently designed a bootstrap navigation bar for my website and incorporated a language selection dropdown menu into it. <li class="nav-item dropdown"> <a class="nav-link dropright" href="#" id="navbarDropdown" role="button" data-toggle="dr ...

Strikeout list on click of a mouse

Is there a way to apply strikethrough formatting to text with just a mouse click? The CSS for lists is beyond the form field margin. I've tried multiple methods without success. No matter how many times I change the code, I can't seem to get it r ...

Eliminate unnecessary gaps by using HTML to position images side by side without vertical space

I am just starting out with html and css coding and recently I built my first website using wordpress. On one of the pages in wordpress, I wanted to display images next to each other with a small space between them. I achieved this successfully, but unfor ...

Mobile Safari on iOS devices is known for its capability to overlay HTML5 <video> on top of everything

Although a similar question was asked 6 years ago without any answers, I am currently facing the same issue. Problem: The <video> tag in my Angular/Ionic application overlaps my image and two buttons in iOS Mobile Safari - no matter what I try! It ...

Exploring HTML for a specific value using Swift

My journey into learning Swift and Xcode began with a simple project. I decided to work on a project that involved finding a specific value on a website. After successfully retrieving the HTML code, my next step is to isolate and extract the exact value I ...

Tips for shortening button text within a flex child element

I'm struggling to achieve a specific layout using flexbox. I require one child element that does not shrink, and two child elements that can shrink/grow and be truncated based on their content while considering the sizes of their content. My current ...

Is it possible for the relative path of a gif image to become invalid when added to a div?

Question Context: In the view, I have a form that will show a loading 'spinner' gif when a user submits it. The Problem: If I place the spinner img element within its container div, the spinner is always displayed, which is not desired: https ...

Position the float input to the right on the same line as an element

This Angular code contains a challenge where I aim to have text at the start of a column and an input box on the right side of the page, both aligned on the same line. The issue lies in the code which floats the input to the right but disrupts the alignme ...