HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
$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
}
}
Also see: Tab Triggers