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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Avatar List</title>
</head>
<body>
  <section class="container">
 
  <h1>Avatar Male List</h1>
  <ul id="avatar_List"></ul>
     </section>
</body>
</html>
              
            
!

CSS

              
                @bg-color:#f5f5f5;
@list-background:#e3e3e3;
@text-color:#5a5a5a;
@white-bg:#ffffff;
@button-color:#E36D01;
body {
  background: @bg-color;
  .container{
    max-width: 1024px;
    padding: 0 20px;
    margin: 0 auto;
  }
  h1 {
    text-align: center;
    font-family: arial;
    color: #5a5a5a;
  }
 
  ul {
    padding: 0;
    display: flex;
    list-style: none;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
    flex-basis: 80%;
    background: @list-background;
    padding-bottom: 20px;
    li{
      background: @white-bg;
      padding: 15px;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin: 20px 20px 0 0;
       width: 100%;
       margin-left:20px;
      p {
        color: @text-color;
        text-align: center;
        margin: 10px 0 0;
        font-size: 28px;
      }
      img {
        margin: 0;
        border-radius: 100px;
        box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
      }
      .button{
            background: @button-color;
            color: white;
            font-size: 14px;
            padding: 10px 15px;
            display: block;
            margin-top: 8px;
            text-decoration:none;
            transition:0.5s ease 0.5ms;
        &:hover,&:focus{
          opacity:0.8;
          
        }
      }
    }
  }
}

@media only screen and (min-width: 450px) and (max-width: 699px) {
    body{ 
     .container{
         max-width:450px;
          margin: 0 auto;
      }
      ul{      
        li{
             width: 37%;
            margin-right: 20px;
            margin-left: 0;
          
          &:nth-child(2n+2) {
              margin-right: 0px;
            }
          }
       }
    }
}
@media only screen and (min-width: 700px) and (max-width: 1023px) {
 
  body{ 
     .container{
          max-width: 700px;
          margin: 0 auto;
      }
      ul{      
        li{
           width: 25%;
            margin-right: 20px;
            margin-left: 0;
            &:nth-child(3n+3) {
              margin-right: 0px;
            }
          }
       }
    }
}

@media only screen and (min-width: 1024px){
   body{ 
      ul{      
        li{
         width: 19.5%;
          margin-right: 20px;
          margin-left: 20px;
            margin-left: 0;
            &:nth-child(4n+4){
                margin-right:0px;
              }
          }
       }
    }
}
              
            
!

JS

              
                // This can be any valid HTML element: p, article, span, etc... It reduce the coding line

function createNode(element) {
  return document.createElement(element); // Create the type of element you pass in the parameters
}

/* The appendChild() method is used to create a text node as the last child of the node. This method also used to move an element from one element to another element. It is used for creating a new element with some text then first create the text as the text node and then append it to the element, then append the element to the document. */

function append(parent, el) {
  return parent.appendChild(el); // Append the second parameter(element) to the first one
}


const ul = document.getElementById("avatar_List"); // Get the list where we will place our authors
const url = "https://randomuser.me/api/?results=12&gender=male&nat=us"; // Get 12 random male users
fetch(url)  // Call the fetch function passing the url of the API as a parameter
  .then(resp => resp.json()) // Transform the data into json
  .then(function(data) {  
    // We can get the data from the API
  
    let authors = data.results; // Get the results
    return authors.map(function(figure){ 
      
      // Map through the results and for each run the code below
          // Create and append the li's to the ul
        let li = createNode("li"), // Append all our elements
        img = createNode("img"),
        p = createNode("p"),
        div_tag = createNode("div"),
        button_div = createNode("a");
      p.className = "avatar-name";
      button_div.className = "button";
      button_div.innerHTML = 'Call Me';
      button_div.href="javascript:;"
      p.innerHTML = `${figure.name.first}`; // Make the HTML of our p to be the first name of our author
      img.src = figure.picture.medium; // Add the source of the image to be the src of the img element
      append(ul, li);
      append(li, img);  
      append(li, p);    
      append(p, div_tag);
      append(div_tag, button_div);

    });
  })
  .catch(function(error) {
  //where we run the code if the server returns any errors
    console.log(JSON.stringify(error));
  });

              
            
!
999px

Console