{"id":8345,"date":"2016-07-08T13:53:22","date_gmt":"2016-07-08T12:53:22","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=8345"},"modified":"2016-07-08T14:14:19","modified_gmt":"2016-07-08T13:14:19","slug":"arrange-divs-by-row-while-aligning-them-vertically","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2016\/07\/arrange-divs-by-row-while-aligning-them-vertically\/","title":{"rendered":"Arrange divs by row while aligning them vertically?"},"content":{"rendered":"<p>Seems there is a real problem ;-) even with valuable <a href=\"stackoverflow.com\/questions\/28681572\/horizontal-masonry-layout-with-flexbox-css-only\">SO<\/a> comments at hand. In the first instance I tried to float all divs. But even when clearing floats this always left a vertical gap. In a second attempt, I used a table but this wasn&#8217;t really responsive design. Next, I tried CSS3 multi-column layout<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#container {\r\n    margin: 0 auto; \r\n    column-count: 3;\r\n    column-gap: 2px;\r\n    width: 320px;\r\n    background-color: white;\r\n}\r\n<\/pre>\n<p>This works as expected\u00a0(<a href=\"https:\/\/jsfiddle.net\/wcXRk\/439\/\">jsfiddle<\/a>).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8347 aligncenter\" src=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2016\/07\/screen.jpg\" alt=\"screen\" width=\"330\" height=\"322\" \/><\/p>\n<p>and could be even responsive when adding some code for smaller screens<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n@media screen and (max-width: 1450px) {\r\n  #inner {\r\n    max-width:950px;\r\n    margin: 0 auto;\r\n    -moz-column-count: 2;\r\n    -webkit-column-count: 2;\r\n    column-count: 2;\r\n  }\r\n}\r\n@media screen and (max-width: 950px) {\r\n  #inner {\r\n    max-width:480px;\r\n    margin: 0 auto;\r\n    -moz-column-count: 1;\r\n    -webkit-column-count: 1;\r\n    column-count: 1;\r\n  }\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/jsfiddle.net\/wcXRk\/432\/\">jsfiddle<\/a> looks great but we are soon running into another problem. Whenever adding more divs as the database is updated, the whole layout gets re-arranged column-wise which is very confusing to the viewer. The same happens with flexbox (attempt #4), currently there is no CSS solution at all. You need some JS layout cheating<\/a> (<a href=\"http:\/\/codepen.io\/desandro\/pen\/nhekz\">codepen<\/a>).<\/p>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 08.04.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>Seems there is a real problem ;-) even with valuable SO comments at hand. In the first instance I tried to float all divs. But even when clearing floats this always left a vertical gap. In a second attempt, I used a table but this wasn&#8217;t really responsive design. Next, I tried CSS3 multi-column layout &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2016\/07\/arrange-divs-by-row-while-aligning-them-vertically\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arrange divs by row while aligning them vertically?<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-8345","post","type-post","status-publish","format-standard","hentry","category-computer-software"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=8345"}],"version-history":[{"count":10,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8345\/revisions"}],"predecessor-version":[{"id":8356,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8345\/revisions\/8356"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=8345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=8345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=8345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}