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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<form action="" class="change" data-action="alcohol">
<ul class="list">
<li class="item">
<label>
<input name="view" type="radio" value="">
<span class="title">Без класса</span>
</label>
</li>
<li class="item">
<label>
<input name="view" type="radio" value="color" checked>
<span class="title">color</span>
</label>
</li>
<li class="item">
<label>
<input name="view" type="radio" value="color image" checked>
<span class="title">color image</span>
</label>
</li>
<li class="item">
<label>
<input name="view" type="radio" value="color image outside">
<span class="title">color image outside</span>
</label>
</li>
<li class="item">
<label>
<input name="view" type="radio" value="text">
<span class="title">text</span>
</label>
</li>
<li class="item">
<label>
<input name="view" type="radio" value="color text">
<span class="title">color text</span>
</label>
</li>
</ul>
</form>
<div class="card">
<form action="" class="main" data-class="main" data-container="alcohol">
<ul class="list">
<li class="item">
<label>
<input name="skills" type="checkbox" value="1" checked disabled>
<span class="title" data-checked="Заказан" data-unchecked="Хочу">Виски</span>
<svg class="picture whiskey" viewBox="0 0 114 154">
<path d="m 25.8,143.4 70.43,0 1,-20 -72.63,0 z"/>
</svg>
</label>
</li>
<li class="item">
<label>
<input name="skills" type="checkbox" value="2" checked disabled>
<span class="title" data-checked="Заказана" data-unchecked="Хочу">Кола</span>
<svg class="picture cola" viewBox="0 0 114 154">
<path d="m 22.44,83.45 76.79,0 -2,39.95 -72.66,0 z"/>
</svg>
</label>
</li>
<li class="item">
<label>
<input name="skills" type="checkbox" value="3">
<span class="title" data-checked="Заказан" data-unchecked="Хочу">Лёд</span>
<svg class="picture ice" viewBox="0 0 114 154">
<rect class="cube left" width="20" height="20" ry="3" x="30" y="75"/>
<rect class="cube center" width="14" height="14" ry="2" x="50" y="80"/>
<rect class="cube right" width="20" height="20" ry="3" x="73" y="75"/>
</svg>
</label>
</li>
<li class="item">
<label>
<input name="skills" type="checkbox" value="4">
<span class="title" data-checked="Заказан" data-unchecked="Хочу">Лайм</span>
<svg class="picture lime" viewBox="0 0 114 154">
<circle class="skin" cx="22.5" cy="53.4" r="20"/>
<path class="slices" d="m 35.43,66.45 c -3.41,3.4 -7.9,5.3 -12.56,5.4 l -0.15,-18 z m 5.59,-13 c 0,4.8 -1.94,9.2 -5.22,12.6 L 23.08,53.55 z m -18.58,18.4 c -4.73,-0.1 -9.65,-2 -12.994,-5.4 L 22.3,53.85 z M 9.386,40.35 c 3.324,-3.4 7.864,-5.5 12.644,-5.5 l 0.24,18 z m 26.224,-0.1 c 3.44,3.5 5.39,8 5.39,12.8 l -18,0.1 z M 3.989,52.75 c 0.15,-4.7 1.88,-8.7 5.1,-12.1 l 12.871,12.5 z m 5.03,13.2 c -3.3,-3.4 -4.99,-7.8 -5.02,-12.7 l 17.931,0.3 z M 22.54,34.85 c 4.77,-0.1 9.28,1.7 12.7,5 l -12.55,13 z"/>
</svg>
</label>
</li>
<li class="item">
<label>
<input name="skills" type="checkbox" value="5">
<span class="title" data-checked="Заказана" data-unchecked="Хочу">Соломинка</span>
<svg class="picture pipe" viewBox="0 0 114 154">
<rect class="top" width="3.674" height="31.23" x="63.35" y="-78.83"/>
<path d="m 76.43,20.35 2.41,2.7 -0.37,0.4 -2.79,-2.3 z"/>
<path d="m 74.66,22.95 3.23,1.4 -0.15,0.5 -3.42,-0.9 z"/>
<path d="m 75.39,21.55 2.94,2.1 -0.33,0.5 -3.17,-1.7 z"/>
<path d="m 74.25,24.35 3.42,0.7 -6.23,27.8 -3.7,0 z"/>
<path d="m 67.74,53.35 3.62,0 -3.03,30.1 -3.54,0 z"/>
<path class="bottom" d="m 64.8,83.55 3.46,0 -5.46,51.85 -3.37,0 z"/>
</svg>
</label>
</li>
</ul>
<svg class="picture hiball" viewBox="0 0 114 154">
<defs>
<linearGradient id="glass" gradientUnits="userSpaceOnUse" x1="60" y1="105" x2="60" y2="135">
<stop class="start" offset="0"/>
<stop class="end" offset="1"/>
</linearGradient>
</defs>
<path class="line" d="m 22.95,58.95 75.78,0 z"/>
<rect class="bottom" width="71" height="4" ry="1" x="25.5" y="147"/>
<path class="mainline" d="m 99.03,83.45 -3,59.95 z m -76.34,0 3.23,59.95 z m 73.34,59.95 0,4 c 0,0 -0.1,0 -0.2,0 l -69.71,0 c -0.11,0 -0.2,0 -0.2,0 l 0,-4 m -3.22,-59.95 0,-29.1 c 0,-0.6 0.56,-1.2 1.24,-1.2 l 0,0 0,0 73.79,0 c 0.7,0 1.3,0.6 1.3,1.2 l 0,29.1"/>
<path class="glass" d="m 45.95,143.4 c -0.56,-9 -1,-28 -1,-28 0,0 0.13,-7 -2.16,-11 -4,-8 -12.62,-8 -15.33,1 -1.48,4 -0.55,12 -0.55,12 l 3.57,26"/>
<path class="glass" d="m 50.78,143.4 -1.79,-26 c 0,0 -0.8,-8 1.7,-13 4.4,-8.05 15.7,-8.05 20,0 2.3,4 1.8,13 1.8,13 l -0.57,26"/>
<path class="glass" d="m 75.75,143.4 0.83,-28 c 0,0 -0.13,-7 2.16,-11 3.94,-8.05 12.62,-8.05 15.29,1 1.5,4 0.5,12 0.5,12 l -2.81,26"/>
</svg>
</form>
</div>
html{
font-size:1.5em;
}
body{
margin:30px;
}
.main,
.change{
display:inline-block;
vertical-align:top;
}
.main{
border:4px solid #369;
border-radius:4px;
font-size:0;
}
.list{
list-style:none;
margin:0;
padding:0;
}
.item{
background:#fff;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
/*Основная форма*/
@keyframes rotate{
0%{
transform:rotateZ(270deg) scale(.3);
}
100%{
transform:rotateZ(360deg) scale(1);
}
}
@-webkit-keyframes rotate{
0%{
-webkit-transform:rotateZ(270deg) scale(.3);
}
100%{
-webkit-transform:rotateZ(360deg) scale(1);
}
}
.main .item + .item{
margin-top:-1px;
border-top:1px dotted #369;
}
.main .item + .item label{
margin-top:-1px;
}
.main .item label{
display:block;
}
.main .item input[type="checkbox"]{
margin:0 0 0 10px;
vertical-align:middle;
}
.main .item .title{
display:inline-block;
position:relative;
box-sizing:border-box;
padding:8px 14px 10px 10px;
vertical-align:middle;
font-size:1rem;
-webkit-transition:background .2s;
transition:background .2s;
}
.main .item + .item .title{
border-top:1px solid transparent;
}
/*Цвет*/
.main.color .item input[type="checkbox"]{
position:absolute;
opacity:0;
}
.main.color .item .title{
width:100%;
}
.main.color .item input[type="checkbox"]:checked + .title{
color:#fff;
background:#609b46;
border-color:rgba(255, 255, 255, .3);
}
.main.color .item input[type="checkbox"]:disabled + .title{
background:#369;
}
/*Скрыт флажок видна картинка*/
.main.image .item .title{
width:100%;
padding-left:1.2em;
}
.main.image .item input[type="checkbox"]{
position:absolute;
opacity:0;
}
.main.image .item .title:after{
content:"";
opacity:0;
position:absolute;
top:50%;
left:.2em;
width:.7em;
height:.7em;
margin:-.4em 0 0;
background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 21"><path d="m 0,9 c 5,4 8,12 8,12 l 2.5,0 c 4,-9 7,-13 15,-19 l -1.5,-1.5 c -7,4 -10,7 -15,13 -2,-3 -4,-5 -7,-7 z" fill="rgba(255, 255, 255, 1)"/></svg>') 0 0 / 100% 100% no-repeat;
}
.main.image .item input[type="checkbox"]:checked + .title:after{
opacity:1;
-webkit-animation:rotate .2s linear;
animation:rotate .2s linear;
}
/*Скрыт флажок видна картинка за пределами*/
.main.image.outside{
margin-left:1.2em;
}
.main.image.outside .item .title{
padding-left:10px;
}
.main.image.outside .item .title:after{
content:"";
left:auto;
right:100%;
margin-right:10px;
background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 21"><path d="m 0,9 c 5,4 8,12 8,12 l 2.5,0 c 4,-9 7,-13 15,-19 l -1.5,-1.5 c -7,4 -10,7 -15,13 -2,-3 -4,-5 -7,-7 z" fill="rgba(96, 155, 70, 1)"/></svg>') 0 0 / 100% 100% no-repeat;
}
.main.image.outside .item input[type="checkbox"]:disabled + .title:after{
background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 21"><path d="m 0,9 c 5,4 8,12 8,12 l 2.5,0 c 4,-9 7,-13 15,-19 l -1.5,-1.5 c -7,4 -10,7 -15,13 -2,-3 -4,-5 -7,-7 z" fill="rgba(51, 102, 153, 1)"/></svg>');
}
/*Текст*/
.main.text .item .title:after{
content:": " attr(data-checked);
opacity:0;
}
.main.text .item input[type="checkbox"]:checked + .title:after{
opacity:1;
}
/*Цвет + текст*/
.main.color.text .item input[type="checkbox"]:checked + .title:after{
opacity:1;
}
/*Вспомогательная форма*/
.change{
margin:0 70px 0 0;
}
.change + .main.image.outside{
margin:0;
}
.change .item + .item{
margin-top:10px;
}
.change .item label{
display:inline-block;
position:relative;
z-index:1;
padding:.2em 1em .3em;
cursor:pointer;
}
.change .item input[type="radio"]{
position:absolute;
opacity:0;
}
.change .item .title{
display:inline-block;
text-shadow:0 1px rgba(255, 255, 255, .5);
}
.change .item .title:before{
content:"";
opacity:.1;
position:absolute;
z-index:-1;
top:0;
right:0;
bottom:0;
left:0;
border-radius:.9em;
background:#576b8a;
-webkit-transition:.1s;
transition:.1s;
}
.change .item input[type="radio"]:checked + .title:before{
opacity:1;
}
.change .item input[type="radio"]:checked + .title{
text-shadow:0 1px rgba(0, 0, 0, .3);
}
.change .item:hover .title:before{
opacity:.3;
}
.change .item input[type="radio"]:checked + .title{
color:#fff;
}
/*Карточка*/
.card{
display:inline-block;
position:relative;
vertical-align:top;
}
/*Картинка*/
@keyframes ice1{
25%{
transform:rotateZ(-15deg);
}
75%{
transform:rotateZ(-35deg);
}
}
@keyframes ice2{
25%{
transform:rotateZ(0deg);
}
75%{
transform:rotateZ(60deg);
}
}
@keyframes ice3{
25%{
transform:rotateZ(0deg);
}
75%{
transform:rotateZ(40deg);
}
}
@keyframes pipe{
25%{
transform:rotateZ(-3deg) translate(0, 2px) scale(1.7, 1.7);
}
75%{
transform:rotateZ(3deg) translate(0, -1px) scale(1.7, 1.7);
}
}
@-webkit-keyframes ice1{
25%{
transform:rotateZ(-15deg);
}
75%{
transform:rotateZ(-35deg);
}
}
@-webkit-keyframes ice2{
25%{
transform:rotateZ(0deg);
}
75%{
transform:rotateZ(60deg);
}
}
@-webkit-keyframes ice3{
25%{
transform:rotateZ(0deg);
}
75%{
transform:rotateZ(40deg);
}
}
@-webkit-keyframes pipe{
25%{
transform:rotateZ(-3deg) scale(1.7, 1.7) translate(0, 2px);
}
75%{
transform:rotateZ(3deg) scale(1.7, 1.7) translate(0, -1px);
}
}
.card .picture{
position:absolute;
top:50%;
left:100%;
width:114px;
height:154px;
margin:-85px 0 0 3rem;
transform:scale(1.7, 1.7);
}
.card .picture{
display:none;
}
.card .picture.hiball,
.card input[type="checkbox"]:checked ~ .picture{
display:block;
}
.picture .start{
stop-color:#ebf5ff;
stop-opacity:.4;
}
.picture .end{
stop-color:#fff;
stop-opacity:0;
}
.picture.whiskey{
fill:#89281b;
}
.picture.cola{
fill:#521810;
}
.picture.hiball{
stroke:#000;
}
.picture.hiball .line{
opacity:.5;
stroke-width:.1;
}
.picture.hiball .mainline{
opacity:.5;
stroke-width:1;
fill:rgba(235, 245, 255, .4);
}
.picture.hiball .glass{
opacity:.5;
fill:url(#glass);
stroke:#cde6ff;
stroke-width:.5;
stroke-opacity:.4;
}
.picture.hiball .bottom{
opacity:.7;
fill:rgba(0, 0, 0, 1);
stroke-width:0;
}
.picture.lime{
}
.picture.lime .skin{
fill:transparent;
fill-opacity:1;
stroke:#81a916;
stroke-width:2;
}
.picture.lime .slices{
fill:#e2f81f;
stroke:#81a916;
stroke-width:.2;
}
.picture.ice .cube{
opacity:.7;
fill:#75808f;
stroke:#b2d3d5;
stroke-opacity:.7;
animation-iteration-count:infinite;
animation-timing-function:linear;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
}
.picture.ice .cube.left{
stroke-width:1;
transform:rotate(-25deg);
transform-origin:40px 85px;
animation-name:ice1;
animation-duration:4s;
-webkit-animation-name:ice1;
-webkit-animation-duration:4s;
}
.picture.ice .cube.center{
transform:rotate(30deg);
transform-origin:57px 87px;
animation-name:ice2;
animation-duration:7s;
-webkit-animation-name:ice2;
-webkit-animation-duration:7s;
}
.picture.ice .cube.right{
transform:rotate(20deg);
transform-origin:83px 85px;
animation-name:ice3;
animation-duration:5s;
-webkit-animation-name:ice3;
-webkit-animation-duration:5s;
}
.picture.pipe{
fill:#3e8271;
stroke:#234940;
stroke-width:.1;
transform-origin:50px 77px;
animation:pipe linear 8s infinite;
-webkit-animation:pipe linear 8s infinite;
}
.picture.pipe .top{
transform:matrix(.6251, .7805, -.7805, .6251, 0, 0);
}
.picture.pipe .bottom{
opacity:.6;
fill:#c0ebea;
stroke:#fff;
}
$(function () {
var $mainForm = $('[data-container="alcohol"]'),
$changeForm = $('[data-action="alcohol"]'),
$views = $changeForm.find('[name="view"]'),
$active = $views.filter(':checked'),
mainClass = $mainForm.data('class');
$(document).on('change', '[name="view"]', function () {
setForm(this);
});
if (!$active.length) {
$active = $views.eq(0);
$active.trigger('click');
} else {
setForm($active.get(0));
}
function setForm (input) {
$mainForm.removeClass().addClass(mainClass).addClass(input.value);
}
});
Also see: Tab Triggers