CSS Tricks : Perfect Multi-column Divs It is sometimes frustrating to get perfect columns with CSS and use them in a responsive mobile/tablet design or a liquid desktop design. Consider the following for a 3 column design: CSS
HTML
Result: Column 1
Column 2
Column 3
The Problem: When you try to create any number of percent width columns where they add up to 100% and use margin, the last column always spills onto the next line. Why does this happen? Because the box model calculates the percent of the parent div's width, but does not consider margins or padding in this computation. The Solution: Put each column into it's own container div and give that div the desired width percent, floating, AND 0 margin. Put your margin, padding and other things in the regular .column class. CSS
HTML
Result: Column 1 Column 2 Column 3 Revision History: Nov 4, 2015: .column class must not have a width specified to get perfect width columns. Published by: Thomas Penwell Initially published on: August 8, 2015 Article last modified on: Sunday, August 14, 2016. |
||