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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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 id="naka">naka</div>
<div id="nishi">nishi</div>
<div id="san">san</div>

            
          
!
            
              #naka , #nishi , #san
  height: 50px
  background-color: red
  
#san.hover
  background-color: purple
            
          
!
            
              //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
Loading ..................

Console