Struggling to align elements in a navbar using HTML and CSS?

Currently, I'm in the process of building a simple website and focusing on customizing the navbar. The logo within the navbar is created using font awesome and text, with a larger font size compared to other elements in the navbar. However, I am facing an issue where the alignment of the logo text does not match the rest of the text in the navbar.

* {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 16px
}

body {
  background-color: RGB(40, 43, 48);
  margin: 0;
  padding: 0;
}

nav {
  background-color: RGB(30, 33, 36);
  text-align: center;
  justify-content: center;
  justify-items: center;
}

.main-nav {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
}

.main-nav li {
  padding: 10px;
}

.main-nav li a {
  color: white;
  text-decoration: none;
  font-weight: bold;
}

.push {
  margin-left: auto;
}

.nav-logo {
  font-size: 20px;
  display: inline-block;
  position: relative;
  color: white;
}

.nav-logo:after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  top: 24px;
  bottom: 0;
  left: 0;
  background-color: white;
  transform-origin: center;
  transition: transform 0.25s ease-out;
}

.nav-logo:hover:after {
  transform: scaleX(1);
  transform-origin: center;
}

nav-content {}
<script src="https://kit.fontawesome.com/df395811d0.js" crossorigin="anonymous"></script>
<nav>
  <ul class="main-nav">
    <li>
      <a href="#home" class="nav-logo"> <i class="fa-solid fa-greater-than fa-18px"></i> Terminalize </a>
    </li>
    <li> <a href="#html" class="nav-contents"> HTML </a> </li>
    <li> <a href="#CSS" class="nav-contents"> CSS </a> </li>
    <li> <a href="JavaScript" class="nav-contents"> JavaScript </a> </li>
    <li> <a href="#python" class="nav-contents"> Python </a> </li>
    <li> <a href="#windows" class="nav-contents"> Windows </a> </li>
    <li> <a href="#linux" class="nav-contents"> Linux </a> </li>
    <li> <a href="#macos" class="nav-contents"> MacOS </a> </li>
    <li class="nav-content push "> <a href="#about"> About </a> </li>
  </ul>
</nav>

View the appearance of my navbar

Answer №1

To center your navigation items, make sure to add the align-items: center property to your main-nav class in your CSS code:

* {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 16px
}

body {
  background-color: RGB(40, 43, 48);
  margin: 0;
  padding: 0;
}

nav {
  background-color: RGB(30, 33, 36);
  text-align: center;
  justify-content: center;
  justify-items: center;
}

.main-nav {
  display: flex;
  align-items: center;
  list-style: none;
  padding: 0;
  margin: 0;
}

.main-nav li {
  padding: 10px;
}

.main-nav li a {
  color: white;
  text-decoration: none;
  font-weight: bold;
}

.push {
  margin-left: auto;
}

.nav-logo {
  font-size: 20px;
  display: inline-block;
  position: relative;
  color: white;
}

.nav-logo:after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  top: 24px;
  bottom: 0;
  left: 0;
  background-color: white;
  transform-origin: center;
  transition: transform 0.25s ease-out;
}

.nav-logo:hover:after {
  transform: scaleX(1);
  transform-origin: center;
}

nav-content {}
<script src="https://kit.fontawesome.com/df395811d0.js" crossorigin="anonymous"></script>
<nav>
  <ul class="main-nav">
    <li>
      <a href="#home" class="nav-logo"> <i class="fa-solid fa-greater-than fa-18px"></i> Terminalize </a>
    </li>
    <li> <a href="#html" class="nav-contents"> HTML </a> </li>
    <li> <a href="#CSS" class="nav-contents"> CSS </a> </li>
    <li> <a href="JavaScript" class="nav-contents"> JavaScript </a> </li>
    <li> <a href="#python" class="nav-contents"> Python </a> </li>
    <li> <a href="#windows" class="nav-contents"> Windows </a> </li>
    <li> <a href="#linux" class="nav-contents"> Linux </a> </li>
    <li> <a href="#macos" class="nav-contents"> MacOS </a> </li>
    <li class="nav-content push "> <a href="#about"> About </a> </li>
  </ul>
</nav>

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

Moving pictures using css3 transitions

Trying to create a straightforward image slider. Below is the provided JavaScript code: $(document).ready(function() { $('#slide1_images').on('click', 'img', function(){ $("#slide1_images").css("transform","translateX ...

Unforeseen behavior in Ajax success callback

My unordered list contains a href link. Initially, only the welcome page is visible on page load. Upon clicking the list for the first time after page load, the desired results are displayed in the corresponding div as expected. The issue arises when swi ...

Positioning elements in CSS using percentages allows for flexible and responsive

I am new to web design and I am trying to create a webpage similar to the one shown in this image. However, I want to set the height and width of the divs using percentage values instead of pixels. Whenever I attempt this, the boxes end up overlapping or ...

Retrieving table information using javascript

My goal is to retrieve information from the <td> elements within the following HTML table: <table class="datadisplaytable" summary="This table lists the scheduled meeting times and assigned instructors for this class.."> <caption class="cap ...

Can columns in Bootstrap be used within a row without a container?

I am currently using bootstrap 4.6.0 and I have a question about the following code structure. While everything seems to be functioning correctly, I am uncertain if I should be utilizing a different container: <div class="container-fluid"> ...

Incorporating HTML/PHP elements into JQuery

I am currently working on a website project for a manufacturing company that involves PHP, HTML, CSS, and JQuery. My goal is to create a seamless user experience where they can easily contact sales representatives for quotes and other information by clicki ...

HTML5 - Ajax - puzzling behavior that I am unable to comprehend

Need Help Clarifying My Issue: I currently have a Div with Page 1 content. Page 1 contains a button that transitions the div content to Page 2. Page 2 has a button that switches the div content back to Page 1. The Problem: If Page 1 is loaded first, t ...

Angular JS allows for the display of text from a textarea upon clicking the submit button

Q] How can I display a single text message from a textarea upon clicking the submit button in angular-js? Here is the current code that I have: <html ng-app="myApp"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1 ...

the table image does not resize correctly in mobile view

I need to resize an image inside a table's <td> when the screen size is in mobile mode. Although I have already added a viewport, my mobile query works correctly for other purposes except for the image. Here is the HTML code: <table class="t ...

Attempting to toggle the visibility of div elements through user interaction

I'm having an issue with click events on several elements. Each element's click event is supposed to reveal a specific div related to it, but the hidden divs are not appearing when I click on the elements. Any help in figuring out what might be g ...

Strange CSS Problem: Button dysfunction in displays sized 13 inches or 15 inches

I have made a landing page using the latest version of bootstrap. However, I am encountering an odd issue where the success button is not clickable on certain devices such as 13-inch and 15-inch laptops and desktops. You can find the URL for the landing p ...

The CSS style of the Div element is not being displayed properly when embedded with JavaScript

Currently, I am working on a simple page for practice purposes. The main issue I am facing is with a div element that has a red border and a blue background. Inside the div, there is a script tag calling an external JavaScript file. Surprisingly, the JavaS ...

The button should only be visible when the input is selected, but it should vanish when a different button within the form is

Having an issue with displaying a button when an input field is in focus. The "Cancel" button should appear when a user interacts with a search bar. I initially used addEventListener for input click/focus to achieve this, but ran into a problem: on mobile ...

Guide to Incorporating a Marker into an SVG Blinking Rectangular or Circular Border Image on Google Maps

I have a link that points to a specific location on Google Maps using latitude and longitude: http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png Now, I am looking to add a blinking border to this marker link. Is there a way to achieve this ...

Spinning an SVG path with CSS3 in a circular motion from its central axis

I have a collection of SVG paths, and one of them is displayed below: <path id="GOL" class="st0" d="M37.5,430.5l-12.4-12.4v-13.3h-4.2c-7.2,0-13.9,2.5-18.7,7.5c-4.7,4.9-7.3,11.3-7.3,18.3 c0,7,2.6,13.5,7.3,18.3c4.8,5,11.4,7.6,18.6,7.6l4.2,0v-13.7L36. ...

Using numerous background images can lead to issues in Safari browser

Currently experimenting with styling the body element using two images. background: url(bg2.png) repeat-x, url(bg1.png) repeat; An issue arises in Safari where it reports an error in the console, stating that it cannot locate the image file specified at ...

Utilizing Selenium automation to navigate a website that features a custom jQuery plugin-checkbox functionality

Utilizing Selenium WebDriver along with JavaScript to automate the testing of a website that features a custom jquery plugin named "jcf" (JavaScript Custom Forms) for aesthetically pleasing forms. You can find more information about this plugin here. I am ...

Verify the position of the scrollbar without triggering any reflow

Here is a function I have: is_bottom: function() { if (settings.scrollBottomOffset === -1) { return false; } else { var scroll_height, scroll_top, height; scroll_height = ...

designing icon buttons

I am interested in adding big buttons with icons to my website. I have images named largebut_hover.png, largebut.png, and icon.png. The icon image is supposed to be displayed inside the light grey background of largebut.png, and when hovering, it should sw ...

Updating text color in JavaFX for a textarea

I'm having trouble getting this to work. After checking the CSS analyzer in the scene builder, it seems that changing the text color in a textarea requires something like this: .text-area .text { -fx-fill: #1e88e5; -fx-font-size: 32px; } How ...