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

              
                <body>

  <main>

    <nav>

      <div class="country-search">
        <input type="text" placeholder="Search country" autocomplete="off" v-model="search">
      </div>

      <div class="country-list">

        <div class="country" v-for="country in countries" @click="selectCountry(country)">
          <img :src="getFlagSrc(country)">
          {{ getName(country) }}
        </div>

      </div>

    </nav>

    <section :style="{ 'background-image': 'url(' + selectedFlagSrc + ')' }">

      <div class="card-container">
        <div class="card">

          <div class="card-title">
            <img :src="selectedFlagSrc">
            {{ selectedName }}
          </div>

          <div class="card-body">
            <div><strong>Code: </strong>{{ selectedCode }}</div>
            <div><strong>Capital: </strong>{{ selectedCapital }}</div>
            <div><strong>Region: </strong>{{ selectedSubregion }}</div>
            <!--<div><strong>Timezone: </strong>{{ selectedTimezone }}</div>-->
            <div><strong>Language: </strong>{{ selectedLanguage }}</div>
            <div><strong>Population: </strong>{{ selectedPopulation }}</div>
            <div><strong>Area: </strong>{{ selectedArea }}</div>
            <div><strong>Currency: </strong>{{ selectedCurrency }}</div>
            <div><strong>World Bank Gini: </strong>{{ selectedGini }}</div>
            <div><strong>Lat Long: </strong><a :href="selectedLatlngUrl" target="_blank">{{ selectedLatlng }}</a></div>
          </div>

        </div>
      </div>

    </section>

  </main>

  <footer>
    Made with <a href="https://restcountries.eu/" target="_blank">REST Countries API</a> and Vue.js
  </footer>

</body>
              
            
!

CSS

              
                $footer_background: rgb(50, 50, 50);
$footer_color: white;

$main_background: rgb(50, 50, 50);

$nav_width: 450px;
$nav_width_medium: 270px;
$nav_width_small: 180px;
$nav_background: white;
$nav_shadow: 0px 5px 25px 0px rgba(0, 0, 0, .75);
$nav_img_width: 70px;
$nav_img_radius: 5px;
$nav_img_shadow: 0px 0px 10px 3px rgba(0, 0, 0, .25);

$card_background: white;
$card_radius: 10px;
$card_shadow: 0px 5px 25px 0px rgba(0, 0, 0, .75);
$card_img_width: 70px;
$card_img_radius: 5px;
$card_img_shadow: 0px 0px 10px 3px rgba(0, 0, 0, .25);

$global_gap: 20px;

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

* {
  font-size: inherit;
  font-family: inherit;
  color: inherit;

  &:focus {
    outline: none;
  }
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Nunito', sans-serif;
  font-size: calc(.4em + .6vw);
  margin: 0;
  background: white;

  display: flex;
  flex-direction: column;

  main {
    flex: 1 1 auto;

    display: flex;
    flex-direction: row;
    
    overflow: hidden;

    background: $main_background;

    nav {
      flex: 0 0 auto;
      width: $nav_width;

      display: flex;
      flex-direction: column;
      
      overflow: auto;

      background: $nav_background;
      box-shadow: $nav_shadow;
      z-index: 1;

      .country-search {
        flex: 0 0 auto;

        display: flex;

        padding: $global_gap;

        input {
          width: 100%;
          padding: ($global_gap / 2) $global_gap;
          border: 2px solid rgb(100, 100, 100);
          border-radius: 100px;
          transition: border-color .2s ease-out;

          &:hover, &:focus {
            border-color: rgb(30, 30, 30);
          }
        }
      }

      .country-list {
        flex: 1 1 auto;
        overflow-y: auto;

        .country {
          display: flex;
          flex-direction: row;
          align-items: center;

          padding: ($global_gap / 2) $global_gap;
          font-weight: bold;
          cursor: pointer;

          &:hover {
            background-color: rgba(0, 0, 0, .15);
          }

          img {
            width: $nav_img_width;
            height: auto;
            margin-right: $global_gap;
            border-radius: $nav_img_radius;
            box-shadow: $nav_img_shadow;
          }
        }
      }
    }

    section {
      flex: 1 1 auto;

      display: flex;

      background: no-repeat center;
      background-size: cover;

      &:after {
        position: absolute;
        top: 0; bottom: 0; right: 0; left: 0;
        content: "";
        background-color: rgba(0, 0, 0, .5);
      }

      .card-container {
        flex: 1 1 auto;

        display: flex;
        justify-content: center;
        align-items: start;

        overflow-y: auto;
        z-index: 1;

        .card {
          margin: $global_gap ($global_gap / 2);
          margin-bottom: 0;
          border-radius: $card_radius;
          background: $card_background;
          box-shadow: $card_shadow;

          .card-title {
            display: flex;
            flex-direction: row;
            align-items: center;

            padding: $global_gap;
            font-weight: bold;

            img {
              width: $card_img_width;
              height: auto;
              margin-right: $global_gap;
              border-radius: $card_img_radius;
              box-shadow: $card_img_shadow;
            }
          }

          .card-body {
            display: flex;
            flex-direction: column;

            padding: 0 $global_gap;

            div {
              margin-bottom: $global_gap;
            }
          }
        }
      }
    }
  }

  footer {
    flex: 0 0 auto;

    z-index: 1;

    background: $footer_background;
    color: $footer_color;
    text-align: center;
    padding: $global_gap / 2;
  }
}

@media screen and (max-width: 1000px) {
  nav {
    width: $nav_width_medium !important;
    
    img {
      width: $nav_img_width / 1.5 !important;
    }
  }
  section img {
      width: $nav_img_width / 1.5 !important;
  }
}

@media screen and (max-width: 700px) {
  nav {
    width: $nav_width_small !important;
    
    img {
      display: none;
    }
  }
}
              
            
!

JS

              
                // Format a nuber with suffix letter
function formatNumber(labelValue) {
  return Math.abs(Number(labelValue)) >= 1.0e+9
    ? Math.abs(Number(labelValue)) / 1.0e+9 + "B"
  : Math.abs(Number(labelValue)) >= 1.0e+6
    ? Math.abs(Number(labelValue)) / 1.0e+6 + "M"
  : Math.abs(Number(labelValue)) >= 1.0e+3
    ? Math.abs(Number(labelValue)) / 1.0e+3 + "K"
  : Math.abs(Number(labelValue));
}

var vm = new Vue({
  el: 'main',

  data: {
    search: '',
    selectedName: '',
    selectedCode: '',
    selectedCapital: '',
    selectedLanguage: '',
    selectedCurrency: '',
    selectedLatlng: '',
    selectedLatlngUrl: '',
    selectedPopulation: '',
    selectedArea: '',
    selectedSubregion: '',
    selectedGini: '',
    selectedTimezone: '',
    selectedFlagSrc: '',
  },

  computed: {
    countries () {
      var self = this;
      var countries;

      // Get JSON from API
      $.ajax({
        url: 'https://restcountries.eu/rest/v2/all',
        async: false,
        success: function(data){
          countries = data;
        }
      });

      // Filter search by country name in all languages
      countries = countries.filter(function(value, index, array) {
        return value['name'].toLowerCase().includes(self.search.toLowerCase())
        || Object.values(value['translations']).join(' ').toLowerCase().includes(self.search.toLowerCase());
      });

      return countries;
    },
  },

  // Select first country in list on load
  beforeMount() {
    var self = this;
    var found = false;
    this.countries.forEach(function(element) {
      if(element['alpha2Code'] === 'US') {
        self.selectCountry(element);
        found = true;
      }
    });
    if(!found)
        this.selectCountry(this.countries[0]);
  },

  methods: {
    // Returns country name
    getName (country) {
      return country['name'];
    },

    // Returns country flag URL
    getFlagSrc (country) {
      return (country['flag'] || 'N/A');
    },

    // Set country data
    selectCountry (country) {
      var self = this;

      $('section').animate({
        opacity: 0
      }, 150, function() {

        self.selectedName = (country['name'] || 'N/A');
        self.selectedFlagSrc = self.getFlagSrc(country);
        self.selectedCode = (country['alpha2Code'] || 'N/A') + ' / ' + (country['alpha3Code'] || 'N/A');
        self.selectedCapital = (country['capital'] || 'N/A');

        var arrayLanguage = [];
        country['languages'].forEach(function(element) {
          arrayLanguage.push(element['name']);
        });
        self.selectedLanguage = (country['languages'].length > 0) ? arrayLanguage.join(', ') : 'N/A';

        var arrayCurrency = [];
        country['currencies'].forEach(function(element) {
          arrayCurrency.push(element['name'] + ' ' + element['symbol']);
        });
        self.selectedCurrency = (country['currencies'].length > 0) ? arrayCurrency.join(', ') : 'N/A';

        self.selectedLatlng = (country['latlng'].length > 0) ? ('Lat: ' + country['latlng'][0] + ', Lng: ' + country['latlng'][1]) : 'N/A';
        self.selectedLatlngUrl = (country['latlng'].length > 0) ? ('https://www.google.com/maps/?q=' + country['latlng'][0] + ',' + country['latlng'][1]) : '';
        self.selectedPopulation = country['population'] ? formatNumber(country['population']) : 'N/A';
        self.selectedArea = country['area'] ? (formatNumber(country['area']) + ' km²') : 'N/A';
        self.selectedSubregion = (country['subregion'] || 'N/A');
        self.selectedGini = country['gini'] ? (country['gini'] + '%') : 'N/A';
        self.selectedTimezone = (country['timezones'].length > 0) ? country['timezones'].join(', ') : 'N/A';

        $('section').animate({
          opacity: 1
        });
      });
    },
  }
});
              
            
!
999px

Console