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

              
                <div id="naka">naka</div>
<div id="nishi">nishi</div>
<div id="san">san</div>

              
            
!

CSS

              
                #naka , #nishi , #san
  height: 50px
  background-color: red
  
#san.hover
  background-color: purple
              
            
!

JS

              
                //ES5と同じ書き方
var ok1 = function(){
  console.log("ok1");
};

ok1();

//arrow function ()=>を使った書き方
var ok2 = ()=> {
  console.log("ok2");
};

ok2();

//arrow function に引数を用いる書き方
var ok3 = (call) => {
  console.log(call);
};

ok3("ok3");

//引数が一つの場合は()も省略可能
var ok4 = call => {
  console.log(call);
};

ok4("ok4");

//jQueryでCSSを与える書き方
$('#naka').css(
  "background-color","red" 
  );

//ES5でのjQueryの書き方
$('#naka').hover(
  function(){
    $(this).css(
  "background-color","blue");    
  },
  function(){
    $(this).css(
      "background-color","yellow"); 
  }
)

//ES6のarrow functionを使った書き方
//arrow functionを使った場合、thisの挙動が変わるので、thisを修正する。具体的には、ホバーしたjQueryオブジェクトがevent.targetに入っているので、eventを引数として渡して、event.targetにcssを与える。
$('#nishi').hover(
  (event) => {
    $(event.target).css(
  "background-color","green");    
  },
  (event) => {
    $(event.target).css(
      "background-color","red"); 
  }
)

//$().CSSの書き方には2通りある
  //1個だけの場合
  //$('要素').css('プロパティ','値');
  //複数のstyle属性の場合
  //$('要素').css({'プロパティ':'値','プロパティ':'値'});

  //CofeeScriptなら以下でOK
  //$('要素').css 
  //  'プロパティ':'値'
  //  'プロパティ':'値'

//hoverの対象、与えるクラスを変数に入れることでより洗練させた記法
//マウスオーバーした対象に.hoverを与えて、.hoverにCSSでスタイルを記述している
const $hoverTarget = $('#san')
const rolloverClass = 'hover'

$hoverTarget.hover(
  (event) => {
    $(event.target).addClass(rolloverClass);    
  },
  (event) => {
    $(event.target).removeClass(rolloverClass); 
  }
)
              
            
!
999px

Console