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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <body>
    <main id="main"> 
        <div id="fontname" ></div>
        <div id="description"></div>
        <div id="text"></div>
    </main>
    <aside>
            <span>Vælg variabel font:</span><br>
            <select v-model="selected">
                <option v-for="font in fonts" v-bind:value="font.id">
                    {{font.displayname}}
                </option>
            </select>
            <br>
            <div id="fontOptions"></div>
            <label class="switch">
                <input type="checkbox" v-model="fonts[selected].cssItalic">
                <span class="slider round"> </span>
            </label>
            <span style="margin-left:0px">Italic [Font-style: italic]</span>
            <br>
            <label class="switch" style="margin-top:5px;">
                <input type="checkbox" v-model="fonts[selected].cssBold">
                <span class="slider round"> </span>
            </label>
            <span style="margin-left:0px">Bold [Font-weight: 600]</span>
            <pre id="cssbox" ></pre>
            <h2>Justér font</h2>
            <div id="options"></div> 
            <div id="infobox"></div>
            <div id="euromind" style="color:gray;font-family:Graduate; font-size:30px;font-weight:900;margin-top:10px;">EUROMIND.COM</div>
            <div style="font-size:20px;">Code-To-Go</div>
    </aside>
    
     
    
</body>

            
          
!
            
              $darkerBackground: #eee;
$lighterBackground: rgba(255, 255, 255, 0.7);
$switchColor: #2196f3;
$fontColor: #000;

body {
  background-color: $darkerBackground;
}

#fontname {
  font-size: 24px;
  line-height: 1px;
  height: 140px;
  overflow: hidden;
  font-variation-settings: "wght" 100, "wdth" 85;
  --delay: calc((var(--char-index) + 1) * 400ms);
  animation: breathe 6000ms infinite both;
  animation-delay: var(--delay);
  @keyframes breathe {
    0% {
      font-variation-settings: "wght" 10, "wdth" 75;
      font-size: 2vw;
    }
    60% {
      font-variation-settings: "wght" 900, "wdth" 100;
      font-size: 2.5vw;
    }
    100% {
      font-variation-settings: "wght" 10, "wdth" 75;
      font-size: 2vw;
    }
  }
}

main,
aside {
  box-sizing: border-box;
  margin: 1em auto;
  padding: 1em 2em;
  background-color: $lighterBackground;
  border-radius: 0.5em;
}

main {
  margin: 10px;
  display: block;
  flex: 1;
  line-height: 1.2;
  color: $fontColor;
  h2 h3 {
    overflow: hidden;
  }
}

aside {
  font-size: 120%;
  line-height: 1.5;
  width: 270px;
  padding: 0;
  //  background-color: transparent;
  font-family: sans-serif;
  font-size: 75%;
  background-color: $lighterBackground;
  border-radius: 0.5em;
  padding: 1em;
  select {
    font-size: 20px;
    font-weight: 900;
    width: 100%;
    height: 40px;
  }
  input[type="range"] {
    width: calc(100% - 4.3em);
  }
  p > span {
    display: flex;
    justify-content: space-between;
  }
  p > span > span {
    font-size: 100%;
  }
  #cssbox {
    font-size: 12px;
    background-color: $darkerBackground;
    padding: 5px;
  }
  #infobox {
    font-size: 12px;
    background-color: $darkerBackground;
    padding: 8px;
    margin-top: 25px;
  }
}
@media screen and (min-width: 640px) {
  body {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-gap: 20px;
  }
}

.switch {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 17px;
  margin-top: 25px;
  input {
    opacity: 0;
    width: 0;
    height: 0;
    &:checked + .slider {
      background-color: $switchColor;
    }

    &:focus + .slider {
      box-shadow: 0 0 1px $switchColor;
    }

    &:checked + .slider:before {
      -webkit-transform: translateX(13px);
      -ms-transform: translateX(13px);
      transform: translateX(13px);
    }
  }
  .round {
    border-radius: 17px;
    &:before {
      border-radius: 50%;
    }
  }
  .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    -webkit-transition: 0.4s;
    transition: 0.4s;
    &:before {
      position: absolute;
      content: "";
      height: 13px;
      width: 13px;
      left: 2px;
      bottom: 2px;
      background-color: white;
      -webkit-transition: 0.4s;
      transition: 0.4s;
    }
  }
}

            
          
!
            
              var app = new Vue({
    el: 'aside',
    data: data,
    watch: {
        selected: function (val) {
            // Ny font valgt: sæt style og fontinformation
            this.setStyleAndInfo(this.fonts[val], true);
        },
        fonts: {
            handler() {
                // en værdi er ændret i font-panelet. Opdatér style
                this.setStyleAndInfo(this.fonts[this.selected], false);
            },
            deep: true
        }
    },
    
    beforeCreate: function () {
        //Klargør data før binding. Hvis ikke klassiske font-værdier er sat for fonten, så brug dewfault    
        data.fonts.forEach(function (font, idx) {
            if (data.fonts[idx].size == null)  data.fonts[idx].size = data.defaultFontSize;
            if (data.fonts[idx].lineheight == null)  data.fonts[idx].lineheight = data.defaultLineheight;
            if (data.fonts[idx].cssItalic == null)  data.fonts[idx].cssItalic = data.cssItalic;
            if (data.fonts[idx].scssBold == null)  data.fonts[idx].cssBold = data.cssBold;
        });
    },

    created: function () {
        this.loadFonts(); // Load fonte via js   
        this.createFontOptions(); // Søt klassike font-options
        this.createSliders(); // Render range.sliders for alle fonte
        this.setStyleAndInfo(this.fonts[this.selected], true); //opdatér style og font-info
    },
    methods: {
        // Indlæs fonte her, så nye fonte kan tilføjes ved kun at ændre JSON.    
        loadFonts : function() {
            if ("fonts" in document) {
                this.fonts.forEach((font) => {
                let face = new FontFace(font.name, `url("https://cdn.jsdelivr.net/gh/lindsoe/VariableFonts/${font.name}-VF.woff2") format('woff2')`)
                face.load().then(document.fonts.add(face));
                }
              );
            }
        },
        // Sæt range-sliders for klassiske font-options: font-size, line-height            
        createFontOptions: function () {
            fontOptions = ["size", "lineheight"];
            fontOptions.forEach(function (opt) {
                opt = "fonts[selected]." + opt;
                document.getElementById("fontOptions").innerHTML +=
                    `<p>
          <label for="${opt}.name">{{${opt}.displayname}}<span aria-hidden="true">({{${opt}.value}})</span>:</label>
          <span>
                  <span>{{${opt}.min}}</span>
                  <input type="range" v-model="${opt}.value"  v-bind:min="${opt}.min"
                          v-bind:max="${opt}.max" v-bind:step="${opt}.step">
                  <span>{{${opt}.max}}</span>
          </span>
          </p>`;
            });
        },

        //Søt range-sliders for font-variant-settings:
        createSliders: function () {
            let sliders = [];
            this.fonts.forEach(function (font, idx) {
                font.axis.forEach(function (option, idx2) {
                    if (sliders.findIndex(x => x.name == option.name) == -1)
                        sliders.push({ name: option.name, displayname: option.displayname });
                });
            })
            sliders.forEach(function (axis) {
                let axIndex = `fonts[selected].axis.findIndex(x => x.name=='${axis.name}')`;
                let ax = `fonts[selected].axis[${axIndex}]`;
                document.getElementById("options").innerHTML +=
                    `<p v-if="${axIndex} > -1">
              <label for="${axis.name}">${axis.displayname} <span aria-hidden="true">({{${ax}.value}})</span>:</label>
              <span>
                      <span>{{${ax}.min}}</span>
                      <input type="range" v-model="${ax}.value"  v-bind:min="${ax}.min"
                              v-bind:max="${ax}.max" v-bind:step="${ax}.step">
                      <span>{{${ax}.max}}</span>
              </span>
              </p>`;
            });


        },
        //Opdatér style og sæt font-info for den valgte font
        setStyleAndInfo: function (font, reset) {
            document.querySelector('#text').innerHTML = this.text;
                        document.querySelector("#fontname").innerHTML= `<h1>${font.displayname}</h1>` ;
            document.querySelector("#description").innerHTML= `"${font.description}"`;

            let style = `
    font-family:'${font.name}';
    font-size: ${(reset) ? font.size.defaultvalue : font.size.value}px;
    line-height: ${(reset) ? font.lineheight.defaultvalue : font.lineheight.value};
    ${(font.cssItalic) ? "font-style:italic;" : "font-style:normal;"}  
    ${(font.cssBold) ? "font-weight:600;" : "font-weight:normal;"}
    font-variation-settings:  
    `;
            let axisInfo = `${font.axis.length} `;
            font.axis.forEach(function (option, idx) {
                style += 
               `'${option.name}' ${(reset) ? option.defaultvalue : option.value},\n    `;
                axisInfo += `(${option.name}:${option.min}-${option.max}) `;
            });
            
            style = style.replace(/\n\s*\n/g, '\n').replace(/,\n\s{4}$/m, ';');
            document.querySelector('main').setAttribute('style', style);
            style = "#text {" + style + "\n}";
            document.getElementById("cssbox").innerHTML = style;
            document.getElementById("infobox").innerHTML =
                `<b> Filstørrelse: </b>${font.filesize} kb<br>
         <b> Axis: </b> ${axisInfo} <p>
         <b> Designer: </b> ${font.designer}<br>
         <b> Udgiver: </b> ${font.publisher}<br>
         <b> Licens: </b>${font.license}<br>
         <b> Link: </b><a href='${font.urllink}'>${font.urltext}</a>`;
        }
    }
})

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console