Tips for achieving equal width li elements within various columns in Bootstrap 4 beta 2 and ensuring they span the full screen width

I've been scratching my head for a while, but I just can't seem to make it work. On the fiddle link provided, you'll notice three main blocks in light gray, each containing a variable number of smaller dark blocks. My goal is to have these smaller blocks evenly spaced across the width of the screen or relative to the .thisBlock block. The markup is pretty complex, so I've only included the essential parts. Link to the Fiddle

<div class="row">

  <div class="col-12">


    <div class="row no-gutters">

      <div class="col c">

        <div class="block">
           <ul class="ul d-flex justify-content-between">
            <li class="d-inline-block">1</li>
            <li class="d-inline-block">2</li>
          </ul>
        </div>

      </div>

      <div class="col c">

        <div class="block">
           <ul class="ul d-flex justify-content-between">
            <li class="d-inline-block">11</li>
            <li class="d-inline-block">22</li>
            <li class="d-inline-block">33</li>
          </ul>
        </div>

      </div>

      <div class="col c">

        <div class="block">
           <ul class="ul d-flex justify-content-between">
            <li class="d-inline-block">11</li>
            <li class="d-inline-block">22</li>
            <li class="d-inline-block">33</li>
            <li class="d-inline-block">44</li>
          </ul>
        </div>

      </div>

    </div>


  </div>

Here's the CSS snippet:

.c {
  background-color: green;
  margin: 0 2px;
  color: white;
  width: 100%;
}
.ul {
      padding: 0;
    margin: 0;
    background-color: #dfe0e2;
    padding: 5px;
}
.ul li {
  background-color: #5d5d5d;
    color: #919191;
    cursor: default;
    width: 100%;
    margin: 0 2px;
}

Answer №1

Here is the jQuery snippet for your reference:

var countLi = $('.thisBlock li').length;

$('.thisBlock .c').each(function(index, item){
    var itemLiCount = $(item).find('li').length;
    $(item).css({'flex-basis': itemLiCount/countLi * 100 + '%'});
})

Check out this JSFiddle link for a live demo!

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 customize the connector for Ant Design Steps?

Does anyone know how to adjust the color and width of the connector line in Ant Design's Steps component? I've tried inspecting it but can't find a way to style it separately using className. If you have any tips, they would be greatly appr ...

The proper way to define the margin-left property for different browsers

I'm working on aligning a checkbox. When I use margin-left : 10px; //works well with IE The alignment looks good in IE. However, if I try using margin-left : 15px; //works better with chrome It looks proper in Chrome. Is there a way to find a so ...

Is there a way to create a row with 4 columns in a loop using Bootstrap 4?

I'm struggling to display 4 columns in one row within a loop. My goal is to achieve the following layout when clicking on the modal in Bootstrap 4: View Desired Layout This is what I have tried so far: <div class="modal-body"> <div cla ...

Retrieve the HTML tags following the modification of my information in ASP.NET

Apologies for any language errors, I am new to asp.net development. 1- I have a table with dynamically created rows and columns based on user selection of row and column numbers. 2- Each row in the table has the following controls: A- One textbox, one l ...

What is the best way to ensure that the text remains visible on the image?

Is there a way to maintain the static 'BUY NOW' tag on an image while allowing other elements to be dynamic? Any suggestions on how to achieve this within an img tag?https://i.sstatic.net/6eLoN.jpg ...

The second div element remains unselected in jQuery

Below is the example of an HTML structure: <span id="17">yes here</span> <div class="PricevariantModification vm-nodisplay"></div> <div class="PricesalesPrice vm-display vm-price-value"> <span class="a"></span> ...

What is the process for adjusting the border color of my button?

Is there a way to change the blue outline color to #D5A021 instead of blue when the button is clicked by the user? I believe it might be related to the btn-primary class HTML <a class="btn btn-primary btn-xl js-scroll-trigger" href="#services">Fin ...

Should Chrome be allowed to have TABLE tags within P tags?

When testing the code below on Google Chrome: <p>Some words <table> ... </table> I noticed that the nesting under Chrome appears as html > body > p > table. It seems like there is a missing </p>, but according to HTML4, ...

Expansive background with adaptable height dimensions

Is there a way to use Foundation to create a header with a full-width image and responsive height using CSS only, or do I need to use JavaScript for this? Can someone assist me with this? This is the code from index.html: <!doctype html> <html ...

Using JQuery to parse an XML file and automatically redirecting the page if a specific attribute equals "Update"

Updated I've made some edits to clarify my request. My website is built using HTML5, CSS3, and JQuery, resulting in all content being on one page. During updates, I want the ability to set an option in a configuration file so that when users visit m ...

What is the best way to add a centered progress spinner on top of an overlay?

Here is a code snippet that includes functionality to append a site overlay as needed. I am currently trying to implement the feature of also displaying an image progress spinner in the center of the screen over the overlay. I would prefer if this spinner ...

JavaScript code is experiencing issues following a for loop

I recently developed a code to upload resized images using HTML and JavaScript. Here is the HTML form setup: <form action="aa.php" method="post" id="uploadImageForm" enctype="multipart/form-data"> <input type="file" id="fileToUploadId" ...

Customizing the styling of an anchor tag using CSS in Bootstrap

I want my active link to appear red: nav class="navbar navbar-inverse"> <div class="container col-1 col-sm-12"> <ul class="nav"> <li class="<%= 'active' if current_page?(squad_path) %> ...

Avoid navigating through hidden tab indexes

Below is the HTML code that I am working with: <span tabindex="19"> </span> <span tabindex="20"> </span> <span tabindex="21"> </span> <span id="hidden" tabindex="22"> </span> <span tabindex="23"&g ...

Adjusting the position of a stationary element when the page is unresponsive and scrolling

Managing a large web page with extensive JavaScript functionality can be challenging, especially when dealing with fixed position elements that update based on user scroll behavior. A common issue that arises is the noticeable jumping of these elements whe ...

Tips for creating a responsive image gallery

After completing the development of my interactive Video Gallery using only HTML and CSS, I encountered an issue with responsiveness. Whenever I resize my browser, the images go out of the frame. I am looking for a solution to make the image gallery adjust ...

Tips for keeping your avatar contained within a Bootstrap grid

I am attempting to adjust the positioning of my "image holder" (avatar) with a top and bottom margin of 3px, but when I implement this change, the image holder shifts outside of the grid. Below is the code snippet in question: <div class="container con ...

What is the best way to dynamically set an ID in Angular using the pound symbol (#)?

I am currently developing a dynamic Angular 6 application that utilizes dynamic components. My approach involves using @ViewChild('<id>', { read: ViewContainerRef }) <id>; to reference the divs where I intend to populate with dynamic ...

Is it possible to submit form data to multiple destinations in an HTML form submission?

I am in the process of developing a quiz application that consists of two essential files: question.php and process.php Within question.php, the user is required to input their answer in a textbox and submit it by clicking a designated button. This input ...

What is the best method for passing parameters from HTML to AJAX within code?

My project involves working with Flask, HTML, and Ajax. Here is the HTML code snippet: <script type=text/javascript> $(function() { $('a#calculate').bind('click', function() { $.getJSON('/_add_numbers&ap ...