What is the best way to line up the items in my navbar horizontally?

I am relatively new to CSS and struggling with getting the Inline-block code to work on my project. My goal is to horizontally align the links in my navbar menu instead of having them stacked vertically.

<nav class="navbar">
    <div class="max-width">
        <div class="logo"><a href="#">Roulathul <span>Uloom.</span></a></div>
        <ul class="menu">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Skills</a></li>
            <li><a href="#">Teams</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div>
</nav>

Here is my HTML code for the navbar.

.navbar .menu .li{
list-style: none;
display: inline-block;
}

I have used the display property with inline-block but it's not rendering as expected. Any suggestions or tips would be greatly appreciated!

Answer №1

How to utilize:

.navigation {
  flex-direction: row;
}

Answer №2

One effective way I use to center my navbars is by utilizing the display: flex property along with justify-content: which allows me to either evenly space out the elements or perfectly center them. For further details on the flex property, check this out

.menu{
list-style: none;
display: flex;
justify-content: space-evenly;
}

Answer №3

To create more space and remove the default list styling, I have added padding to the navbar elements. Here is the updated code:

.navbar {
    display: flex;
    align-items: center;
    top: 0px;
}

.navbar ul {
    display: flex;
}

.navbar ul li {
    list-style: none;
}

.navbar ul li a {
    display: block;
    padding: 5px 22px;
    text-decoration: none;
}
<nav class="navbar">
    <div class="logo">
        <a href="#">Roulathul <span>Uloom.</span>
        </a>
    </div>

    <ul>
        <li class="item"><a href="#Home">About</a></li>
        <li class="item"><a href="#Services">Services</a></li>
        <li class="item"><a href="#Clients">Skills</a></li>
        <li class="item"><a href="#Contact Us">Teams</a></li>
        <li class="item"><a href="#Contact Us">Contacts</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

"How can I make one div stretch to the height of its parent while allowing another div to only fill the available height

I am currently designing a dashboard-like layout with two rows. The top row is not as important, but the second row is presenting a challenge. It consists of two divs with varying heights. My goal is to have the left div fill the available space without o ...

After transitioning to TypeScript, the CRA app is encountering issues loading CSS files compiled by SASS

My React application was originally created using create-react-app and I had been successfully loading scss files with the node-sass package. However, after deciding to switch to TypeScript following the steps outlined in , my css files are no longer being ...

The column flex-direction property seems to be malfunctioning

Can anyone help me with styling a ul tag using display: flex? I'm trying to order it by column with flex-direction: column;, but for some reason, it's not working. Here is the CSS code for the container: #nav li.four_columns ul.sub-menu { widt ...

If the text width of a label exceeds the total width of its container, intelligently display a sub-string based on pixel calculations

I am looking to shorten the text inside a label if its width exceeds the total width of its container. Instead of displaying the full text, I want to display a sub-string of it. if (SensorType.Text.Length >= 25) { SensorType.Text = SensorType.Text ...

Center-align a list with items floated to the left in a d-flex container

I'm attempting to create an inline list that resembles a grid with as many cards arranged horizontally as possible. However, I've encountered a problem - when I float the list items to the left, the text centering no longer functions and the list ...

Putting a variable in a statement in Angular and TypeScript is a common task that can be accomplished

This snippet is written in Angular and involves using a variable to modify a conditional statement without having to repeatedly update every variable type. The code snippet below showcases an example in an HTML input tag. import { FormBuilder, FormGroup, V ...

Generating a dynamic list of array data within an array using ForEach in SwiftUI

Exploring the Apple tutorial on the "Scrumdinger" app (here) has provided valuable insights into data display within a list. However, as I delve deeper into my project's navigation hierarchy and data models, I've encountered a minor challenge. T ...

My ability to click() a button is working fine, but I am unable to view the innerHTML/length. What could be the issue? (NodeJS

Initially, my goal is to verify the existence of the modal and then proceed by clicking "continue". However, I am facing an issue where I can click continue without successfully determining if the modal exists in the first place. This occurs because when I ...

Creating a layout similar to Facebook can be achieved by utilizing HTML and CSS, specifically using flexbox to structure

I am looking to create a website layout similar to Facebook, with the following features: A fixed or sticky header and no footer 3 div elements, where div1:div2:div3 = 1:2:1 3 scroll bars to control each div... Scroll-1 and scroll-3 will be inside div-1 a ...

Looking to connect a dropdown to an icon that has the type "button"?

I am facing a challenge with an icon placed on a Twitter Bootstrap container. My goal is to click on this icon and have a dropdown menu appear, offering various options that link to different websites. Currently, I am able to display the dropdown menu, but ...

Problem encountered with submenu text in CSS drop-down menu

Hey there! I've recently started working on a website and encountered a problem while trying to create a dropdown menu using CSS and HTML. The hover function for the submenu is functioning properly, but I'm struggling with changing the font color ...

Childs - A jQuery Stride

I am trying to figure out how to modify a specific child element within an HTML structure. Specifically, I want to target the first anchor tag within a list item of an unordered list. Here is what I have attempted so far: [HTML AND JQUERY] <body> ...

Submitting a multipart form via AJAX from a textarea and input fields

After attempting numerous JS codes to submit a form with multiple pieces of data (2 files and 1 textarea), I have not found a solution that works effectively. So, how can we use AJAX to send form data that is not empty to PHP? <form method="post" enct ...

Automatically submit upon selecting an option

Encountering some difficulties with the code provided below. Purpose of this code I have multiple list items (shown here is just a snippet) made up of select elements, options, and one submit input field. When an option is chosen, the user can click on ...

Generating unique identifiers and names for duplicated input fields in a form, which change dynamically

Innovative approach: When dealing with multiple replicated inputs, changing the id and name attributes can be a hassle. How can we ensure that each input remains unique, especially in a real project with several inputs like component_date and component_own ...

What causes my animation to “reset” upon adding a new element using innerHTML?

One of the functionalities on my webpage involves a script that inserts a div called "doge" using innerHTML when a button is clicked. Additionally, there is a CSS keyframes animation applied to another div on the same page. However, whenever the button is ...

Use jQuery to locate the nearest elements

Currently seeking a way to locate and choose the 5 nearest "li" elements (two, three, four, five, and six) with the class "active". Any suggestions? <li class="one">Hello</li> <li class="two">Hello</li> <li class="three">Hell ...

When you hover over the text, the color will shift

I have created two boxes that are blue with white text and change to a different color scheme when hovered over. However, I am experiencing an issue where the text color reverts back to the original color when hovering below the text area of the box. Here ...

What causes the background-color:attribute to malfunction when there are comments in the preceding line?

Recently, while testing internal stylesheets in the latest version of Chrome, I encountered a peculiar bug that caused my code to break. Strangely enough, any comments placed before background-color:rgb(51,51,51) seemed to trigger the failure of the code. ...

Controlling Formatting in ASP.NET

Feeling puzzled by a seemingly simple question with no clear solution in sight. We're attempting to transition an interface to an ASP.NET control that currently appears like this: <link rel=""stylesheet"" type=""text/css"" href=""/Layout/CaptchaLa ...