float
or inline-block
( more info). So I want to share with you great ideas - Justify Grid Framefork.float
, we are faced with the problem of centering the element and we have to carefully specify all the values ​​of the width and indents. Existing Grid frameworks (for example, 960.gs ) certainly solve this problem. But it turns out that the markup is not correct and developers constantly have to use .clearfix. Plus, problems can arise from fractional pixels. If we talk about the inline-block
, the inconvenience appears due to the fact that elements with this value are aligned on the baseline, and not on the upper edge. And if there are several inline-blocks on the page, each of which is located on a new line, then there will be some gaps between them. Any space will affect your layout. The solution is - CSS Grid Layout or Flexible Box Layout , but these solutions are not supported on most browsers. <div class="main"> <h1>Image Gallery</h1> <div class="image"></div> <div class="image"></div> <div class="image"></div> </div>
.main { text-align: justify; font-size: 0; } .main:after { content: ''; display: inline-block; width: 100%; } h1, .image { text-align: left; font-size: medium; } .image { vertical-align: top; display: inline-block; width: 30.3571%; }
$columns: 12 !default; $column-width: 4em !default; $gutter-width: 2.5em !default; %grid { text-align: justify !important; text-justify: distribute-all-lines; font-size: 0 !important; & > * { text-align: left; font-size: medium; } &:after { content: ''; display: inline-block; width: 100%; } } %grid-cell { vertical-align: top; display: inline-block; width: 100%; } @function grid-span($cols, $total: $columns) { @return ($column-width * $cols + $gutter-width * ($cols - 1)) / ($column-width * $total + $gutter-width * ($total - 1)) * 100%; }
Source: https://habr.com/ru/post/182146/
All Articles