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

              
                .wrapper
  section.sw-sec
    h1.sw-title 640*480
    #res1.sw-res(data-w="640", data-h="480")
    
  section.sw-sec
    h1.sw-title 1920*1080
    #res2.sw-res(data-w="1920", data-h="1080")
    
  section.sw-sec
    h1.sw-title 720*480
    #res3.sw-res(data-w="720", data-h="480")
    
    
  section.sw-sec
    h1.sw-title 任意のサイズ
    
    .sw-option
      .sw-option-input
        .sw-option-sec
          span.sw-option-context.x 横:
          input#ratio-w.sw-option-val(type="text", value="1920")
        .sw-option-sec
          span.sw-option-context.y 縦:
          input#ratio-h.sw-option-val(type="text", value="1080")
      .sw-option-result
        button#res-btn.sw-res-btn(type="button") 計算
        #res4.sw-res
    
  
    
  
      
              
            
!

CSS

              
                .wrapper
  padding: 20px
  
.sw
  &-sec
    margin-bottom 2em
  &-title
    font-size 98%
    
  &-option
    &-input
      margin-bottom 20px
    &-sec
      margin-bottom 10px
      &:last-child
        margin-bottom 0
    &-context
      display inline-block
        
  &-res-btn
    cursor pointer
    margin-bottom 20px
    &:focus
      outline: none
  
              
            
!

JS

              
                /**
 * 最大公約数を求める
 */
function gcd(x, y){
  if(y === 0) return x
  return gcd(y, x % y)
 }


/**
 * 予め決めておいたアスペクト比の計算
 */
const arr = ['res1','res2','res3']
for(let i = 0, iLen = arr.length; i < iLen; i++){
  const id = arr[i]
  const res = document.getElementById(id)
  const w = res.dataset.w
  const h = res.dataset.h
  const g = gcd(w,h)
  const ratio_w = w / g
  const ratio_h = h / g
  
  res.innerHTML = `結果:${ratio_w}:${ratio_h}`
}


const btn = document.getElementById('res-btn')
const ops_res = document.getElementById('res4')
const ops_w = document.getElementById('ratio-w')
const ops_h = document.getElementById('ratio-h')


/**
 * 任意に入力したサイズのアスペクト比を計算
 */
btn.addEventListener('click', ()=>{
  const w = ops_w.value - 0
  const h = ops_h.value - 0
  const g = gcd(w,h)
  const x = w / g
  const y = h / g
  
  ops_res.innerHTML = `結果:${x}:${y}`
}, false)








              
            
!
999px

Console