Consistent padding applied to navigation bar links with a set width limit

Having some trouble with the navbar on a project I'm currently working on. Struggling to achieve consistent padding for each link and maintain a fixed width for the navbar. Despite multiple attempts, I haven't been successful in achieving equal padding across all the links. The goal is to be able to easily add or remove links without having to constantly adjust the padding values. The code snippet below shows what I've attempted so far. Any assistance would be highly appreciated as I've spent quite some time searching for a solution to no avail. Apologies if this question has been asked before. Thank you.

HTML:

<div class="navbar">
    <ul>
        <li class="navbar-active"><a href="home.php">Home</a></li>
        <li ><a href="about.php">About</a></li>
        <li ><a href="registration.php">Registration</a></li>
        <li ><a href="attendees.php">Attendees</a></li>
        <li ><a href="schedule.php">Schedule</a></li>
        <li ><a href="faq.php">FAQ</a></li>
        <li ><a href="speakers.php">Speakers</a></li>
        <li ><a href="photos.php">Photos</a></li>
        <li ><a href="contact.php">Contact</a></li>
    </ul>
</div><!-- /.navbar -->

CSS:

/**
 * Navbar
 */

div.navbar{
  width:1000px;
  background-color: #E15532;
  text-transform: uppercase;
  height: 30px;
  line-height: 30px;
}

div.navbar ul{
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
div.navbar ul li{
  float: left;
}
div.navbar ul li a{
  display: inline-block;
  margin: 0;
  padding: 0;
  font-weight: bold;
  text-decoration: none;
  color: #F7F6E2;
  border-right: 1px solid #AF4128;
  border-left: 1px solid #AF4128;
  border-bottom: 1px solid #AF4128;
  padding: 0 16.67188px;
  text-align: center;   
}
div.navbar ul li a:hover{
  background-color: #AF4128;
}

Answer №1

If you're looking for a solution, using display table, table-row, and table-cell might be your best bet. Check out this live demo - http://jsfiddle.net/ck1hbtzq/

.navbar {
    display: table;
    width: 1000px;
}

.navbar ul {
    display: table-row;
}

.navbar li {
    display: table-cell;
}

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

What is the best way to use a jQuery variable within a .css() function

I'm working on a typewriter effect with some advanced CSS code. I need the program to calculate the length of a PHP variable and adjust the cursor animation steps accordingly. Basically, I want the cursor movement in the animation to be determined by ...

Is the positioning of the div element required to be adjusted based on the responsive design layout

Is there a way to adjust the placement of a div based on responsive views without resorting to insertBefore or insertAfter methods? ...

Is there a way to display both the label and the input field in a single line?

How do I align the label and input on the same line with a spacing of 1.5cm between them? I tried using this resource, where it mentioned using form-inline but wasn't successful in achieving the desired layout. https://i.sstatic.net/7MW2H.png Appre ...

Having difficulty retrieving data from JSON file using Backbone framework

When I click on the div, I am attempting to retrieve JSON data but am unable to view the output. I am utilizing Backbone Collection to fetch JSON data. I have tried displaying the JSON data in the console as well as within another div. The contents of the ...

Is the Bootstrap carousel floating outside the document's natural order?

As I work on building a landing page for a new startup, I encountered an issue with the layout. I am using a carousel in the "hero section," and everything seemed to be working fine until I attempted to add the next section. To my surprise, the next sectio ...

angularjs: hide div based on text entered in textfield

Is there a way to hide a div (with the class "card") until the user inputs text into the textfield in an AngularJS application? I believe the solution involves using ng-show, but I'm unsure of how to implement this functionality. Any assistance would ...

Issue with returned data in Json result

My application uses jsonresult to display a list of cities within a country. The data is fetched from a database and loaded into a dropdown list using jQuery. However, I'm facing an issue where the jsonresult stops working if the number of cities exce ...

Can a script be dynamically loaded into a div while accessing local variables?

Consider the scenario where you have two files: test.html <div id="stuff"></div> <button onclick="doStuff()">Magic</button> <script> var foo = new function() { this.bar = function() { return "THE MAGIC!"; }; ...

Ways to prevent selection or highlighting of an HTML input field?

Is there a way to prevent users from selecting or highlighting an <input> element? Consider the following: input { user-select: none; } <input type="number" value="123" /> Unfortunately, the methods suggested in How to disable text s ...

execute the function after the animation has finished

Is it possible to trigger a function once an animation is complete using jQuery? Here's the code I'm working with: $('html, body').animate({scrollTop:$("body > .addAccountForm1").offset().top }, 'slow'); I want to execut ...

Experiencing a lack of defined or no outcome when outputting the API callback

I am troubleshooting an issue with my script that searches for movie titles from a database. While I receive results in the console without any errors, the renderMovies function is not storing the API movie title, plot, and other details properly in my var ...

Ways to focus on a specific div using JavaScript

I am attempting to create a 'snow' effect on the background of a particular div with a red border. Here is the code, but you can also view it here: <!-- language: lang-js --> var width = getWidth(); var height = getH ...

Executing multiple ajax calls and retrieving the results: A step-by-step guide

I am looking to run a series of Ajax calls and collect the responses before rendering the results for the user. The current code I am using is not working as expected because the render function is being executed before all the Ajax responses have been ga ...

Having trouble with jQuery validation: Seeking clarification on the error

I have implemented some validations on a basic login page and added jQuery validation upon button click. However, the code is not functioning as expected. I have checked the console for errors but none were displayed. Here is the code for your review: ...

Stopping the setInterval with jQuery: A guide for beginners

I have a drop-down menu where I can choose the interval time for the setInterval. example.php: <select id="proc_id" class="multiselect custom processselect" name="proc_id" style="display: none;"> <option>Select</option> <opti ...

"Consistent Behavior: jQuery ajax always triggers fail event, even when success is expected

My web page relies heavily on AJAX requests. Take a look at the following code snippet: function fetchSpecificData(start,end){ var link = createLink('open', start, end); getAjaxResponse(link).done(function(data) { //store data in ...

What is the best way to align text alongside icons using ng-bootstrap in Angular 8?

I have a set of four icons positioned next to each other, but I want them to be evenly spaced apart. I tried using the justify-content-between class, but it didn't work. How can I achieve this? I'm creating a Progressive Web App (PWA) for mobile ...

Error: The program encountered a TypeError because it was unable to read the property 'top' of an undefined element when attempting to click the send

I have been searching for solutions, but none seem to match the requirements of my code. My website has various categories. I encountered an issue while attempting to add a new ad post here. form.find('.info-tooltip-container').addClass(&ap ...

Align the menu at the bottom of the navbar using Bootstrap

I'm looking for a way to adjust the alignment of the menu text within the Bootstrap 3 navbar. Here is my current code: <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> ...

Issues with Dropdown Menu Toggle Functionality on iOS Devices

The menu and toggle button are working perfectly on Android browsers, but there seems to be an issue on iOS devices... When I click the button, the menu shows up briefly and then disappears immediately. I've tried various workarounds such as disabli ...