What is the best way to align the main section of the navbar in the

I am facing a challenge with centering a navbar that includes 4 anchor tag buttons in the center (home, about, services, contact). I am struggling to align it properly within the navbar. Additionally, there is another anchor tag on the far left of the navbar (a phone number link) which is causing some alignment issues. The part I want to center seems to be positioned between this far left link and the right boundary of the page.

I can't seem to figure out how to centrally align these 4 tags on the grid.

Hopefully that explanation makes sense, as I'm not very familiar with the technical terms.

1-530-680- 8255 1-530-680-8255

Answer №1

To align elements next to each other on the page, you can utilize floats and adjust the widths and padding accordingly. If you need assistance with CSS, I recommend checking out some online tutorials.

nav ul {
  list-style-type: none;
  display: inline-block;
  margin: 0px;
  padding: 0px;
  width: 100%;
  
}

nav ul li {
  display: inline-block;
  text-align: center;
  width: 60px;
  margin: 0px;
  padding: 0px;
}

nav ul li span {
  font-size: 0.7em;
}

nav ul li i {
  font-size: 2em;
}

.left {
  width: 40%;
  float: left;
}

.right {
  width: 60%;
  float: right;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">



<nav>
  <div class="left">
    <p>000 000 0000</p>
  </div>
  <div class="right">
    <ul>
      <li><a href="#"><i class="fas fa-phone"></i><br><span>Contact</span></a></li>
      <li><a href="#"><i class="fas fa-wrench"></i><br><span>Services</span></a></li>
      <li><a href="#"><i class="fas fa-at"></i><br><span>About</span></a></li>
      <li><a href="#"><i class="fas fa-home"></i><br><span>Home</span></a></li>
    </ul>
  </div>
</nav>

Answer №2

This template came with a lot of pre-existing CSS styles that would need to be heavily modified in order to accommodate your changes without altering the overall appearance too much. Despite this, your answer is near perfect. However, I did adjust the following CSS code:

nav ul {
list-style-type: none;
display: inline-block;
margin: 0px;
padding: 0px;
width: 100%;

}

I made the following modifications:

nav ul {
display: inline-block;
text-align: center;
width: 1100px;
margin: 200px;
padding: 200px;
 }

The navigation menu is now centered but the container has become vertically elongated. We need to revert it back to its original height.

See screenshot for reference

Answer №3

Let's start fresh. My goal is to align these 4 anchor tag li's in the center of this ul.

Is there a way I can group these four items into a single container and then use CSS to position them to the left? I simply want these 4 elements to be visually centered within that ul.

Here's an image illustrating what I mean

Below is the complete header section in HTML. There's quite a bit of CSS, so I'm not sure what specifically to refer to, but I'll include my current code below for reference.

<!-- Header -->
    <header class="header header-fixed header-fixed-on-mobile header-transparent" data-bkg-threshold="100">
        <div class="header-inner">
            <div class="row nav-bar">
                <div class="column width-12 nav-bar-inner">
                    <div class="logo">
                        <div>
                            <a href="tel:1-530-680-8255" style="color:grey; display:inline-block">1-530-680-8255</a>
                            <a href="tel:1-530-680-8255"><i class="fas fa-phone" style="display:inline-block"></i>1-530-680-8255</a>
                        </div>
                    </div>
                    <nav class="navigation nav-block secondary-navigation nav-right">
                        <ul>
                            <li class="aux-navigation hide">
                                <a href="#" class="navigation-show side-nav-show nav-icon">
                                    <span class="icon-menu"></span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                    <nav class="navigation nav-block primary-navigation nav-center">
                        <ul>
                            <li class="current"><a href="index.html">Home <i class="fas fa-home"></i></a></li>
                            <li class="current"><a href="index.html">About <i class="fas fa-at"></i></a></li>
                            <li class="current"><a href="index.html">Services <i class="fas fa-wrench"></i> </a></li>
                            <li class="current"><a href="index.html">Contact <i class="fas fa-phone"></i> </a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </header>
<!-- Header End -->

---CSS---

nav ul li  {
    display: inline-block;
    text-align: center;
    width: 100px;
    margin: 00px;
    padding: 0px;
}

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 dynamically assign a CSS class to a DOM element during a drag operation while the mouse button is held down?

I am currently working on developing a unique pathfinder visualizer. My progress so far includes creating a grid of size 16x45 using the function below: export const drawBoard = () => { const boardContainer: HTMLDivElement | null = document.querySelec ...

Updating the active tab in the navigation bar whenever the router navigates

I'm struggling with changing the active tab in Angular 2 and Bootstrap 4. I have managed to get the active tab to change using this code snippet: navbar.component.html <nav class="navbar navbar-fixed-top navbar-light bg-faded"> <button cl ...

Troubles with CSS in MUI Component Integration

How can I successfully implement a vertical timeline using Material UI in React? I've set it up, but the CSS isn't functioning as expected. Is there an error in my implementation? List of Dependencies: "@emotion/react": "^11.11.1& ...

Can you help me identify the reason behind a page displaying a temporary horizontal scrollbar?

While browsing the following page in Google Chrome: A horizontal scrollbar appears briefly during page load. It seems that something hidden below the fold is causing this issue, but I haven't been able to identify the exact cause. EDIT:- Watch a v ...

Is there a way to incorporate HTML tags into an option?

Is there a way to include the <i></i> tags inside the <option></option> element? This is the current code I have: <option value="<?= $pages->ID ?>"><i class="<?=$icon?>"></i><?php echo get_the_t ...

jQuery Mobile - Implementing Persistent Toolbars along with a custom back button functionality

UPDATE Here is a fiddle of the problem: https://jsfiddle.net/9k449qs2/ - attempt to select the header using your picker, but every time you click it will select the whole page instead. I am currently working on a project that includes a persistent header ...

What is the best way to convert a dynamic HTML page to a PDF using Django?

1) First, I scrape various web pages to gather information. 2) Once the necessary information is extracted, I integrate it into an HTML page and enhance its appearance using custom CSS. 3) Subsequently, I aim to convert the content into a PDF format for di ...

issue with selecting tabs in jquery

I need help with a problem that is connected to my previous article on CSS, button selection, and HTML tags. You can find the article here. I am not very proficient in JavaScript, so I would appreciate any insights or guidance on how to tackle this issue. ...

The CSS file is not connecting properly despite being located within the same directory

I have double-checked that both of these files have the correct names and are in the exact same directory. However, for some mysterious reason, the CSS is not applying any styling to my page. I would greatly appreciate any assistance with this issue! Belo ...

What is the best method for inserting space between two divs?

I need to create more space between the last two cards and the image at the bottom, but this spacing should increase as I resize the browser window. Can anyone help me with this? https://i.stack.imgur.com/rq9t2.png https://i.stack.imgur.com/tOikx.png Th ...

Find and conceal the object within the list that includes the term "Ice"

The teacher's assignment is to create a radio button filter that hides items with the word "Ice" in them, such as "Ice Cream" and "Iced Tea." Here is the current code I have been working on: <!DOCTYPE html> <html> <head> <me ...

How to retrieve the value from an editable td within a table using Jquery

I am working with a dynamic table that looks like this: <table> <tbody> <tr> <td>1</td> <td contenteditable='true'>Value1</td> </tr> <tr> ...

Angular dynamically changes the placeholder text in an input based on a selection made in a mat select dropdown

Trying to change the placeholder text in a mat-input based on selection in mat-select, but struggling to bind it to the selected option. <mat-form-field appearance="outline" class="search-field" style="width:40vw"> ...

Having difficulty refreshing a page following button click in PHP

I'm encountering an issue where the PHP page isn't reloading automatically after a specific button is clicked. The changes only take effect when I manually refresh the page. Here's the PHP script in question: <?php // Initialize the sess ...

Is the custom cursor feature malfunctioning in IE9?

In my form, I have a web browser control that uses a custom cursor in the CSS code. Everything appears to be working fine in IE8. Css Code cursor: url(AppDirectiry\Classes\QClasses\ClsDesignHtml\Cursors\arrow.ani); However, it s ...

retrieve the information stored in the rows of the table

Here is the arrangement, with numerous div class="extra" elements in my project. <div class="extra"> <table width="90%"> <colgroup> <col width="40%"/> <col width="30%"/> <col width="30% ...

Issue with submitting form on PHP page

I need some help with my signup form: <h2>Signup</h2> <form action="actions.php"> Email:<br> <input type="text" name="email"> <br> Password:<br> &l ...

Unable to click on Textarea due to CSS issue

Is there a way to prevent clicking on a textarea by setting its css? <textarea></textarea> Many thanks! ...

Obtaining a URL in JavaScript

Hey there, I'm diving into the world of JavaScript and could use some guidance. I'm currently working on implementing forward and backward buttons on a webpage. The URL structure is http://webaddress.com/details?id=27 My goal is to write two fun ...

ASP.NET Core MVC: Issue with Passing C# Razor Variable to HTML Tag

GitHub Repo: https://github.com/shadowwolf123987/Gun-Identification-App I'm currently facing an issue in passing the values of two C# variables from the code block defined in my view to the corresponding html tags within the same view. Unfortunately, ...