What is the best way to adjust the width of a horizontal <ul> list using <li> elements?

Need assistance with solving this issue. I am trying to make the <li> elements take up the full size of the <ul> (currently there is some space on the right side). One approach I have considered is removing the right padding from the <ul> (not sure how to do that) and then setting the width of each <li> or calculating it based on the total width of the <ul> divided by 5. However, I don't think this method is quite right because even if I can get it to fit, it may not be a perfect fit. Apologies for any language mistakes in my explanation.

ul {
  padding: 0;
  width: 70%;
  height: 50px;
  border: 1px solid;
}

li {
  height: 100%;
  width: 100px;
  display: inline-block;
  border: 1px solid;
}

li a {
  box-sizing: border-box;
  padding-top: 13px;
  height: 100%;
  text-align: center;
  display: block;
  border: 1px solid;
}
<ul>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
</ul>

If anyone could offer guidance and correct any mistakes, it would be greatly appreciated. Thank you!

Answer №1

Implement flexbox for automatic width adjustment

ul {
  padding: 0;
  width: 70%;
  height: 50px;
  border: 1px solid;
  display: flex;
}

li {
  list-style: none;
  border: 1px solid;
  flex: 1;
}

li a {
  box-sizing: border-box;
  padding-top: 13px;
  height: 100%;
  text-align: center;
  display: block;
  border: 1px solid;
}
<ul>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
  <li><a href="#">Click</a></li>
</ul>

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

Personalizing CSS for a large user base

My website allows users to choose themes, customize background, text, and more. I am seeking the best method to save all of these changes. Is it preferable to use a database read or a file read for this purpose? Any recommendations are greatly appreciate ...

Tips on aligning text to the left on mobile devices using CSS and HTML

When viewed on a standard 16:9 computer screen, everything looks perfect with text on the left and an image on the right. However, when it comes to smaller screens like phones, the picture appears on top of the paragraph instead. I am new to this, so any a ...

Assigning a price to a list of pizza options within a dropdown menu

//The goal is to assign a numerical price to each pizza in the array. We must maintain the structure of the array within the select form. Next, we need to display it in another PHP file, how do we retrieve the values? <fieldset> ...

Sidebar Masonry - Use Bootstrap for a Unique Layout

My goal is to have the page divided into 4 rows, with Masonry aligning the posts within 3 rows and a sidebar displayed on the right. However, I am facing an issue where Masonry mixes everything up and does not allow me to have a sidebar at the right. HTML ...

What is the process for clearing CSS position properties?

I am facing an issue with a multiselect dropdown in my kendo grid, which is being used for a kendo modal window. The dropdown box initially appears correctly but when I scroll horizontally due to multiple columns, the selected value still displays at the o ...

Dynamic divs to occupy the rest of the available vertical area

I have been experimenting with a new website layout and created a form setup. However, I am facing an issue with the fluidity of the layout. While the items are floating into position, there is a problem where if the item on the right is 400px bigger than ...

What is the best way to use ajax to append a value to an input if it is empty, or add a comma with

I recently came across this answer and implemented the following code: Here is the Ajax receiver: success: function(data) { jQuery("#assigncat").val(function(i,val) { return val + (val ? '' : ', ') + data.cat_id; ...

Attempting to Create a New User and Display the Resulting Page Using JavaScript and Handlebars Templates

I've implemented a form that allows users to input data. https://i.sstatic.net/prh11.png Once the user hits "Add User", they are successfully added to the database. However, instead of transitioning to the next page as expected, the form remains popu ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

Utilize CSS to ensure divs display inline-block, but stack them only if they overlap

Below are the div elements I have: .parent { padding: 10px; background: grey; } .child { background: green; display: block; position: relative; width: 50px; } .stacked { left: 0px; } .three { left: 200px; } <div class="parent"&g ...

Tips on aligning border-radius with parent border-radius

Seeking to create a text box with a sleek line on the left side for design flair. The challenge arises when attempting to match the thickness of the line with the border radius of 10px. After various unsuccessful attempts, here is the current solution: ...

Designing a navigational sidebar featuring clickable links to specific locations on Google Maps

I'm currently utilizing a map script created by Derek Ender that integrates with Google Fusion Tables to display locations on a map. While the script is functioning well, I have received a request to make the sidebar list of locations clickable. The ...

Why does the DropDownList consistently remove the initial value?

I am currently in the process of developing a recipe website focused on meals. I have created an admin panel where I can manage the meals added to the site. One issue I am facing is with deleting a meal that was previously added. The menu displays the numb ...

The CSS styles are not being completely applied to the PHP function

My current task involves dealing with multiple folders containing images. When a link is clicked on the previous page, a unique $_GET variable is sent and processed by an if statement, triggering a function to search for and display all pictures within the ...

Illuminate a corresponding regular expression within a text input

I currently have a functional code for testing regex, which highlights matching patterns. However, my challenge lies in highlighting the result within the same input as the test string. Below you will see the HTML and JavaScript snippets along with two ima ...

Having trouble getting a resizable DIV inside a 100% height DIV with margin to work properly. Any tips or assistance would be greatly

I've encountered a common issue that is slightly different from others I've come across. Despite my best efforts, I have been unable to find a solution on my own. If anyone could offer me some guidance on this, I would greatly appreciate it. The ...

Using Node.js to retrieve table data from a URL

My journey with Node JS and express is just beginning as I dive into building a website that serves static files. Through my research, I discovered the potential of using NodeJS with Express for this purpose. While I have successfully served some static HT ...

Looking to discover how to optimize a website for various Android resolutions?

Currently, I am working on designing websites specifically for Android phones. However, I have encountered a major challenge due to the wide range of screen resolutions found on these devices. Some phones boast a height of 800px while others are limited to ...

Manipulating lines and positions with jQuery

I am looking to implement a feature that allows users to choose a specific region on an image using jQuery. The functionality should be similar to the tagging feature on Facebook, but with the added bonus of being able to rotate and scale the selected area ...

Each characterHas its own line

Is there a way to display all text in a div vertically, with one character per line and centered, without using a fixed width? I have achieved this layout by giving the div a fixed width of width: 7%; and using word-break: break-all; Would it be possible ...