Centralized navigation bar

I am currently facing a challenge with centering my nav bar and I'm not sure how to proceed. The nav bar is placed within a class and a div, which is causing confusion for me. I have attempted to align it to the center and also tried using float:center without success.

body {
  background-color: #000000;
}

div {
  min-height: 75px;
  line-height: 75px;
  text-align: center;
  color: #57df13;
  font-weight: bold;
  font-family: verdana, sans-serif;
}

.inner {
  width: 50%;
  max-width: 960px;
  margin: 0 auto;
}

.header .inner {
  font-size: 125%
}

.menu .inner ul {
  list-style-type: none;
}

.menu .inner li {
  float: left;
  padding-left: 18px;
  transition: all .3s ease-in-out;
}

.menu .inner li:hover {
  font-size: 150%;
}
<head>
  <title>PandaGamingNetwork</title>
  <link href="CSS/master.css" type="text/css" rel="stylesheet">
</head>

<body>
  <div class="header">
    <div class="inner">
      <h1> PandaGamingNetwork </h1>
    </div>
  </div>
  <div class="menu">
    <div class="inner">
      <ul>
        <li> Home </li>
        <li> About </li>
        <li> Vids </li>
        <li> Memes </li>
      </ul>
    </div>
  </div>
</body>

Answer №1

Replace the float:left property with display:inline-block in the .menu .inner li CSS selector.

.menu .inner li {
    /* float: left; */
    padding-left: 18px;
    transition: all .3s ease-in-out;
    display: inline-block;
}

Answer №2

To center the menu, you need to remove all the existing styling from your .inner rule and replace it with the following:

.inner {
  display: flex;
  justify-content: center;
}

Additionally, make sure to include padding: 0; in .menu .inner ul to prevent any offset caused by padding.

body {
  background-color: #000000;
}

div {
  min-height: 75px;
  line-height: 75px;
  text-align: center;
  color: #57df13;
  font-weight: bold;
  font-family: verdana, sans-serif;
}

.inner {
  display: flex;
  justify-content: center;
}

.header .inner {
  font-size: 125%
}

.menu .inner ul {
  list-style-type: none;
  padding: 0;
}

.menu .inner li {
  float: left;
  padding-left: 18px;
  transition: all .3s ease-in-out;
}

.menu .inner li:hover {
  font-size: 150%;
}
<div class="header">
  <div class="inner">
    <h1> PandaGamingNetwork </h1>
  </div>
</div>
<div class="menu">
  <div class="inner">
    <ul>
      <li> Home </li>
      <li> About </li>
      <li> Vids </li>
      <li> Memes </li>
    </ul>
  </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

Utilizing Adjacent Sibling Selectors within the context of a specific enclosing class

I have a question regarding the following HTML structure: <div class="a"> <div class="b"></div> <div class="c"></div> </div> My goal is to apply a specific CSS rule only within the a class: .b + .c { margin-le ...

Is there a way to turn off alerts from Aspx files for HTML and CSS?

Dealing with annoying warnings in my aspx files has been a constant struggle. The "CSS Value is not defined" message pops up when I reference CSS files from different projects, causing unnecessary frustration. Even more frustrating are the warnings about i ...

Converting HTML Form Data into CSV with Multiple Rows

I currently have a form that generates a CSV file with data from select elements in the HTML form. The columns in the CSV correspond to the selected options in the form, but I need to extend this functionality to populate multiple rows in the CSV. Expecte ...

- Prefixing with -webkit-transform and overlooking z-index

When using Safari 5.1.7 on Windows, I noticed that some rotated elements are overlapping others: However, when I test it on Firefox, Chrome, and IE, the issue doesn't occur: Is there a solution to prevent this overlap problem specifically on Safari? ...

What advantages does using ImageMagick to resize images offer compared to using CSS?

My Ruby on Rails application has a feature that allows users to upload images. I have discovered that Active Storage can utilize ImageMagick to resize images using this code: model.image.variant(resize: "100X100") However, resizing images can also be ach ...

Tips for Excluding Content Retrieved Through file_get_contents?

Currently, I am storing the source code of a webpage in a variable called $html using the following line: $html = file_get_contents('http://www.google.com'); When I use <textarea><?php echo htmlentities($html); ?></textarea> ...

Design an HTML watermark input that remains visible as the user starts typing

I'm currently in the process of developing an application that enables businesses to access their account through theirname.mydomain.com. I am working on creating a signup form for this purpose. Today, I stumbled upon squarespace and noticed they hav ...

Unlocking the power of python with web2py by tapping into html form values

I'm working on a project using web2py and need to incorporate ajax/javascript with a form. Currently, when a user selects an option in the departure box, the arrival box appears. However, I'm unsure of how to filter the list of arrival options ba ...

Apply a specific style to the initial element generated by *ngFor

My current method for displaying a certain number of * characters is utilizing the code snippet below: <div *ngFor="let line of lines; let i=index">*</div> I am interested in applying a margin only to the first element. The margin value sh ...

Developing HTML5 animation by utilizing sprite sheets

Struggling to create an engaging canvas animation with the image provided in the link below. Please take a look at https://i.stack.imgur.com/Pv2sI.jpg I'm attempting to run this sprite sheet image for a normal animation, but unfortunately, I seem to ...

Using Jinja2 to iterate through a dictionary while having the ability to choose which key-value pair to access

I'm attempting to generate an HTML table from data received on the web as a dictionary app.py: client = boto3.client('ec2') vpc_ids = client.describe_vpcs() for i in vpc_ids.get('Vpcs'): for tag in i.get('Tags'): ...

In the Firefox browser, tables are shown with left alignment

I recently designed a responsive HTML newsletter with all images neatly wrapped in tables. My goal was to ensure that on smaller screens, the tables stack on top of each other for better readability, while on wider displays, they appear side by side in a r ...

Implementing Jquery Table Selection with Custom CSS Class

When I attempted to use the selectable feature on a table with a CSS class applied, the selection did not work. However, when I removed the CSS class, the selection worked perfectly fine. I suspect that the issue lies within the CSS definition, but I' ...

Issue with Angular 2 NgFor Pattern Error Message Display Absence

I am attempting to incorporate inputs with a regex requirement within an ngFor loop, but I am not receiving the expected error message when entering something that does not match the required pattern. Even when I input an incorrect pattern, "Test" remains ...

Aligning text with a scalable vector graphic (SVG) illustration

Is there a way to position the text next to the SVG object? The current output is as follows: The desired outcome is to have the text displayed alongside the SVG image: Below is the HTML code snippet: <div class="alert alert-success smallFont" id="i ...

Only wrap certain elements if they consist of two specific items

<div class="section"> <label>Title: </label> <input type="text" /> </div> <div class="section"> <label>Text: </label> </div> My goal is to enclose the label + input within an additional div ...

What is the reason that preventDefault fails but return false succeeds in stopping the default behavior

I'm having trouble with my preventDefault code not working as expected. While using return false seems to work fine, I've heard that it's not the best practice. Any ideas why this might be happening? if ($('.signup').length == 0) ...

Unable to expand or collapse rows in ng-table

Looking to implement an expand and collapse feature for ng-table, where clicking on a row should expand it to show more detail. However, currently all rows expand on click. Any ideas on how to achieve this? Any assistance would be greatly appreciated, tha ...

The cursor in a contenteditable element fails to return to its original position after adding a new line and then deleting it

I have come across a basic HTML code snippet: span { outline: none; } hello <span contenteditable="true"> world </span> Upon testing, I observed that each time I press ENTER within the contenteditable span, the cursor moves to a new ...

Leverage PHP to retrieve information from a JSON file and integrate it into a dropdown menu on an HTML

I've been given a task to develop a PHP routine that will extract the ISO code and name from a geojson file for use in a dropdown list of countries on a website. This is completely new to me and I'm finding it difficult to understand the documen ...