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

Decoding HTML with PHP

I'm facing an issue with creating a Web page Parser. The structure of the page is as follows: <TABLE WIDTH=80%> <tr><td colspan=7><BR><BR></td></tr> <TR> <Td colspan=7><FONT FACE="arial" align ...

When attempting to select an option from the dropdown menu, I encounter an issue where the

My code is not behaving as expected. Whenever I click on the child elements, the dropdown changes to display: none. I am encountering an error when clicking on the input frame and displaying:none. How can I resolve this issue? I would like to be able to ...

What is the best way to deactivate unclicked href links within a loop?

Looking at the template image, my goal is to disable all links that were not clicked when one of the links from 'number1' to 'number3' is clicked. For example, if 'number2' is clicked, then 'number1' and 'number ...

The font sizes appear larger when styled with HTML compared to using Photoshop

When I view my <nav> element in Chrome, the font size of each list element appears much larger than it was originally designed in Photoshop. The font is displaying 23px wider in Chrome compared to Photoshop, even though my resolution is set at 72dpi ...

Discover the steps to download web page data using Objective-C while ensuring that JavaScript has finished executing

I attempted something similar: NSString *url = @"http://www.example.com"; NSURL *urlRequest = [NSURL URLWithString:url]; NSError *error = nil; NSString *htmlContent = [NSString stringWithContentsOfURL:urlrequest encoding:NSUTF8StringEncoding error:&e ...

"Utilizing React's useState feature to dynamically update numerous dropdown components

Here is a React component snippet: const [show, setshow] = useState(false); const handleShow = () => { setshow(!show); }; Accompanied by the following CSS styles: .show { display: block; } .dropdown_content { padding: 3px; display: none; po ...

Having trouble adjusting the space between the footer and the bottom of the page

Looking to create a footer using multiple elements The first element should be positioned at: left: 944px; top: 9749px; The second element should be positioned at: left: 715px; top: 9819px; The third element should be positioned at: left: 718px; top: ...

Troubleshooting jQuery: Unable to refresh the webpage

I have a PHP page that contains a form, checkboxes, and a submit button. I added an if statement to execute a PHP script I created when the button is clicked, which deletes certain values from the selected rows. The button functions properly and changes s ...

What is the best way to create an interactive menu icon that includes dropdown options using MUI menu features?

i am looking to create a component similar to this currently, I am utilizing a material UI pop menu in my project below is the JSX code snippet <div className="navMenu" style={{ position: "relative" }}> <Tooltip title ...

Applying box shadow to input group addon in Bootstrap 3 using CSS

What I am trying to achieve is that when I click on the inputbox or selectbox, the box shadow defined in my CSS should also cover the input-group-add-on feature in Bootstrap 3. The issue I'm facing is that the input-group-add-on does not display the ...

Move a <div> using a handle (without using JQuery)

I devised a plan to create a moveable div with a handle and came up with this code snippet: var mydragg = function() { return { move: function(divid, xpos, ypos) { divid.style.left = xpos + 'px'; divid.style.top = ypos + &apo ...

The website that had been functioning suddenly ceased operations without any modifications

It seems like this might be related to a JavaScript issue, although I'm not completely certain. The website was working fine and then suddenly stopped. You can find the URL here - Below is the HTML code snippet: <!DOCTYPE html> <html> ...

Issue with Domsanitizer bypasssecuritytruststyle functionality on Internet Explorer 11 not resolving

CSS:- Implementing the style property from modalStyle in TypeScript <div class="modal" tabindex="1000" [style]="modalStyle" > Angular Component:- Using DomSanitizer to adjust height, display, and min-height properties. While this configuration work ...

The scrollIntoView function is not functioning as expected

Having an issue with my function called scrollIntoView. It just refuses to work :( Take a look at the code below: HTML <section class="page_mission"> <div class="page_mission_text"> <div class="scroll-animations"> <di ...

Angular Material: creating a custom sidenav transition from detailed layouts to icon-based designs seamlessly without the need for predefined

I'm currently working on a <sidenav> that has the ability to toggle between displaying text along with icons or just icons using a menu button. The <sidenav-content> section is set to automatically resize with a smooth transition effect. ...

Is the table scrollable within the tbody tag?

Is it possible to create a table with a scrollbar on the right side using only CSS and without any plugins like jQuery? Additionally, I want the table header to remain fixed in place. What steps do I need to take to achieve this functionality? ...

Getting Started with CSS Alignment - A Novice's Guide

Recently, I embarked on my journey to learn HTML and CSS with the ambition of creating a login page. Although I've successfully crafted a basic version, I'm encountering an issue where the input boxes and labels are misaligned, giving off an unpr ...

Guide on making a flowchart using CSS

I'm working on creating a CSS flow chart diagram and I've included an image below for reference. Might there be a straightforward method to achieve this? I've been scouring the web for examples, but I'm unsure of what terminology to use ...

What is the priority of the asset pipeline's execution order?

What is the priority of asset pipeline? I am trying to replace a part of ace.css style with user.css.scss. The stylesheet file ace.css in the vendor folder should be overridden by user.css.scss. However, it did not work as expected even when I included ...

When interacting with elements with the "user-select: none" property, WkWebView still allows text selection

When using an iOS iPad app with a single fullscreen WKWebView, an issue arises when long-pressing on an area with user-select:none - the first text in the next available area without user-select:none gets selected instead of being ignored. Is there a way t ...