Tips for centering all icons in the navbar

* {
  padding : 0;
  margin  : 0;
  }
nav {
  padding          : 20px;
  background-color : #809906;
  list-style       : none;
  border-bottom    : 2px solid black;
  }
a {
  color         : black;
  padding-right : 115px;
  }
a:hover {
  color         : hotpink;
  }
<script src="https://kit.fontawesome.com/b75e3e30ff.js" crossorigin="anonymous"></script>


<nav>
  <a href="#" style="padding-left: 5px;"><i class="fa-solid fa-bars"></i></a>
  <a href="#"><i class="fa-solid fa-house"></i></a>
  <a href="#"><i class="fa-solid fa-user"></i></a>
  <a href="#"><i class="fa-solid fa-magnifying-glass"></i></a>
  <a href="#"><i class="fa-solid fa-cart-shopping"></i></a>
</nav>

I attempted various strategies, such as flexbox, to align the icons in the navbar centred but I was unsuccessful. My objective is to position all the icons at the centre of the navbar. As someone new to this field, I am still learning and experimenting.

Answer №1

Flexbox is an amazing choice for creating responsive navigation bars.

nav {
  padding: 1em;
  background-color: #809906;
  border-bottom: 2px solid black;
  display: flex;
  justify-content: center;
  gap: 1.5em;
}

a {
  color: black;
}

a:hover {
  color: hotpink;
}
<script src="https://kit.fontawesome.com/b75e3e30ff.js" crossorigin="anonymous"></script>

<nav>
  <a href="#"><i class="fa-solid fa-bars"></i></a>
  <a href="#"><i class="fa-solid fa-house"></i></a>
  <a href="#"><i class="fa-solid fa-user"></i></a>
  <a href="#"><i class="fa-solid fa-magnifying-glass"></i></a>
  <a href="#"><i class="fa-solid fa-cart-shopping"></i></a>
</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

Is it possible to adjust the positioning of this navigation style?

Discover a unique collection of navigation styles by following this link: http://tympanus.net/Development/ArrowNavigationStyles/ Be sure to explore the final style "Fill Path" at the end of the page. I'm interested in adjusting the position of the ...

Issue with background/hero video not adjusting its size

I've been experimenting with creating a page that features a video as the background, but no matter what I try, the video never seems to resize properly. The image below shows how it looks: image in question body { margin: 0; } .hero-se ...

Is it possible to edit multiple classes simultaneously in Bootstrap?

After creating a div with the class container and adding 50px padding to the top, I am now ready to add another container using Bootstrap's CSS. Do I need to create a new class like container-2 to edit the new container's style or are there multi ...

The Unique Font That Mysteriously Blocks Fake Italic Styles on Webkit Browsers

Currently, I am utilizing the PT Sans Narrow font in my project, which unfortunately only offers regular and bold styles. As a result, I require the browser to apply faux italics when needed. Strangely, this functionality is only working on non-webkit brow ...

Utilizing JSON and select for dependency management

Let's say we have a JSON object: { "A": { "1": "1", "2": "2", "3": "3" }, "B": { "4": "4", "5": "5", "6": "6" }, "C": { "7": "7", "8": "8" } } And we also have ...

The issue with the display grid position being set to absolute is causing functionality

Struggling to create an image catalog with cards containing text while using position absolute on the text and position relative on the card. Unfortunately, it's not working as expected. /*catalog style*/ .grid-container{ padding: clamp(5px,10vw,2 ...

Click to switch CodeMirror's theme

http://jsbin.com/EzaKuXE/1/edit I've been attempting to switch the theme from default to cobalt and vice versa, toggling each time the button is clicked. However, I am facing an issue where it only switches to the new theme once and doesn't togg ...

What is the best way to obtain a direct file link from a server URL using JavaScript?

After acquiring a file located at /home/johndoe/index.html, I am utilizing a tool like XAMPP to host, with the folder /home being hosted on localhost. The variables in play are as follows: $server_addr = "localhost"; $server_root = "/home"; $file_dir = " ...

Leverage the power of JavaScript functions within the app.component.ts file of

I have a JavaScript file named action.js and I am trying to incorporate it into an Angular project. After doing some research, I found out that the js file should be placed in the assets folder and the path must be referenced in the scripts array within an ...

Learn the process of sending notifications upon clicking on an advertisement by a user

I'm currently working on a system that displays ads on mobile devices. Our clients have the option to use their own custom HTML code for their advertisements. We want to be able to track when a user clicks on these ads. I am considering wrapping the u ...

jQuery sidebar with a fixed position

Is there a way to implement a sidebar menu feature using jQuery that reappears on the left as the user scrolls down the page? You can see an example sidebar menu here. ...

Tips for revealing a hidden HTML tag

I am currently trying to validate the content within #textd to ensure it is not empty and contains more than 150 characters. If it meets these conditions, I need to transfer the content to another webpage; otherwise, display an error message based on the c ...

How to modify the link to ensure that a particular tab is already selected when the page loads

How to Add Script for Linking to Rawdata Tab I need help loading specific page content with the Rawdata tab open instead of the Summary tab. What code should I add to the link to ensure that the page loads with "Rawdata"? https://i.stack.imgur.com/avETs. ...

Guide to bringing API information into a Material UI Card

I've been working on a Recipe app that leverages data from the edamame API. I successfully imported Material UI cards into my .js file to pull data from the API and stored it in a const named recipes. However, I'm facing difficulties in getting t ...

Make the jQuery toggle() function work like a regular radio button when selecting multiple options at a time

I have recently created two radio buttons using <i> font icons. Previously, I had successfully used the same code to create a checkbox, so I applied it to the radio buttons as well. After fixing the positioning, everything seemed fine when interactin ...

What steps should I follow to set up HAProxy for server sent events compatibility?

I am currently working on integrating Server Sent Events into an established application. The challenge I face is that there may be extended periods (approximately 5 minutes) where no event is generated. I would like to set up the endpoint in a way that it ...

Retrieve the identifiers of various HTML elements and store them in an array

Within a div, there are multiple objects. I am trying to retrieve the IDs of all elements based on their class, knowing that the number of elements may vary. So far, my attempt has been: arr = $(".listitem #checkBox").hasClass('checkedItem').att ...

Alignment of images on an HTML page using Bootstrap tech

I need some assistance with adjusting the alignment of these photos. I would like them to be more centered, possibly shifted down and to the left. I am working with Bootstrap and there is no CSS attached to it. Everything is contained within the ul tags. A ...

display a tooltip for a disabled image hyperlink in JSP

I am currently working on a popup menu that displays different images, each with its own unique link. Here is an example of what a single menu element looks like: <li class="button-link" data-idp="idfirst"> <s:a href='%{l ...

It seems like Flexbox is ignoring the flex-direction: column property set for a header element

I'm a bit confused because it seems like setting flex-direction: column on an element should display the children of that element in a horizontal row. My layout is simple - at the top, I have the logo, navigation links, and some controls. Below that, ...