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

              
                <ul id="container" class="cf"></ul>

  <script id="ourTemplate" type="text/x-handlebars-template">
    {{#each this}}
    <li class='list-container'>
      <div class="image-container">
        <a href="{{ url }}" target="_blank">
          <img src="{{ image_url }}">
        </a>
      </div>
      <div class="name-container">
        {{ name }}
      </div>
      <div class='role-container'>{{{ role }}}</div>
    </li>
    {{/each}}
  </script>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
.cf:before,
.cf:after {
    content: " ";
    display: table;
}

.cf:after {
    clear: both;
}
body {
  margin: 0;
  padding: 0;
}
ul#container {
  width: 100%;
  margin: 0 0 20px 0;
  list-style-type: none;
  padding: 0;
  background-color: #C9E4E7;
}
li.list-container {
  float: left;
  width: 100%;
  height: 200px;
  text-align: center;
  outline: 1px solid #ccc;
  padding: 10px;
}
.image-container {
  display: block;
  margin: 10px auto;
  height: 90px;
}
.image-container img {
  max-width: 12%;
  margin-top: 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid #fff;
}
.image-container a {
  color: #6D92AD;
  text-decoration: none;
}
.role-container {
  font-weight: bold;
  margin: 8px 0 0;
  color: #776D5A;
}

@media (min-width: 32em) and (max-width: 45.562em) {
  li.list-container {
    width: 50%;
  }
}

/*  Tablet View  */
@media (min-width: 45.563em) and (max-width: 61.312em) {
  li.list-container {
    width: 33.333%;
  }
}


/*  Desktop View  */
@media (min-width: 61.313em) {
  li.list-container {
    width: 25%;
  }
}
              
            
!

JS

              
                const url = 'https://api.jikan.moe/anime/1/characters_staff';

fetch(url)
.then(function(response) {
  if (!response.ok) {
    throw Error(response.statusText);
  }
  // Read the response as json.
  return response.json();
})
.then(function(data) { 
  // Do stuff with the JSON
  console.log(data);
  createHtml(data.staff); // The trick here was adding staff to the data
})
.catch(function(error) {
  console.log('Looks like there was a problem: \n', error);
});


// Function to generate the HTML
function createHtml(ourData) { // ourData is just a parameter and can be named anything
  let rawTemplate = document.querySelector("#ourTemplate").innerHTML;
  let compiledTemplate = Handlebars.compile(rawTemplate);
  let ourGeneratedHTML = compiledTemplate(ourData);
  
  let ourContainer = document.querySelector("#container");
  ourContainer.innerHTML = ourGeneratedHTML;
}





              
            
!
999px

Console