CSS3 columns are not behaving as expected, causing elements to be oddly positioned and not filling the width correctly

Exploring the column rule in CSS for a Pinterest-inspired layout has been a bit confusing. The results are not turning out as expected, and I suspect there might be an error in my approach.

One issue I've encountered is that when the number of child elements increases, the last column gets significantly disrupted. The elements from each column end up shifting to the bottom of the previous one, except for maybe the first or second row.

Furthermore, I notice a strange and large margin below the final row. It appears as if there's an invisible additional row at the end, even though there isn't.

Lastly, it seems like the columns fill up in an odd order. For instance, the 3rd element goes to the 3rd row while the 8th element is placed at the top.

Despite these challenges, the columns do seem to appropriately adjust their width based on the number of elements in the list.

An interesting observation is that removing the column-gap rule actually increases the space at the bottom of the page!

I'm wondering if there's a better way to consistently make sure the content always fills 100% of the width (with N rows as specified by column-count) and have the cells inserted from left to right before moving to the next row?

#posts{         
        width: 100%;
        overflow: hidden;
        -webkit-column-count: 4;
        -webkit-column-gap: 1.875em; /* 30px */
        -webkit-column-fill: auto;
        -moz-column-count: 4;
        column-gap: 1.875em;
        -moz-column-gap: 1.875em; /* 30px */
        -moz-column-fill: auto;
        column-count: 4;
        column-fill: auto;
    }

.post{                  
    display: inline-block;
    margin-bottom: 1.875em;
    -webkit-column-break-inside: avoid;
    -moz-column-break-inside: avoid;
    column-break-inside: avoid;
}

HTML

<section id='posts' class='clearfix'>
    <div class='post'>
        <div class='top' style='background-image: url("http://lorempixel.com/400/300/sports/1")'></div>
        <div class='bottom'>
            <span class='title'>Lorem ipsum sit ament lorem lorem ipsum</span>
            <span class='date'>em 15/08/2014</span>
        </div>
        <span class='category'>Lorem ipsum</span>
    </div>
....
    </section>

An example of an issue (there are multiple occurrences, this one occurs with columns-count: 4 and 6 items in the list)

Answer №1

multiple-columns are not fully supported yet, with known bugs in Chrome. It seems that there is no easy fix for this issue at the moment. Patience may be required until the browser resolves these issues.

You can check out the support for #multicolumn here

Chrome has been known to have issues calculating container height incorrectly and frequently experiences problems with margins, padding, and occasionally displays a pixel of the next column at the bottom of the previous column.

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

Converting an HTML table into a visual image

I've encountered an issue. My task involves transferring an HTML table to a PDF using fpdf. Is there a way to transform an HTML table into an image (via URL link)? ...

Choose from a variety of categories with overlapping options

I am in the process of designing a webpage that requires the user to choose values for various categories from a dropdown list. Below is a snippet of the code showcasing this: <div class="SurveyFormContainer"> <label for="cat1">category 1& ...

Adjusting the width of the Bootstrap input group-prepend/addon

I am encountering difficulties with ensuring that all prepend add-ons have the same width. The issue arises when using Font Awesome icons, as each prepend is sized according to its specific icon. I came across a similar thread from approximately one year a ...

The Art of Repeating: Navigating through a Multi-Layered Array

My PHP Array looks like this: $fruits = array( array("Apple", 1.25), array("Banana", 0.86), ); Desired HTML Output: I want the HTML output to be formatted as follows: Fruit: Apple Price: 1.25 Fruit: Banana Price: 0.86 Attempts Made: I tried ...

What are some other options to using position: absolute when working within an inline position:relative?

I've been struggling with this problem for some time now and just can't seem to find a solution. The issue involves a series of position: relative spans enclosing text, along with a position: absolute span set to right: 0;. I expected the second ...

Ensure there is a gap between each object when they are arranged in a

Is there a way to customize the layout of elements in the ratings view so that there is automatic spacing between them? I considered using text (white spaces) for this purpose, but it seems like an inefficient solution. Are there any other alternatives to ...

Achieve vertical center alignment of items using flexbox styling

I'm attempting to vertically center elements using CSS flexbox. I have successfully implemented it with the non-vendor-prefixed code, but I am facing issues in Webkit (Chrome) even with the vendor prefixes. My goal is to vertically align the spans wi ...

What is the best way to generate a ul-li structure using JSON input and jQuery?

There is a JSON variable present: var links=[{"text":"Home","href":"http://home.com","icon":"fas fa-home","target":"_top","title":"My Home","children":[{"text":"home2","href":"home2.com","icon":"fas fa-chart-bar","target":"_self","title":"home2","category ...

Retrieving all options from a dropdown list in HTML using ASP.net C#

I am currently working with a select list that looks like this: <select name="Section" id="Section" size="5"> <option>Section1</option> <option>Section2</option> <option>Section3</option> <option>Section4< ...

Guide on how to forward the response obtained from an Ajax call to a different HTML page

I am working with a mongoose database that stores data containing an individual's first and last name. The user inputs their first name into a field, triggering an ajax request sent to the file named controller.js. This file generates a JSON response ...

What is the best way to ensure a grid remains at 100% width when resizing a browser window?

Within the div element, I have two child divs. One has the class col-md-2 and the other has the class col-md-10.Check out a sample view here In the image provided, the div containing hyperlinks (Database edit, invoice, preview) is not taking up 100% width ...

"Interacting with the ng-keypress event causes the page to smoothly scroll

As a newcomer to angularjs, I am trying to figure out why my component (which simulates a "checkbox" using fontawesome icons) causes the page to scroll down when the user presses the space key. Here is a snippet of my component : ugoFmk.component(' ...

Angular iteration does not display column as undefined

For the past 4 hours, I've been wrestling with this challenge! :D The issue at hand is that I'm attempting to create a form and dynamically add rows with input fields. Here's how it looks: </div> <a ng-click="add_r ...

Troubleshooting image resolution issues in ASP web application (using C#)

I've been working on developing an asp web application that requires users to register details of a person, including uploading an image. The file name of the details/image are stored in a SQL database with the image filename saved in an NVARCHAR colu ...

Do not apply styling to a particular page in CSS and HTML

Utilize the teachable.com platform and take advantage of their code Snippets feature (refer to attached photo #1) https://i.stack.imgur.com/dW1lB.png I inserted the following code: div { direction: rtl; } To modify the website's direction to be ...

What steps can be taken to repair the footer area within this CSS document?

As a beginner ASP.NET developer, I am encountering CSS for the first time. The CSS file I have is fairly simple, but I am facing difficulties with the footer section. The current appearance of the footer is as follows: I am looking to make the following m ...

What is the best way to eliminate the gap between spans in Bootstrap?

Imagine you have the following code: <div class="row-fluid"> <div class="span6"></div><!--span6 END--> <div class="span6"></div><!--span6 END--> </div><!--row END--> Now envision two red b ...

Is there a way to turn off alerts from Aspx files for HTML and CSS?

Dealing with annoying warnings in my aspx files has been a constant struggle. The "CSS Value is not defined" message pops up when I reference CSS files from different projects, causing unnecessary frustration. Even more frustrating are the warnings about i ...

Highlighting of tab CSS is not persistent when switching tabs or clicking elsewhere on the page

Using Bootstrap 4, a navigation tab is created. However, upon loading the page, the home tab is automatically loaded but not highlighted. Clicking on any tab will highlight it correctly, but once clicked anywhere else on the page, the highlight disappears. ...

The labels assigned to buttons will direct users to unique links specifically designated for that button

I've been working on a website to share some code I created, but my skills in HTML and CSS are not the best. Please forgive me if there are obvious mistakes. Here's the code I have so far: <!DOCTYPE html> <html> <head> ...