Is there a way for me to position my logo in the middle of my navigation bar?

How can I center my logo in the navbar? I've attempted to use mx-auto with Bootstrap 4 Utilities, but it didn't work. It seems like I need to set up some flexbox properties, but I'm not sure which ones to use due to the messy code structure.

Although I admit this might not be the best way to create a navbar, I chose this approach for better responsiveness, even though it needs to be optimized.

@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;600;700;800;900&display=swap');
* {
  box-sizing: border-box;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  background: #fff;
  color: #191919;
  height: 110vh;
  font-family: 'Nunito Sans', sans-serif;
}

#logo {
  max-width: 100px;
  display: inline-block;
}

.nav {
...

Apologies for any language errors in my query.

Answer №1

Start by organizing the three sections into menus, logo, and login/logout. Then, change the justify-items to space-between inside the nav element. Rearrange the logo section to be the second section.

@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;600;700;800;900&display=swap');
* {
  box-sizing: border-box;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  background: #fff;
  color: #191919;
  height: 110vh;
  font-family: 'Nunito Sans', sans-serif;
}

#logo {
  max-width: 100px;
  display: inline-block;
}

.nav {
  clear: both;
  background-color: #fff;
  overflow: auto;
  justify-content: space-between;
  display: flex;
  align-items: center;
}

.nav a {
  display: block;
  color: #191919;
  text-align: center;
  padding: 18px 14px;
  font-weight: 800;
  text-decoration: none;
  font-size: 1rem;
  display: inline-block;
}

.nav a:hover {
  color: #191919 !important;
}

.nav .dropdown {
  float: left;
  overflow: hidden;
}

.nav .dropdown:hover .dropbtn {
  background-color: #fff;
  color: #191919;
}

.nav .dropdown:hover .dropdown-content {
  display: block;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.nav .dropdown .dropbtn {
  font-size: 1rem;
  border: none;
  outline: none;
  color: #191919;
  padding: 14px 16px;
  background-color: inherit;
  margin: 0;
  font-family: 'Nunito Sans', sans-serif;
  font-weight: 800;
  cursor: pointer;
}

.nav .dropdown-content {
  display: none;
  position: absolute;
  background: #fff;
  min-width: 160px;
  z-index: 1;
}

.nav .dropdown-content a {
  float: none;
  color: #191919;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
  transition: 0.4s ease;
  font-weight: 600;
}

.nav .dropdown-content a:hover {
  background-color: rgba(25, 25, 25, 0.034);
  color: #191919;
}

.nav .account {
  color: #191919;
  line-height: 1;
  font-size: 1rem;
  font-weight: 600;
}
<div class="nav" id="topnav"><div>
  <a href="/">Home</a>
  <a href="/feed">Feed</a>
  <a href="/discover">Discover</a>
  <a href="/messages">Messages</a>
  <div class="dropdown">
    <button class="dropbtn">Account</button>
    <div class="dropdown-content">
      <a href="/profile">My profile</a>
      <a href="/projects">My projects</a>
      <a href="/settings">Settings</a>
      <a href="/help">Help</a>
    </div>
  </div>
  </div>
  <div>
    <a href="/">
    <img src="https://nosfera.app/assets/img/logo.png" id="logo" alt="">
  </a>
  </div>
  <div>
  <a href="/login" class="account" alt="Log in">Log in (or <strong>sign up</strong>)</a>
  <a href="/logout" class="account" alt="Log out">Log out</a>
    <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

Insert a gap between the two columns to create some breathing room

Does anyone know how to create spacing between columns in an HTML table without affecting the rows? In my table, each column has a border around it: <table> <tr> <td style="padding:0 15px 0 15px;">hello</td> <td style=" ...

Bootstrap does not display unordered lists (<ul>) or ordered lists (<ol>)

I'm having trouble with my code that should display ordered and unordered lists. Even though I am using Bootstrap, I can't seem to get any list styling - no numbers or bullets are showing up. <ul> <li>test1</li> <li>test2 ...

Displaying Past Data on Website

Is there a way to display Previous Page Values in HTML when the back button is clicked without refreshing the page? I am facing an issue where clicking the back button always causes the page to refresh. ...

Transferring the selected radio button from one HTML page to another without using PHP

I'm looking to transfer radio button data from the first HTML to the second using Pure JavaScript Feel free to use jQuery if needed. jQuery was used 1st HTML <body> <label for="1"> <input type="radio" name="num" id="1" checked="che ...

Implementing audio effects in IE6 HTML

I've implemented the following code to play a sound effect on my website in Firefox, Chrome, and IE9: <body> <audio id="audio1"> <source src="audio.wav" type="audio/wav"> <source src="audio.mp3" type="audio/mpeg"> audio tag no ...

iCloud Web Portal - Element Search Failed: Element Not Found

Exploring Python as a novice, I embarked on a project that requires logging into Gmail and iCloud using Selenium. The Gmail portion went smoothly, indicating that I am headed in the right direction. However, I hit a roadblock while trying to identify the l ...

How to successfully implement ng-show with Html5's <dialog> tags

It's incredible how simple Html5 dialogs are. It feels like they should have been here 15 years ago! I'm having trouble getting ng-show to work with dialogs. Any tips on how to make it happen? <!DOCTYPE html> <html ng-app="project"> ...

Why does my text keep aligning to the left when I adjust the width, causing my background to remain attached to the text?

When I add a width attribute to my #information h1 id, it seems to override the text-align: center; property and aligns the text/background to the left instead of center. Basically, I need assistance in centering the headers with the appropriate backgroun ...

The W3C validator does not recognize any modifications made after jQuery and JavaScript have been applied

My goal is to ensure that my website passes all errors on the W3C Validator. I have encountered a few errors related to the alt text of images. In an attempt to address this issue, I wrote and added the following code to the <head> <script type=" ...

Having issues with floats in Bootstrap?

I'm facing an issue trying to float two elements within a Bootstrap navigation bar, but for some reason it's not working. .cls1 { float: left !important; } .cls2 { float: right !important; } <link href="https://maxcdn.bootstra ...

`The font appears extremely thin when viewed on Safari and iOS devices.`

I'm struggling to resolve the issue with super-thin fonts on Safari/iOS despite trying all recommended solutions. Here is the comparison: https://i.stack.imgur.com/5DVHz.png The _document.js file: import Document, { Html, Head, Main, NextScript } fr ...

What are some techniques for styling the content within a table?

I have a function that dynamically creates tables: function generateTableContent(data) { var table = $('<table id="tblResultsList">'); var tr; var td; $.each(data.d.foundItems, function(i, item) { var button = $(& ...

Endless cycle of changing border colors

I'm trying to achieve a specific effect where the border of a div changes colors in an infinite loop. However, I want this effect to be applied only to the border of the div and not the entire body background. Here is an example: http://jsfiddle.net/A ...

Achieving perfect alignment of an iframe on a webpage

Having an issue with aligning the iframe on my website. I have two buttons set up as onclick events that connect to internal pages displaying PHP data in tables within the iframe. Despite trying various CSS styles and positioning methods, I can't seem ...

The issue of the click event not functioning properly within a Javascript-based carousel

I have set myself the challenge of creating a carousel using only JavaScript, but I am encountering issues with the click events. The images should change when I click on "next" or "prev", but it's not working as expected. Could someone please point ...

The DIV element is failing to fill the entire screen's width

I am completely new to web development and currently working on creating my very first website. I've managed to set up the layout, but I'm facing an issue when trying to optimize it for mobile devices. Specifically, some of my divs (particularly ...

PHP: Sending multiple values under a single name

Here's the code I'm currently working with. It includes a form with 6 inputs. The last 3 inputs are named firstanswer, secondanswer, and thirdanswer. <form action="addsurvey.php" method="post"> <input type="text" name="surveyname"> ...

Adding a background image in javascript using data from a MySQL database

My current tech stack includes CodeIgniter, vanilla JavaScript, AJAX, CSS, and MySQL. I am trying to figure out how to set the background of an image that is stored in a MySQL database. While the following code is error-free and working perfectly, my cha ...

How to implement jquery select functionality on clickable table rows?

I've come across a challenge while trying to implement clickable table rows with the jquery selectable function. Everything works perfectly fine with li elements, but I seem to hit a roadblock when using tables - the click event just stops working. Wh ...

Fundamentals of object property in jQuery and Javascript

Currently working on creating a new property named startPosition and setting the top property to equal the button's current top value in CSS. Below is the jQuery code snippet: var morphObject = { button: $('button.morphButton'), c ...