Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS columns masonry emulation #108

Open
mhulse opened this issue Jan 13, 2017 · 0 comments
Open

CSS columns masonry emulation #108

mhulse opened this issue Jan 13, 2017 · 0 comments

Comments

@mhulse
Copy link
Owner

mhulse commented Jan 13, 2017

There's this:

http://codepen.io/bradfrost/pen/XpWZGL

/*------------------------------------*\
    #LAYOUT
\*------------------------------------*/


/**
 * Grid object
 * 1) Over-arching grid container
 * 2) Creates overlap effect with content below
 */

.g {
  padding: 0.5rem;
  max-width: 84rem;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: -3rem;
  /* 2 */
}


/**
 * 2-to-3-up masonry grid
 * 1) Creates a Pinterest-style, masonry grid with blocks of varying heights.
 * 2) Set number of columns to display
 */

.g--masonry-2-to3-up {
  column-count: 2;
  /* 2 */
  column-gap: 0;
  @media all and (min-width: 40em) {
    column-count: 3;
    /* 2 */
  }
  @media all and (min-width: 56em) {
    column-count: 4;
    /* 2 */
  }
}


/**
 * Grid item
 * 1) Direct child of the grid container element
 * 2) Prevents content from splitting up because of the 
 *    parent's CSS columns
 */

.g__item {
  padding: 0.5rem;
  -webkit-column-break-inside: avoid;
  /* 2 */
  page-break-inside: avoid;
  break-inside: avoid;
}

The markup:

<div class="g g--masonry-2-to3-up">
  <div class="g__item">
    <div class="block">
      <img src="http://lorempixel.com/g/450/200/" alt="" class="block__img" />
      <h2 class="block__title">Lorem ipsum dolar semet</h2>
    </div><!--end block-->
  </div><!--end g__item-->
  ...
  ...
  ...
</div><!--end g-->

Another explanation:

// By default the contents of the .article remains full width, centred and a maximum of 70ems wide.

.article {
 margin: 1em auto;
  width: 100%;
  padding: 1em;
  max-width: 70em;
}

// When the viewport hits 700px we split the contents into 2 columns and set the gap between the columns at 4% of the width.

@media  (min-width: 700px) {
.article {
    column-count: 2;
    column-gap: 4%;
         }
}

// Then when there is more space, at 1000px, we increase the column count to 3 and decrease the gap to 1%.

@media  (min-width: 1000px) {
.article {
          column-count: 3;
            column-gap: 1%;
         }
}
@mhulse mhulse added the README label Mar 31, 2018
@mhulse mhulse added the Layout label Aug 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant