Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
// The numbers are Unsplash It picture IDs
- var pics = [
-     1, 20,  635, 42,
-   180, 625, 201,  7,
-    48, 180, 534,  24
- ]


// Loop all pictures and print checkboxes and lightboxes for them
- var pic_id = 0
- each pic in pics
  - pic_id++

  input(type="checkbox", id="pic-#{pic_id}")
  label.lightbox(for="pic-#{pic_id}")
    img(src="//unsplash.it/800/600?image=#{pic}")


.grid
  // Loop all pictures and print the actual images
  - var pic_id = 0
  - each pic in pics
    - pic_id++

    label.grid-item(for="pic-#{pic_id}")
      img(src="//unsplash.it/400/300?image=#{pic}")

              
            
!

CSS

              
                
// CHANGELOG
// 2014/12/21 Created the pen
// 2015/01/14 Cleaned the code and documented it
// 2015/05/27 Switched missing picture to a working one, changed couple of pictures to match the color scheme better and made some small changes to the code


// NOTES
// * I'm using Autoprefixer and haven't prefixed styles because of that



//============
// MIXINS

// Mixin for breakpoints
@mixin breakpoint($max-width) {
  @media screen and (max-width: $max-width) {
    @content;
  }
}



//============
// ELEMENTS

// Set box-sizing to border-box for all elements
*,
*:before,
*:after {
  box-sizing: border-box;
}


// Set cursor to pointer for labels that have 'for' attribute
label[for] {
	cursor: pointer;
}


// Hide checkboxes. They're triggered through labels
input[type="checkbox"] {
	display: none;
}


// When toggling lightbox grid's opacity will lower and body's black background color will make a fading element
body {
	background-color: #000;
}


// Containers
%container {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
}


// Lightboxes
// Hiding lightboxes happens by setting their scale to 0. This way it's possible to create animated transition when showing them
.lightbox {
  @extend %container;
  
  z-index: 1;
  min-height: 100%;
  overflow: auto;
  transform: scale(0);
  transition: transform .5s ease-out;
  
  img {
    position: fixed;
    top: 50%;
    left: 50%;
    max-width: 96%;
    max-height: 96%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
  }
}


// Set lightboxes scale to 1 when opening lightbox. Read more above
input[type="checkbox"]:checked + .lightbox {
  transform: scale(1);
}


// Reduce grid's opacity when opening lightbox. Read more above
input[type="checkbox"]:checked ~ .grid {
  opacity: .125;
}


// The grid of images
.grid {
  @extend %container;
  
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  height: 100%;
  padding: 16px;
  overflow: auto;
  z-index: 0;
  background-color: #222;
  text-align: center;
  transition: opacity .75s;
  
  .grid-item {
		display: block;
    width: 25%;
    padding: 16px;
    opacity: .75;
    transition: opacity .5s;
  
    &:hover {
			opacity: 1;
		}
    
		@include breakpoint(1280px)	{ width: 33.3333%; }
    @include breakpoint(960px)	{ width: 50%; }
    @include breakpoint(480px)	{ width: 100%; }
  }
  
  img {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console