Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've finally finished working on the Projects section of my blog and wanted to share the CSS and HTML I used to make it happen. I wanted to achieve the look that Pinterest uses for it's pins pages, where the pins flow down the page. I wanted to allow each pin to be of a different height and not to force other pins to align to it's top/bottom i.e. the gaps between pins should be constant and one pin could span the height of multiple other pins without interference of their layout.

This was the end result...
pinterest_columns1.jpg


The CSS/HTML I had to use is a bit messy due to the Blog software I'm using so I put together a simple stand-alone example here: https://github.com/ikromin/misc/blob/master/html/pinterest_columns.html.

Lets look at some HTML.
 HTML
<div class="columns">
<div class="pin">
<div class="pin_content">First pin content</div>
</div>
<div class="pin">
<div class="pin_content">Second pin content</div>
</div>
</div>


That's pretty straight forward, just a wrapper DIV with class 'columns', this ensures that the content inside is split into columns. Then I have a DIV for each of the 'pins'. The nested DIV with class 'pin_content' is where the actual text/images/etc goes.



The complimentary CSS for the above is:
 CSS
.columns {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-fill: auto;
-moz-column-fill: auto;
column-fill: auto;
}
.pin {
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
column-break-inside: avoid;
padding-bottom: 1em;
}
.pin_content {
background-color: #ccc;
padding: 0.5em;
}


Also fairly straight forward. The 'columns' class is set up to split its content into 3 columns and fill them automatically without trying to balance their heights. I noticed this doesn't work very well with just 4 pins, but other combinations of pins looked ok.

The 'pin' class makes sure the content inside it is not split across columns and adds padding at the bottom, this is what creates the vertical gap between pins. For some reason I noticed that adding a bottom-margin to this class made things look odd, hence the padding and a nested DIV. The 'pin_content' class can be styled any way desired, I just added a background colour and some padding.


From my example on Github, using column layout produces this...
pinterest_columns2.jpg


Meanwhile if I remove the 'column' class, I get this...
pinterest_columns3.jpg


Pretty cool! Don't forget to check out the page that inspired this post - My current and past projects.

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

WebLogic Maven Plugin - How to fix the MojoExecutionException: The artifact location was not specified

jPhotoFrame version 0.4 released with a whole new layout engine

Upcycling a couple of old broken lamps to create something amazing

A custom exception mapper and writer for a RESTful JAX-RS Jersey service

How to fix Plex error - Sorry there was a problem playing this item

Jersey JAX-RS filters and interceptors execution order for a POST request

Fix your Mac - users not showing on the macOS login screen when FileVault is enabled

BMB-012 Nanoblock T-Rex Skeleton Model assembly

Writing a custom MessageBodyReader to process POST body data with Jersey

How to make Skype for Business responsive again on macOS

Recent Galleries

BMB-012 Nanoblock T-Rex Skeleton Model assembly

Tiny Arcade revision 6 kit assembly and decal application

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity