Igor's Blog

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

, , , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

NeoOffice Viewer macOS Word Document viewer vs Preview and Microsoft Word

Importance of cleaning the internal fans and heatsinks in a MacBook Pro

Adding an email subscribe feature to your Blog with Blogtrottr

How to remove Google's logo from your G Suite applications

Pedestal fan transformed into a ceiling fan

Testing the Velvet WiFi Hotshot signal strength

Improving slow download speeds on the PS4 and PSN

Add batch image resize functionality to macOS using Automator

Show transfer percentage and speed when copying files in Linux and Bash

So I finally got to try eating some space food

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me on...