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

Uploading a file using AngularJs

When it comes to uploading an image or file using HTML tag in AngularJS, it seems that the tag is not supported. The solution? Create a custom directive. In my index.html page, I included the following code: <body ng-controller="myController"> ...

Adjust the height of a div based on the font size and number of lines

I'm trying to create a function that automatically sets the height of a div by counting lines. I managed to get it partially working, but then it stopped. Can someone please help me with this? function set_height() { var div_obj=document.getEleme ...

Deactivate the Submit button when the database field has been populated

My form includes a submit button. The Submit button should be disabled if the "price" for a specific product is already filled: PHP Code <?php $host="localhost"; $username="root"; $password=""; $db_name="ge"; $con=mysqli_connect("$h ...

Styling an HTML table with two columns: one column displaying an image, and the other column containing information related to the image

I have a concept that involves creating a table with 2 columns. The left column will feature an image, while the right column will display data about the image in 6 rows. ________________________________ | |_______________| | | ...

Located at the lower section of the parent container

In my flex container, I have two boxes arranged side by side (collapsing into one column on smaller screens). I've ensured that these boxes have the same height when displayed together, as shown in the image below: Now, my goal is to position the ED ...

How can you use ng-click to disable a div in AngularJS?

I'm looking to dynamically disable a div in AngularJS based on a certain condition. I know I can achieve this by adjusting the CSS (such as reducing contrast and color) but the div also has an ng-click property that I want to prevent from being trigge ...

Why does "height: auto;" not function properly when I implement "float:left"?

I have set up three responsive columns and now I want to add a wrapping div for them. Although I have created the wrap div, it seems to only work with pixel values. I would prefer to use percentages or auto as I am aiming for a responsive layout. For exa ...

Vue's watch feature will not execute if the watched property remains unchanged during a page reload

<template> <!-- The navbar has a property for gender, the color of the navbar will change depending on the gender --> <!-- pass the props gender through a form submission and event --> <div class="nav-main" :class="{f ...

Optimal Strategy: Utilizing Spring Boot for Backend Development and jQuery for Frontend Interface

I am currently tackling a project that involves a Spring Boot 2 Backend and a jQuery Frontend. The frontend communicates with the backend by sending Ajax requests to Spring REST controllers in order to interact with database entities. One of the challenge ...

Exploring methods to detect when a PHP page has been printed using the 'ctrl+p' shortcut and then subsequently updating

Hey there! I'm currently managing a php website that functions as an accounting system. Within this system, there are receipts, invoices, and other forms of documentation in use. However, I've encountered a problem with the main table in my myS ...

Troubleshooting a CSS overflow problem in the main slider

While exploring the website , I encountered a minor issue. When I added "overflow: hidden" to the featured slider div, the images appeared stacked if JavaScript was enabled or the user's internet connection was slow. However, a new problem has arisen ...

Reducing the amount of text displayed on ion-text to a minimum

HTML: <ion-list *ngFor="let message of messages"> <ion-item lines="none" type="button" button="true"> <ion-grid> <ion-row> <ion-col class="message"> <ion-text> ...

Looking for a way to customize it using @emotion/styled? Dealing with the deprecated makeStyles from MUI problem?

I have been working on setting up my styling using @emotion since makestyles were removed in React 18. Despite making changes as per my research, I am not seeing any updates reflected on my page. The expected result looks like this: https://i.stack.imgur. ...

issue with displaying content in bootstrap tabs

Every time I attempt to load a tab, it redirects me to the homepage. Just for reference, I am using AngularJS as my JavaScript framework. <div class="container"> <h1> Tab Panel </h1> </div> <div id="exTab1" class="container"&g ...

Using React Native's stylesheet to apply multiple values in a CSS statement

Here's a scenario to help clarify my question: Imagine I want to add margin to an element in the following way: const myView = () => <View style={styles.viewStyle}></View> const styles = StyleSheet.create({ viewStyle: { margin: ...

Update the less mixin

I attempted to eliminate the border radius from all Bootstrap elements by creating a custom-mixins.less file with the following lines in it. My intention was for these lines to overwrite the original .border-radius mixin, but unfortunately, it did not work ...

Use jQuery to insert the TEXT heading as an input value

Can anyone help me with copying text from a heading to an input value? Here's an example: <h2 class="customTitleHead">This is a Heading</h2> I want to transfer the text from the heading into an input field like this: <input type="tex ...

What is the best method for resetting the CSS style of a specific DOM subtree?

While working on a Chrome Extension, I encountered a problem where an HTML subtree and CSS style sheet injected into the original page were being affected by the original CSS. Despite my attempts to override the styles, it seemed unfeasible to manually set ...

Identify HTML elements within a textarea or text input using JavaScript while also accommodating the common special characters ">" and "<"

Is there a way to accurately detect HTML tags in textarea or text input fields before submitting a form? While it may seem straightforward to use regular expressions like /<\/?[^>]*>/gi.test(str) for this purpose, the challenge arises when de ...

Preventing Canvas Image Disappearance with JavaScript's onload Event

My current issue involves adding an Image to my webpage. However, every time I hit the refresh button, the image disappears. After researching on Stack Overflow, it was suggested to include window.onload=yourDrawFunction() in the code. Despite following th ...