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

Mini review of the Sonoff B1 WiFi light bulb

Coherence cache performance optimistic vs replicated schemes

Coherence and weblogic.xml in different types of J2EE web app deployments

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

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 3 - broken speaker replacement

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

Atari Lynx repair - Part 1 - introduction and case disassembly

jPhotoFrame updated to version 0.3.1 with an image rotation correction utility

iOS 11 pre-GM mini review before it gets revealed next week

Recent Galleries

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

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

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

Blog Activity

Blog Activity