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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="container">
  <h1> Wikipedia Viewer </h1>
  
 
  <button id="random" type="button">Random Article</button>
  <input id="search" type="text" name="search" placeholder="Search - Type & Press Enter">
  <br>
  <div id="content">
    
    
  </div>
  

  
</div> 
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Yrsa');

body{
  background-color: #ed6753;
}

h1{
  font-family: 'Yrsa',serif;
  color: white;
  text-align: center;
}
#random{
  display: block;
  margin: 20vh auto 0;
  border-radius: 6px;
  font-family: 'Yrsa',serif;
  font-size: 25px;
  color: white;
}

input[type="text"]{
  margin: 2vh auto 0;
  background-image: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-128.png'); 
  background-position: 96% 5px; 
  background-repeat: no-repeat;
  padding: 0px 40px 0px 10px;
  background-size: 25px 25px;
  width: 300px;
  border-radius: 6px;
  transition: width 1s;
  transition: transform 1s;
}

input[type="text"]:focus{
  width: 500px;
  transition: width 1s;
  transition: transform 1s;
  
}

.moveup{
  transform: translate(0,-20vh);
  transition: transform 1s;
  
  
}

.gray{
  width:95%;
  height:150px;
  background-color:#ffffff;
  margin: 0 auto;
  padding: 20px;
  color: #4c4c4c;
  border-radius: 5px;
}

              
            
!

JS

              
                $("#random").click(function() {
  window.open("https://en.wikipedia.org/wiki/Special:Random");;
}) // Random Article Page Button


//Detects if the Enter Key is Pressed, Most likely pressed when typed something in search box

$(document).keypress(function(e) {
  if (e.which == 13 && document.getElementById("search").value.length != 0) { // checks if the key pressed is enter
    $("#search").addClass("moveup"); //moveup class adds a smooth transition effect
    $("#random").addClass("moveup");
    content = document.getElementById("search").value; //Sets the content variable to what is inside search box

    var url = "https://en.wikipedia.org/w/api.php?callback=?&action=opensearch&search=" + content + "&format=json" // URL for JSON API

    $.getJSON(url).done(function(data) { // Gets JSON data from wikipedia API

      var contenthtml = ""; // For Adding the boxes
      for (var i = 0; i < data[1].length; i++) { // For loop for adding boxes, more convinient than typing divs for all the result boxes
        var title = data[1][i];
        var abstract = data[2][i];

        contenthtml += "<br><div class=gray><h5><b><a href='https://en.wikipedia.org/wiki/" + title + "' target = _blank>" + title + "</a></b></h5><br><p> " + abstract + "</p></div><br>";
        

      }

      $('#content').html(contenthtml); // Sets the content Html to id content 

      if (data[1].length === 0) { // Length is 0, when user types in something invalid, as the API returns nothing
        $('#content').html("<div class='gray'><h5 style='text-align:center;'> You typed in something Invalid. <h5></div>"); // Box for telling user that it's an error

      }

    }).fail(function() {
      console.log("<div class='gray'><h5 style='text-align:center;'> Error retrieving data from server, Try Again Later <h5></div>"); //Incase there's an error with the server 
    });

  }
});
              
            
!
999px

Console