Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HTML/CSS – Problem with aligning elements in navbar

I’m trying to make this simple website and right now I’m working on the navbar. In the navbar I also have this logo that I created with font awesome and text, it also has a bigger font size than the other elements in the navbar. My problem is that the logo text isn’t aligning with all the other 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>

What my navbar looks like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you just had to set align-items: center on your main-nav class, as shown below:

* {
  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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading