Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <script src="https://unpkg.com/vue@next"></script>

<div id="app">
    <!-- ボタンをクリックすると、クラス名が付与される -->
    <button v-bind:class="myClass" v-on:click="addClassName">
      クリックしてね!
    </button>
</div>
              
            
!

CSS

              
                /* 背景を赤にするクラス */
.red {
  background-color: red;
}

/* 背景を青にするクラス */
.blue {
  background-color: blue;
}

/* 背景を黄色にするクラス */
.yellow {
  background-color: yellow;
}

/* 文字色を白にするクラス */
.font-color-white {
  color: white;
}

              
            
!

JS

              
                Vue.createApp({
  data() {
    return {
      // クラス名の初期値は空
      myClass: "",
    };
  },
  // 関数を記述するオプションオブジェクト
  methods: {
    // 乱数を生成し、その値によって異なるクラス名を付与
    addClassName: function () {
      // 0,1,2のいずれかとなる乱数値を生成
      const randomNumber = Math.floor(Math.random() * 3);

      // 乱数値
      switch (randomNumber) {
        case 0:
          // クラス名に .red を設定
          this.myClass = "red";
          break;

        case 1:
          // クラス名に .blue, font-color-white を設定
          // 【Point】配列形式で渡すと、複数のクラス名を付与できる
          this.myClass = ["blue", "font-color-white"];
          break;

        case 2:
          // クラス名に .yellow を設定
          this.myClass = "yellow";
          break;
      }
    },
  },
}).mount("#app");

              
            
!
999px

Console