Eliminate gaps between lines in a wrapped Flexbox layout

I am trying to eliminate the spaces between rows in a horizontal list flexbox. I am creating an alphabetical list and I want it to flow seamlessly without any gaps.

This is what I have so far:

#example 
{
  display: block;
  margin-left: auto;
  margin-right: auto;
  background-color:#555;
  color: white;
}
#example ol
{
    display:flex;
    /*justify-content: center;
    justify-content: space-between;
    flex: 1 ;*/
    flex-shrink: 0;
    flex-flow: row wrap;
    justify-content: space-between;
    align-items:flex-start;
    /*align-self: center;*/
    /*align-content:flex-start;*/


}
#example ol li::marker
{
    margin-right:5px; 

}
#example ol li
{
    color:white;
    font-size:40px; 
    list-style-position:inside;
    margin-bottom: 20px;
}
#example ul li
{
    color:white;
    font-size:20px;
    margin-bottom:20px;
}

View whitespace between list items

Appreciate any help you can provide

Answer №1

It's possible that using flex won't give you the desired outcome. One alternative is to experiment with float: left; on child elements, but this may still result in uneven spacing below the content.

You could explore the Masonry layout solution in JavaScript as another option.

Alternatively, utilizing column-count: 3; can help eliminate those white spaces, although the layout will appear as follows:

A D G
B E H
C F J

(arranged from top to bottom similar to a newspaper)

I've included two rules within the ul to prevent the division of content across columns.

  display: inline-block;
  width: 100%;

.wrapper {
  column-count: 3;
}

.wrapper ul {
  display: inline-block;
  width: 100%;
  list-style: none;
  padding: 0;
  margin: 0 0 1em;
}
<div class="wrapper">
  <ul>
    <li>List 1 - child</li>
    <li>List 1 - child</li>
    <li>List 1 - child</li>
    <li>List 1 - child</li>
    <li>List 1 - child</li>
    <li>List 1 - child</li>
  </ul>
  <ul>
    <li>List 2 - child</li>
    <li>List 2 - child</li>
    <li>List 2 - child</li>
  </ul>
  <ul>
    <li>List 3 - child</li>
    <li>List 3 - child</li>
    <li>List 3 - child</li>
    <li>List 3 - child</li>
    <li>List 3 - child</li>
  </ul>
  <ul>
    <li>List 4 - child</li>
    <li>List 4 - child</li>
    <li>List 4 - child</li>
    <li>List 4 - child</li>
    <li>List 4 - child</li>
  </ul>
  <ul>
    <li>List 5 - child</li>
    <li>List 5 - child</li>
    <li>List 5 - child</li>
  </ul>
  <ul>
    <li>List 6 - child</li>
    <li>List 6 - child</li>
  </ul>
  <ul>
    <li>List 7 - child</li>
    <li>List 7 - child</li>
    <li>List 7 - child</li>
    <li>List 7 - child</li>
    <li>List 7 - child</li>
  </ul>
  <ul>
    <li>List 8 - child</li>
    <li>List 8 - child</li>
    <li>List 8 - child</li>
    <li>List 8 - child</li>
  </ul>
  <ul>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
    <li>List 9 - child</li>
  </ul>
  <ul>
    <li>List 10 - child</li>
    <li>List 10 - child</li>
  </ul>
</div>

Answer №2

After examining the HTML code, it is evident that removing the whitespace alters the appearance of the grid by adjusting each element's height based on its content.

If this adjustment is deliberate, one solution could be to 1) change all child elements to display inline so they shrink and expand only as needed, or 2) if the column content remains constant regardless of screen size, place each column in a separate container with a specified minimum height.

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

Issue with absolute positioning occurs when the screen resolution or window size is altered, causing the feature to

Take a look at the code snippet below: <div style="position: relative;"> <div style="position: absolute; left: 10px; top: 18px;"> <img id="ImgTachoMetre" src="/Images/u174_normal.png"> </div> </div> I have wr ...

Tips for incorporating multiple classes in Material UI by utilizing the classes props

When using the css-in-js technique to apply classes to a react component, how can I add multiple classes? Below is an example of the classes variable: const styles = theme => ({ container: { display: 'flex', flexWrap: 'wrap&apo ...

Using a web browser control to choose a radio button and then submit the form

Currently, I am attempting to use my WebBrowser control in order to select a radio button and also click on a submit button that doesn't have any id or name attached. Below is the snippet of HTML code from the webpage: <form method="post> & ...

Adaptable Bootstrap Button that Adjusts to Different Screen Sizes

I want this button to adjust its size according to the screen dimensions. The current code keeps the button fixed in place. See below for the code snippet. <button type="button" [className]="'btn btn-block m-0'" kendoButton ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): EDIT: The layout on large screens looks fine, as I prefer not t ...

Tips for effectively overlaying one container on top of another in a responsive manner

There are a pair of containers. The main container functions as the parent, while the child container acts as a tag to categorize the content. The objective is to position the tag container at the top right corner of the main content container, slightly of ...

Styling: How can I create indentation for a specific text area while leaving another unaffected?

I am attempting to format this complete form with an indentation: <%= form_for([micropost, micropost.comments.build], :html => { :id => "blah_form" }) do |f| %> <div class="field"> <p2>Who are you?</p2> ...

Adding Extra Fields to PHP Email Form

Currently, I have an email form set up using PHP: <form method="post" action="contactus.php" autocomplete="off"> <label for="Name">Name:</label> <input type="text" name="Name" id="Name" maxlength="60" required/ ...

Using jQuery to position an element above an ID

I'm currently working on a unique portfolio gallery for my website, but I've encountered a problem. What I'm aiming for is to create a gallery that will slide up when a thumbnail is clicked, without loading all images on the page at once. T ...

Updating image on click in CSS and HTML

How can I change the image to display a different picture when clicked? I currently have a green image that, upon clicking, switches pages and transforms into a white image. Before Click After Click This is my code: <ActiveLink activeClassName=" ...

Is your JQuery Gallery experiencing issues with the next button function?

I'm working on developing a simple gallery using JQuery. The main concept is to have all image files named x.png (where x is a number), and the program will then add a number to the current one, creating x+1.png and so forth. Here's the code I ...

Reading settings from web.config file in an HTML page

Currently working with ASP.NET 3.5 web forms. I've recently saved the path of my website in the web.config file under the key "CommonPath". I have a basic static HTML page that I would like to utilize this key on. Any suggestions on how to achieve ...

Stop users from refreshing or closing the window while an axios request is being processed

I'm in the process of creating a dynamic Web Application that involves utilizing Axios.get requests. Given that Axios operates asynchronously, my approach includes an async function along with await axios.all: async handleSubmit(){ const ...

What is the method to extract div text using Python and Selenium?

Is there a way to extract the text "950" from a div that does not have an ID or Class using Python Selenium? <div class="player-hover-box" style="display: none;"> <div class="ps-price-hover"> <div> ...

Scroll sideways with AJAX content replacement

I've successfully discovered various methods for loading and replacing content with ajax, as well as ways to hide/show with effects. However, I'm now seeking a technique that allows the new content to slide into a div while the old content slide ...

Clicking the set button in Jquery mobile datebox resets the time

I am experimenting with the jquery mobile datebox (courtesy of Jtsage) to select time and date. Unfortunately, every time I reset the time by clicking the set button, I am unable to retrieve the correct time. Below are my code snippets: $.extend($.jtsag ...

Hugo/Docsy encountered an error while executing the template at <.url>: unable to assess the url field in type bool

Currently, I'm in the process of creating a static web application using Hugo in combination with the Docsy theme. In my code for the Docsy Partials, I'm attempting to incorporate a conditional statement that appends the word mailTo: to my .url i ...

Isotope grid shatters when browser window is resized

My goal is to design a 3-column grid using Twitter Bootstrap and Isotope. However, when I resize the browser to force the layout into a single column mode, Isotope fails and leaves large spaces both vertically and horizontally. Regular Layout Issues in ...

Is it possible to change the background color using jQuery?

Can you assist me with this: I have a website and I am looking to modify the bg-coler when hovering over the menu (similar to how it works on the rhcp-website). I attempted using jquery for this, but unfortunately, it did not yield the desired result.. ( ...

Problem encountered while generating a torus shape using webGL

I am currently developing a program that aims to create 3D parametric shapes using webgl. The current code I have works successfully for rendering a sphere, but when I try switching the equations for a torus, only the upper half of the torus is being displ ...