cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="wrapper">
  <div class="main">
    <h1>Dynamic Flag</h1>
    <small></small>
    <span class="flag-icon"></span>
    <small><span class="dynamic-text"></span></small>
  </div>
  <aside>
    <h3>Top 3</h3>
    <span class="flag-icon first"></span>
    <small>Australia</small>
    <span class="flag-icon second"></span>
    <small>South Korea</small>
    <span class="flag-icon third"></span>
    <small>Honduras</small> 
  </aside>
</div>
            
          
!
            
              $countries: algeria argentina australia belgium bosnia brazil cameroon chile columbia costa_rica croatia ecuador england france germany ghana greece holland honduras iran italy ivory_coast japan mexico nigeria portugal russia south_korea spain switzerland united_states uruguay;

@mixin flag($chosen-country, $height) {
  $width: floor($height / 0.66);
  $newHeight: $width * 0.66;
  $spriteHeight: $width * 0.7;

  width: $width;
  height: $newHeight;

  @each $country in $countries {
    $i: index($countries, $country);
    $background-position: -($spriteHeight * ($i - 1));

    @if $chosen-country == $country {
      background-position: 0 $background-position;
    } 
    @else if $chosen-country == "all" {
      &.#{$country} {
        background-position: 0 $background-position;
      }
    }
  }
}


.flag-icon {
  background: url('https://matthewshields.co.uk/wordpress/wp-content/themes/me/img/flag-sprite.svg');
  background-repeat: no-repeat;
  background-size: 100% auto;
  display: inline-block;
}

.main .flag-icon {
  @include flag(all, 275px);
}

aside .first {
  @include flag(australia, 80px);
}

aside .second {
  @include flag(south_korea, 80px);
}

aside .third { 
  @include flag(honduras, 80px); 
}




 





body {
  background: #f1f1f1;
  text-align: center;
}

.wrapper { 
  width: 620px;
  margin: 0 auto; 
}

.main {
  width: 440px;
  float: left;
  background: #ccc;
}

aside {
  width: 150px;
  float: right;
  background: #aaa;
}

small {
  margin-bottom: 10px;
  display: block;
}
            
          
!
            
              $(document).ready(function(){
    var classes = ["algeria", "argentina", "australia", "belgium", "bosnia", "brazil", "cameroon", "chile", "columbia", "costa_rica", "croatia", "ecuador", "england", "france", "germany", "ghana", "greece", "holland", "honduras", "iran", "italy", "ivory_coast", "japan", "mexico", "nigeria", "portugal", "russia", "south_korea", "spain", "switzerland", "united_states", "uruguay"];

    $(".main .flag-icon").each(function(){
        var random = classes[~~(Math.random()*classes.length)];
        $('.main .flag-icon').addClass(random);
        $('.dynamic-text').text(random);
    });
});
            
          
!
999px
Loading ..................

Console