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

              
                <h4>螢幕解析度</h4>
<div>width: <span class="width"></span>px</div>
<div>height: <span class="height"></span>px</div>

<h4>hw, vh</h4>
<small>裝置長寬/100的px值,是一種會依裝置不同而變動的大小</small>
<p class="vh_description">正在計算你的vh</p>
<p class="vw_description">正在計算你的vw</p>

<div class="vh"></div>
<div class="vw"></div>
              
            
!

CSS

              
                .vh {
 position: absolute;
 right: 0;
 top: 0;
 background-color: rgba(255, 0, 0, .5);
 width: 20vw;
 height: 1vh;
 &::before {
  content: '↑1vh';
  position: absolute;
  top: 100%;
  vertical-align:middle;
 }
}

.vw {
 position: absolute;
 right: 0;
 bottom: 0;
 background-color: rgba(0, 255, 0, .5);
 width: 1vw;
 height: 20vh;
  &::before {
  content: '→\A 1vw';
  position: absolute;
  right: 100%;
  text-align: right;
  white-space: pre-line;  
 }
}
              
            
!

JS

              
                setInterval(show, 1000);

function show() {
  $('.width').html(screen.width);
  $('.height').html(screen.height);
  $('.vh_description').html(`右上角是1vh的高度, 在此裝置上的大小是${screen.width/100}px`)
  $('.vw_description').html(`右下角是1vw的寬度, 在此裝置上的大小是${screen.height/100}px`)
}
              
            
!
999px

Console