Is it possible to equalize the size of these list elements?

I'm new to working with HTML and CSS. My goal is to have navigation buttons that are all the same size, occupying one third of the width of the panel they are placed in. I have access to the original code but can only make adjustments rather than completely replacing it.

The buttons are organized in an unordered list and should span the entire width of the panel where they reside. In Internet Explorer, they display uniformly in size, however in Chrome and Firefox, there are slight discrepancies: the button containing the shortest text appears smaller, while longer text causes the button to expand accordingly. Despite the text being much smaller than the buttons, they seem to affect the button sizes.

The code currently sets the list item elements at 1% width, known as a workaround for achieving similar sizes. Intuitively, using 33% should create the desired uniformity, yet the total occupied width by the three buttons amounts to approximately 33%, leaving empty space. Experimenting with different percentages yields inconsistent results: lower percentages work better on wider screens but fail on narrower ones; anything above 10-33% causes the buttons to gradually shrink instead of filling the available space.

Various attempts to modify the display property for the li elements or ul elements have not yielded the expected outcomes. Reducing the max-width for the text strings did not prevent the buttons from scaling based on string length.

The provided code snippet:

[insert updated code snippet here]
[insert updated HTML structure here]

My aim is to ensure all three buttons maintain the same size regardless of the page's width when arranged in a single row (with vertical stacking below a certain width). What could be causing this issue?

Thank you for any assistance.

Answer №1

"I was provided with the original code and though I can adjust it, I am unable to completely replace it."
What aspects are open for adjustments and what cannot be changed?

Avoid using tables (display: table-cell, etc) for layout purposes.
Instead, consider utilizing 'floats', 'flexbox' or 'grid'.

If you have precisely 3 elements, floats could work effectively:

/* Utilizing Floats */

.nav-justified > li {
    display: inline-block;
    float: left;
    width: 33.3333%;
}

.nav-justified::after { /* clearfix */
    content: '';
    display: table;
    clear: both;
}

If you desire all the <li> elements to possess equal size, no matter how many there are, flexbox is the way to go:

.nav-justified {
    display: flex;
}
.nav-justified > li {
    flex: 1 1 0; /* flex-grow: 1; flex-shrink: 1; flex-basis: 0 */
}

With this approach, each item will receive an even allocation of space, regardless of their individual content.

Answer №2

For those utilizing the bootstrap framework, it is advisable to embrace and utilize the classes that come with bootstrap rather than crafting your own styles.

Explore the Nav class and style provided by bootstrap

html {
  font-family: sans-serif;
  -webkit-text-size-adjust: 100%;
      -ms-text-size-adjust: 100%;
}

body {
  margin: 0;
}

html {
  font-size: 62.5%;
}

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
    min-width: 400px;
    background-color: #bbc98f;
}

ul,
ol {
  margin-top: 0;
  margin-bottom: 10px;
}

.nav {
  padding-left: 0;
  margin-bottom: 0;
  list-style: none;
}

.nav-pills > li {
  float: left;
    border-style: solid;
    text-align: center;
}

.nav-pills > li + li {
  margin-left: 2px;
}

.nav-justified > li {
  float: none;
    display: table-cell;
    width: 1%;
}

.panel {
  margin-bottom: 10px;
  margin-top: 10px;
  background-color: #ffffff;
}

.panel-body {
  padding: 15px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<body class=""> 
    <div class="body-content">
<div class="panel panel-body">
<ul class="nav nav-pills">
<li>
<a href="/PartLibrary/Parts">Parts</a>
</li>
<li>
<a href="/PartLibrary/Recipes">Recipes</a>
</li>
<li>
<a href="/PartLibrary/RobotPrograms">Robot Programs</a>
</li>
</ul>
</div>
    </div>
    

</body>

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

Leverage a JSON variable within jQuery to showcase additional JSON variables

This code snippet is a work in progress, and there is room for improvement. The goal here is to have the content of thumb2 displayed in the #imageLoad container when a user clicks on a thumbnail inside the #placeholder DIV. Keep in mind that both Thumb and ...

Insert a section of background within the div

Does anyone know how to create a div with a partial background like the example shown here? https://i.sstatic.net/CDqCe.png I attempted to add white margin, but I'm struggling to get it right. ...

What is the reason that custom styling for a single react component instance does not function properly?

In my current view, I have integrated a react component as shown below: <Jumbotron> Lots of vital information </Jumbotron> I am looking to give this particular instance a unique style, like using a different background image. However, addin ...

What is the process for adding tailwind CSS via npm?

Before, I was including Tailwind using a CDN. Now, I have installed it with npm and all three .css files are included, but the styles are not appearing in my HTML document. Here is the directory structure and a link to style.css The content of tailwind.c ...

Steps for showcasing a automated slideshow

I'm currently working on creating a slideshow that automatically displays multiple images. While the first image shows up just fine, it doesn't seem to transition to the next one. var currentSlide = 0; displaySlides(); functio ...

Generating a clickable link from information pulled from a database and utilizing the get() method

Currently experimenting with a form I created and everything is functioning smoothly. My current objective involves retrieving specific rows from my database and presenting them as a summary on a separate page. However, I want these rows to appear as hyper ...

Enhancing the appearance of specific text in React/Next.js using custom styling

I have a table and I am currently working on implementing a search functionality that searches for an element and highlights the search terms as they are entered into the search bar. The search function is functional, but I am having trouble with the highl ...

Conceal the countdown clock and reveal the message box

I am attempting to create a functionality where the text box will replace the timer when it reaches 0, and then the timer will be hidden. I am seeking a straightforward solution using either the 'v-show' or 'destroy' property in vue.js ...

Text centered over an animated underline using CSS

Seeking help with my bootstrap 4 nav menu. I have implemented a CSS animation that creates an outward underline effect for the nav-link items. However, I am struggling to center the text above the line. Any suggestions on how to achieve this? I attempted ...

Concealing information based on the value of a variable

Creating a dynamic price estimator. I need help writing a jQuery function that can hide or show a specific div element based on the value of a variable. For example, let's say I have an HTML div with the ID 'Answer': <div id="answer"&g ...

trigger jquery popup from server-side code (ASP.Net VB)

Within my code, I have created a div element which serves as a popup message: <div class="info message"> <h3>Informa&ccedil;&atilde;o</h3> <p>Mensagem informativa.</p> </div> In addition, ther ...

The transition feature is not functioning properly in Firefox

I have a basic HTML and CSS setup below. It seems to be working fine in Chrome, but I'm having trouble with the transition effect in Firefox. I am currently using Firefox version 18. I tried looking up solutions on Google and Stack Overflow, but none ...

Stop all animations in JS and CSS

Looking for a way to halt all CSS and JavaScript animations, including canvas and webGL effects, on a specific webpage. Some animations can cause slow performance on certain browsers like Opera and Firefox, so I'm seeking a code snippet or guidance o ...

Tips for positioning a JQuery drop-down correctly

Although I am not well-versed in JQuery and struggle with CSS, I often find myself working with both. Currently, I have encountered a problem: The jquery script I am using involves clicking on an image to reveal a login box that drops down using slideTogg ...

What causes the size of an image to decrease when placed within an anchor tag?

Trying to add clickable social media icons, but when wrapped in an anchor tag the images shrink significantly. <span class="iconspan"> <a href="https://www.instagram.com/lil_ijoez/" target="_blank" ...

The setting "break-word" within word warp attribute isn't effective for formatting my text

Here is the CSS code that I am using: .SubjectCell{ width: 300px; padding-left: 3em; padding-right: 2em; color: black; font-size: 20px; word-wrap:break-word; } I have applied this class to a table cell within a table in my datalist: <td class ...

Switching from vertical pills to horizontal tabs for smaller screens

I have a vertical pills menu that looks great on large screens, but takes up too much space on small screens. Is there a way to switch it to a horizontal tab layout for smaller screens? I tried searching online for examples but couldn't find any. < ...

Utilizing JQuery to capture user input in a textarea and showcase it in a span element with key press

Is there a way to capture the user's input and display it in a span above the textarea? Specifically, how can I detect when the user presses the enter/return key (keyCode 13) and correctly insert a line break ( ) in the span? $('#InviteMessage ...

Is the accuracy of Chrome's inspect device not up to par?

I'm currently testing how the page appears on a 1366x768 laptop. When inspected in the device, it looks perfect: https://i.sstatic.net/OECnx.png However, on the actual laptop screen, it's completely off: https://i.sstatic.net/chaeY.png It&ap ...

The timer freezes briefly at 1:60 before switching to 1:01

I'm in the process of creating a website for Rubik's cube scrambling and timing, and everything seems to be working well so far. I have implemented a scrambler, a timer, and a list of recorded times (still a work in progress). The timer is functi ...