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

              
                <div class="card">大家都知道,CSS只是一个声明式的语言,主要为标记语言服务。很多程序员鄙视它,有一部分原因是CSS并不像其他程序语言一样,具有一些逻辑能力以及函数功能等特性。随着CSS的不断变革,其慢慢地也变得越来越强大。</div>
<div class="card">变量对于CSS而言是这两年大家关注的一个话题。对于变量而言,最早是出于CSS的一些处理器语言当中,比如Sass、LESS之类的。随着CSS的发展,变量的概念也被引入到CSS中。</div>
<div class="card">用户界面是最直观的呈现给用户,而其中动画在这方面又扮演着重要的角色。正如@Nick Babich所说:动画将用户界面带入生活。而且,UI动画在用户体验方面也是重要的一环。</div>
<div class="card">今年花了不少的时间在学习DOM相关的知识,经过这段时间的学习,可以通过一些JavaScript的API操作和处理Web页面上的HTML元素。在Web中除了DOM之外还有另外一个对象模型:CSS对象模型(即CSSOM)。</div>
<div class="card">在Web页面或应用程序中都可能会有按钮的出现,甚至很多时候链接的样式看起来也像个按钮。那么我们应该怎么来美化按钮的样式呢?在这篇文章中,我们一起来聊聊按钮样式应该怎么才能更好的控制。</div>
              
            
!

CSS

              
                $gap: .75em;
$r: 50vh;

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
body {
	width: 100vw;
	min-height: 100vh;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	flex-direction: column;
}

.card {
	// 设置数字顺序的关开 --i
	// 当--p有效时,采用--p的值,否则采用回退值0
	--i: var(--p, 0);
	// 当 --i = 0 => --j = 1
	// 当 --i = 1 => --j = 0
	--j: calc(1 - var(--i));
	
	// --i = 0 => 1 - 2 * 0 = 1 - 0 = 1
  // --i = 1 => 1 - 2 * 1 = 1 - 2 = -1
  --s: calc(1 - 2 * var(--i));

  // 给渐变色设置一个自定义属性
  --color-list: #ccc, #f90;
	
	// 圆角半径
	// --i = 0 => --j = 1, --r0 = $r, --r1 = 0
	// --i = 1 => --j = 0, --r0 = 0, --r1 = $r
  // --wide 未显式设置值时 --wide = 0
	// --wide 显式设置值是,将采用设置的值,比如 1
	--k: var(--wide, 0);
	--r0: calc(var(--k) * var(--j) * #{$r});
  --r1: calc(var(--k) * var(--i) * #{$r});
	
	// 宽屏和窄屏的切换
  --k: var(--wide, 0);

    
	
	box-sizing: border-box;
	margin: 2em auto;
	// border: solid 2px #f90;
	padding: .75em;
	max-width: 35rem; 
	width: 80%;
	
	
	counter-increment: count;
	
	display: flex;
  align-items: center;
	
	background: linear-gradient(
		calc(var(--s) * 90deg),
		var(--color-list)
	);
	
	transform: translate(calc(var(--k) * var(--s) * 10%))
               rotate(calc(var(--k) * var(--s) * 5deg));
  flex-direction: var(--wide, column);
  font: 900 calc(var(--k) * .5em + .75em) segoe script, comic sans ms, cursive;
	
	border-radius: var(--r0) var(--r1) var(--r1) var(--r0);
	
	text-align: var(--p, right);
	
	
	&:nth-child(2n) {
		--p: 1;
	}

  &::before {
		font-size: 2em;
  	content: counter(count, decimal-leading-zero);
		// --i等于0,开关关闭,数字的顺序为 order=0
		// --i等于1,开关打开,数字的顺序为 order=1
		order: calc(var(--k) * var(--i));
		
		// 当 --i = 0 => margin-left = 0; --j = 1; margin-right = $gap
		// 当 --i = 1 => margin-left = $gap; --j = 0; margin-right = 0
		margin-left: calc(var(--k) * var(--i) * #{$gap});
    margin-right: calc(var(--k) * var(--j) * #{$gap});
  }
	
	
	@media (min-width: 340px) {
  	--wide: 1
  }
	
}



              
            
!

JS

              
                
              
            
!
999px

Console