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

              
                <div class="wrapper">
  <div id="heading">
    <h1>Wikipedia Viewer</h1></div>
  <div id="bg">
    <div id="search-wrapper">
      <input id="input" type="text" name="searchtxt" placeholder="search wikipedia" autocomplete="on">
      <button id="searchBtn"><i class="fa fa-search" aria-hidden="true"></i>
</button>
      <button id="ran-art-btn"><a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">View Random article</a></button>
    </div>

  </div>
  <div class="content-area">
    <div class="search-results"></div>
  </div>
</div>
<footer>
  <div>
    <p>Designed and code by <a href="ishekahonde.github.io" target="_blank">Ishe</a>
  </div>
</footer>
              
            
!

CSS

              
                html, body {
  height: 100%;
  font-family: 'Roboto', sans-serif;
}
.wrapper {
  display: flex;
  flex-flow: column wrap;
}
#heading {
  text-align: center;
}
#bg {
  height: 150px;
  background: url('https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1200px-Wikipedia-logo-v2.svg.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: 50%;
}
#search-wrapper {
  display: flex;
  flex-flow: row wrap;
  margin: 0 auto;
  justify-content: center;
}
.content-area {
  background: rgb(214, 202, 182);
  background: rgba(214, 202, 182, 0.3);
}
#input {
  border-radius: 2px;
  border: 3px solid orange;
  background: rgb(214, 202, 182);
  background: rgba(214, 202, 182, 0.3);
  padding: 2px;
  font-size: 20px;
}
#input:focus {
  outline: none;
}
#ran-art-btn {
  font-size: 1em;
  border-radius: 2px;
  border: 2px solid black;
  padding: 5px;
  height: 40px;
}
#searchBtn {
  color: black;
  position: relative;
  right: 34px;
  top: 2px;
  font-size: 1.2em;
  margin: 1px;
  border-radius: 2px;
  background: transparent;
  border: none;
  padding: 5px;
  height: 35px;
}
#ran-art-btn > a {
  text-decoration: none;
  color: black;
}
#searchBtn:focus {
  outline: none;
}
#searchBtn:hover {
  cursor: pointer;
  background: transparent;
}
.snippets {
  margin: 7px auto;
  width: 80%;
  padding: 15px;
  border: 0.5px solid grey;
  border-radius: 2px;
  background: white;
}
.snippets:hover {
  box-shadow: 1px 2px 1px 1px rgba(198, 194, 194, .8),
    1px 2px 1px 1px rgba(198, 194, 194, .8);
}
.wikilinks {
  text-decoration: none;
  font-weight: 500;
  font-size: 1.2em;
}
footer > div > p {
  text-align: center;
}
@media screen and (max-width: 340px) {
  #ran-art-btn {
    font-size: 0.85em;
    position: relative;
    top: 10px;
  }
  #searchBtn {
    position: relative;
    top: -37px;
    left: 170px;
  }
}

              
            
!

JS

              
                $(document).ready(function() {
  var isClicked = false;
  var searchText;
  $("#input").on("keyup", function(e) {
    searchText = $("#input").val();
  });
  var htmlStr;
  $("#searchBtn").on("click", function() {
    $.ajax({
      type: "GET",
      url:
        "https://en.wikipedia.org/w/api.php?action=query&format=json&indexpageids=&prop=extracts&exintro&gsrlimit=15&generator=search&origin=*&gsrsearch=" +
          searchText,
      success: function(data) {
        var dataWe = JSON.stringify(data);
        var myArray = data.query.pageids;
        myArray.forEach(function(arrItem) {
          var idName = data.query.pages[arrItem].title;
          var pageExtr = data.query.pages[arrItem].extract;
          var wikiUrl = "https://en.wikipedia.org/?curid=" + arrItem;
          console.log(pageExtr);
          htmlStr =
            '<div class="snippets">' +
            "<a target='_blank' class='wikilinks' href=" +
            wikiUrl +
            ">" +
            idName +
            "</a>" +
            "<p>" +
            pageExtr.slice(0, 200) +
            "..." +
            "</p>" +
            "</div>";
          $(".search-results").append(htmlStr);
          isClicked = true;
        });
      }
    });
  });
  $("#input").keydown(function(event) {
    if (event.keyCode == 13) {
      $("#searchBtn").click();
      isClicked = true;
    }
    if (isClicked == true) {
      $("#input").keypress(function() {
        $(".search-results").empty();
      });
    }
    $("#input").keydown(function(e) {
      if (e.keyCode == 8) {
        $(".search-results").empty();
      }
    });
  });
});

              
            
!
999px

Console