Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                #wrapper
  button#restore.material-icons refresh
  #cards
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Song+Myung|Source+Sans+Pro|Material+Icons');

$red: rgb(255, 63, 63);
$yellow: rgb(251, 255, 73);
$blue: rgb(0, 121, 209);

body
{
  margin: 0;
  padding: 1rem;
  height: calc(100vh - 2rem);
  background-color: #0079d1;
}

#restore
{
  position: fixed;
  top: 2rem;
  left: 2rem;
  background-color: $red;
  color: #fff;
  border: 1px solid #999;
  padding: .75rem;
  border-radius: 50%;
  box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

#wrapper
{
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background-color: $yellow;
  #cards
  {
    padding: 1rem;
    .card
    {
      background-color: #fff;
      border-radius: 12px;
      padding-bottom: 1rem;
      width: 40rem;
      margin: auto;
      position: relative;
      margin-bottom: 2rem;
      box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.5);
      
      animation-name: example2;
      animation-duration: 1s;
      animation-fill-mode:forwards; 
      
      .image-wrapper
      {
        width: 100%;
        height: 12rem;
        transition: 1s all;
        position: relative;
        
        .image
        {
          border-top-left-radius: 12px;
          border-top-right-radius: 12px;
          height: 100%;
          background-size: cover;
          background-position: center;
        }
        
        .close
        {
          position: absolute;
          cursor: pointer;
          top: 1rem;
          left: 1rem;
          background-color: rgba(122, 122, 122, .3);
          border-radius: 12px;
          display: inline-block;
          padding: .5rem 1rem;
          text-align: center;
          transition: 1s all;
        }
        
        &:hover
        {
          height: 16rem;
          & > .close
          {
            padding: .5rem 2rem;
            background-color: rgba(122, 122, 122, .4);
          }
        }
        
        .tags
        {
          position: absolute;
          bottom: -.75rem;
          right: .5rem;
          .tag
          {
            display: inline-block;
            cursor: pointer;
            border-radius: 12px;
            padding: .25rem .5rem;
            margin-left: .5rem;
            text-transform: uppercase;
            color: #fff;
            font-family: 'Source Sans Pro', sans-serif;
            font-size: .8rem;
            font-weight: 400;
            &.red
            {
              background-color: $red;
            }
            &.blue
            {
              background-color: $blue;
            }
            &.yellow
            {
              color: #333;
              background-color: $yellow;
            }
          }
        }
      }
      
      .title
      {
        text-transform: uppercase;
        font-family: 'Song Myung', serif;
        font-weight: 700;
        font-size: 1.6rem;
      }
      .content
      {
        height: 4rem;
        overflow: hidden;
        background-color: #fff;
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
        padding: 1rem;
        font-family: 'Source Sans Pro', sans-serif;
        animation: 1s all;
        p
        {
          margin: .5rem 0;
          width: 80%;
        }
        
        button
        {
          position: absolute;
          right: 1rem;
          bottom: 1.5rem;
          background-color: transparent;
          border: 1px solid #999;
          padding: .75rem;
          border-radius: 50%;
          box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.25);
          cursor: pointer;
        }
      }
      
      &.hidden
      {
        animation-name: example;
        animation-duration: 1s;
        animation-fill-mode:forwards; 
      }
      
      &.expanded
      {
        border: 1px solid #dadce0;
        .image-wrapper
        {
          height: 16rem;
        }
        
        .content
        {
          height: auto;
          overflow: visible;
        }
      }
    }
  }
}

@keyframes example {
    from {
      height: 12rem;
    }
    to {
      opacity: 0;
      height: 0;
      display: none;
    }
}

@keyframes example2 {
    from {
      opacity: 0;
      display: none;
    }
    to {
      opacity: 1;
      display: block;
    }
}
              
            
!

JS

              
                var news = [
  {
    id: 1,
    title: 'I went to the beach',
    content: 'It was legen... wait for it... DARY. Legendary. It was legen... wait for it... DARY. Legendary. It was legen... wait for it... DARY. Legendary. It was legen... wait for it... DARY. Legendary.',
    background: 'https://www.pixelstalk.net/wp-content/uploads/2016/03/Roman-Summer-Wallpaper-HD.jpg',
    tags: [
      {
        color: 'blue',
        tag: 'Beach'
      },
      {
        color: 'red',
        tag: 'Trip'
      }
    ]
  },
  {
    id: 2,
    title: 'I went to the big city',
    content: 'I don\'t know which one it was since I got so excited about it that I booked the first flight I saw at the airport',
    background: 'https://images.pexels.com/photos/1139556/pexels-photo-1139556.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
    tags: [
      {
        color: 'red',
        tag: 'Trip'
      }
    ]
  },
  {
    id: 3,
    title: 'I got a new friend',
    content: 'It can even fly, can you believe it!!!',
    background: 'https://images.alphacoders.com/511/thumb-1920-511344.jpg',
    tags: [
      {
        color: 'yellow',
        tag: 'Animals'
      }
    ]
  },
];

$( document ).ready(function() {
    for(var i = 0; i<news.length;i++)
    {
      var card = news[i];
      $('#cards').append(`
        <div class="card" id="card` + card.id + `">
<div class="image-wrapper">
        <div class="image" style="background-image: url(` + card.background + `);"></div>
        <div class="close" data-id="` + card.id + `">
          <div class="icon">
<i class="material-icons">
close
</i>
        </div>
        </div>
        <div class="tags"> 
          ` + getTagsHtml(card.tags) + `
        </div>
      </div>
      <div class="content">
        <div class="title">` + card.title + `</div>
        <p>` + card.content + `</p>
        <button><i class="material-icons">
chevron_right
</i></button>
      </div>
        </div>
      `);
    }
  
  $(".close").click(function(){
    var id = $(this).attr('data-id');
    $("#card" + id).toggleClass('hidden');
  });

  $("button").click(function(){
    $('.card').removeClass('hidden');
    $('.card').removeClass('expanded');
  });
  
  $(".card").click(function(){
    $('.card').removeClass('expanded');
    $(this).addClass('expanded');
  });
});

function getTagsHtml(tags)
{
  var html = '';
  for(var i = 0; i<tags.length;i++)
  {
    var tag = tags[i];
    html = html + '<div class="tag ' + tag.color +'">#' + tag.tag + '</div>';
  }
  
  return html;
}
              
            
!
999px

Console