Flexbox Masonry design without the initial block

After much effort, I successfully created a posts list layout using CSS flexbox, but the masonry layout for post blocks still eludes me.

In the code snippet provided below, you'll notice that while the first post achieves full width as intended, the subsequent posts align equally instead of creating a masonry effect.

I am seeking guidance on how to implement this desired masonry layout using CSS flexbox.

Answer №1

For more information on using multi-column layouts in CSS, check out this resource: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Columns/Using_multi-column_layouts

The CSS Multi-column Layout Module allows for the creation of multiple columns of text within a block layout. This is particularly helpful as long lines of text can make reading challenging. By utilizing limited-width columns placed side by side, akin to newspapers, readers can maintain focus and readability.

You can also explore this tutorial and others at: https://css-tricks.com/almanac/properties/c/columns/

With a few key CSS rules, a print-inspired layout that adapts to different screen sizes can be achieved. Similar to how a newspaper adjusts its columns as the page size changes, web layouts can automatically balance and flow content naturally across various devices.

Below is a code snippet you can use to test behavior:

/* Box Sizing */
* {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
*:before,
*:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Post Layout not Using Flex */
.post_layout {
    column-count:2;
    column-fill:balance;
    border:1px solid red;
    box-sizing: border-box;
}
.first-post {
    transition: .8s opacity;
    border:1 px solid green;
}
.col-6 {
    transition: .8s opacity;
    border:1px solid blue;
    margin:5px
}
<div class="first-post">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eget placerat lectus. Aliquam erat volutpat. Integer condimentum quis diam sed elementum. Donec vitae tellus in turpis condimentum ullamcorper non in nulla. Praesent erat ligula, facilisis sed augue eget, commodo ultrices eros. Morbi id augue semper, tincidunt purus et, semper ipsum. Vivamus tristique efficitur pharetra. Sed tempus malesuada purus, eget dapibus nibh ultrices vel. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pra...
</div>
<div class="post_layout">
    <div class="col-6">
        In malesuada lorem vel nunc auctor tempor. Vivamus lobortis molestie lorem, non posuere orci auctor nec. Mauris auctor placerat aliquet. Cras venenatis tellus et mi euismod eleifend. Proin ultricies blandit metus eu vestibulum. Quisque iaculis placerat lobortis. Etiam eu fermentum nibh, ac faucibus metus. Nulla placerat justo et malesuada ornare.
    </div>
    <div class="col-6">
        Praesent efficitur ligula magna, eget maximus nibh maximus a. Nulla facilisi. In hac habitasse platea dictumst. Suspendisse vulputate nulla vitae nunc luctus, vitae venenatis est efficitur. Praesent iaculis, mauris condimentum vulputate fermentum, dui elit rutrum ligula, non efficitur risus tortor sed massa. Sed a dui semper, finibus ex quis, posuere tortor. Duis rutrum lacus vitae feugiat gravida. Nullam a orci sit amet purus tempor commodo. Praesent blandit nisl tellus, non accumsan felis sollicitudin eu....
</div>

If you are looking to utilize the column-span property, note that it is not supported. The first block needs to be taken out of the column boxes.

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

Where can I locate documentation on the source code of Node Red Editor in order to customize the CSS and JS for the client?

I am seeking assistance in modifying the following files: red.min.js located at: ~ npm\node_modules\node-red\node_modules@node-red\editor-client\public\red style.min.css located at: ~ npm\node_modules\node-red\ ...

What is the best way to apply CSS styles conditionally in AngularJS?

Q1. What is the most effective method to modify the appearance of each selected "item" by a user, before pressing the main "delete" button? The aim is to provide immediate visual feedback to eliminate the need for a confirmation dialog box. Users will mark ...

Exploring the semantics of CSS documents

Picture this scenario: I have a massive CSS file with over 40,000 lines, like the one found at https://cdn.jsdelivr.net/npm/[email protected] /dist/semantic.css I need to sift through this file and specifically search for class definitions that inclu ...

What causes text to display on image hover with v-if, v-else, @mouseover, and @mouseleave in Vue.js?

I'm having an issue with creating a hover effect on images using Vue.js. After implementing the code below, I encountered a problem where the text is displayed over all images when hovering over one of them. How can I fix this so that only the text re ...

Distances measured in relation to the present Div

When trying out the jQuery animation effect by editing margins to move, an issue arose. The problem is that while using the animation effect within a div that contains most of the content on the page, the edited margin ends up being relative to the actual ...

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. ...

Tips for removing the extra space below an element within a details element

When I have a details element and try to set its height to 100%, there is some space below the element, even when tested with a textarea and div. https://i.sstatic.net/zZszF.png I am specifically talking about the space between the red border of the .log ...

Creating tags in HTML and displaying them on a webpage

I have a code that sends a message from a textarea after completion tags are entered as I wrote. The desired output should be: <h1> Thanks </h1> The expected output is: Transmitter Thanks instead of <h1> Thanks </h1> ...

The appearance of my hyperlink-text seems unusual within my list of linked bullets

Observing the image: https://i.sstatic.net/uSezX.png In the scenario where the hyperlink text is split into two lines, the second line does not align with the starting position of the first line. How can we automatically indent the second line to the rig ...

The alignment of items to the top, center, and bottom is experiencing difficulties

I am facing an issue with positioning elements within a div. The layout consists of an image on the left, followed by information on the right (a span, an h3, and another span). My goal is to align the first span at the top, center the h3, and position the ...

Subtract and include characters in a string

Can you help me swap out \n for a new line? Below is the content retrieved from the database: <!DOCTYPE html>\n<html>\n<body>\n<div>\n<label class=\"s20 c03\">Label</label>\n< ...

What is the best way to ensure that the input search bar, microphone icon, and two small boxes adapt to different screen

Upon submitting my exercise for The Odin Project, I was under the impression that everything looked perfectly aligned and centered on my MacBook Pro 15-inch screen. However, when I viewed the completed webpage on a larger computer screen at work, I noticed ...

What is the method for retrieving the IDs of checkboxes that have been selected?

I attempted running the following code snippet: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://static.jstree.com/v.1. ...

Methods for adding information to a database without using HTML form tag

This is the creation of my design... And here is the snippet of my HTML code... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <!-- Form fields for dealer information --> < ...

Exploring the World Wide Web with BeautifulSoup4

I am trying to extract all the times from a webpage and store them in a list variable. How can I achieve this? Any help is appreciated. <div class=panchang-box-secondary-header> <div class="list-wrapper pl-2"> <div class="li ...

CSS / JavaScript Navigation Menu overshadowing Flash content in Firefox

On my website, I have a drop-down menu that was created using CSS and JavaScript. This menu drops down over a Flash animation. Interestingly, in Internet Explorer 6 and 7, the drop-down menus successfully appear over the Flash animation. However, in Mozill ...

Removing HTML Elements from an iFrame with JavaScript

Is it possible to delete a div with content in an iFrame using JavaScript? How can I achieve that? I am looking to completely remove the div from the HTML rather than just hiding it with CSS (e.g. display: none). While I have some understanding of JavaScr ...

Animate the smooth transition of a CSS element when it is displayed as a block using JQuery for a

I have implemented the collapsible sections code from W3 School successfully on my website. Now, I am trying to achieve a specific functionality where the "Open Section 1 Button" should slide down with a margin-top of 10px only if the first section "Open S ...

"Utilizing jQuery to achieve vertical center alignment within a div

Attempting to vertically center a div within another div that has 100% dimensions is proving to be a bit challenging. The code I have written seems to work but occasionally triggers an odd bug. This is the snippet of code in question: var window_height = ...

What is the best way to adjust the animation settings for SweetAlert2's Toast feature?

I recently integrated SweetAlert2's toast notifications into my web application and customized the animation using the customClass parameter to have the notification slide in from the right side. However, there are a couple of things I'm struggli ...