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.
.header
h1 Your cart
p "I say let the world go to hell, but I should always have my tea."
p ― Fyodor Dostoyevsky, Notes from Underground
.cart-container
.empty style="display:none" No more twinkies !
ul.cart
li.product data-price=4.90 data-quantity=2
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/sidebar-cupcake.png"
.product-paper
.product-name Cupcake
.product-price $ 4.90
.product-quantity x2
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=3.50 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/ponytails-coffee-time-coffee-cup3.png"
.product-paper
.product-name Coffee
.product-price $ 3.50
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=5.70 data-quantity=3
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/Chocolate.png"
.product-paper
.product-name Chocolate
.product-price $ 5.70
.product-quantity x3
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=6.90 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/waffle-homestyle.png"
.product-paper
.product-name Waffle
.product-price $ 6.90
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=3.90 data-quantity=2
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/donuts.jpg"
.product-paper
.product-name Donuts
.product-price $ 3.90
.product-quantity x2
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=6.50 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/raspberry-sorbet.gif"
.product-paper
.product-name Sorbet
.product-price $ 6.50
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=1.80 data-quantity=3
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/croissant-psd49504.png"
.product-paper
.product-name French Croissant
.product-price $ 1.80
.product-quantity x3
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=2.50 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/Macaron.png"
.product-paper
.product-name Macaron
.product-price $ 2.50
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=2.50 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/millefeuille-vanille.jpg"
.product-paper
.product-name Mille-feuille
.product-price $ 12.90
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
li.product data-price=9.90 data-quantity=1
.product-preview
.thumbnail
img.image src = "https://s.cdpn.io/24822/tarte-au-citron.jpg"
.product-paper
.product-name Lemon Pie
.product-price $ 9.90
.product-quantity x1
.product-interactions
.button.plus +
.button.minus -
.button.del
table.bill
tr.subtotal
td.label Subtotal :
td.value $ 71.90
tr.salestax
td.label Sales tax :
td.value $ 3.60
tr
td.label Shipping :
td.value $ 5.00
tr.total
td.label Total :
td.value $ 80.50
.actions
.big-button.go Get them !
.actions
.big-button.return Return to shop
@import compass
@import url(https://fonts.googleapis.com/css?family=Mouse+Memoirs:400,700)
*
box-sizing: border-box
html, body
font: 16px 'Mouse Memoirs'
background: #ad6932
color: #523118
width: 100%
height: 100%
.header
text-align: center
padding: 1em 0 2em
background-image: repeating-linear-gradient(45deg, #5f391c, #5f391c 100px, #865127 100px, #865127 200px)
color: #f0dccd
//border-bottom: 5px solid white
box-shadow: 0 0 0 .5em rgba(255, 255, 255, 0.25) inset
h1
font-size: 4em
p
font-size: 1.2em
font-style: italic
.cart-container
width: 100%
height: 280px
display: table
.empty
font-size: 3em
width: 100%
text-align: center
display: table-cell
vertical-align: middle
.cart
list-style: none
height: 280px
width: 10000px
cursor: grab
position: relative
left: 0
transform: translate3d(0, 0, 0)
.product
position: relative
width: 200px
height: 280px
float: left
&:hover
z-index: 1
&:nth-child(3n+1)
.product-preview, .product-interactions
background: #E8B0AF
&:nth-child(3n+2)
.product-preview, .product-interactions
background: #FDDAC4
&:nth-child(3n)
.product-preview, .product-interactions
background: #F1D5A5
.product-preview
padding: 1em
height: 280px
position: relative
.thumbnail
width: 100%
min-height: 120px
max-height: 200px
.image
width: 100%
margin-top: 1em
.product-paper
position: absolute
height: 75px
bottom: 0
background: rgba(255, 255, 255, 0.65)
padding: 1em
display: block
width: 100%
margin-left: -1em
.product-name
font-size: 1.6em
//letter-spacing: -1px
text-align: center
.product-price
text-align: center
font-size: 1.2em
.product-quantity
font-size: 2em
width: 2em
height: 2em
text-align: center
padding: .35em 0
border-radius: 1em
position: absolute
top: .5em
right: .5em
background: #fff
transform: rotateZ(10deg)
backface-visibility: hidden
&:hover .product-interactions, .visible
opacity: 1!important
transform: perspective(600px) rotateX(0deg)!important
.product-interactions
position: absolute
bottom: 75px
width: 100%
height: 60px
border-bottom: 1px dashed rgba(0, 0, 0, .4)
transform-origin: 50% 100% 0
transform: perspective(600px) rotateX(90deg)
opacity: 0
transition: .4s all ease-in-out
display: table
.button
width: 32%
height: 60px
float: left
text-align: center
font-size: 5em
line-height: .75em
color: #999
background: rgba(255, 255, 255, .65)
cursor: pointer
user-select: none
transition: .1s all ease-in-out
transform-origin: 50% 0 0
transform: perspective(600px)
z-index: 0
position: relative
display: table-cell
vertical-align: middle
&.plus
color: #7fb034
&.minus
color: #a0ce5a
&.del:after
content: "+"
position: absolute
color: red
left: 50%
margin-left: -.15em
transform: rotateZ(45deg)
&:nth-child(1), &:nth-child(2)
border-right: 1px dashed rgba(0, 0, 0, .1)
&:nth-child(2)
width: 36%
&:active
font-size: 7em
background: #fff!important
box-shadow: 0 0 0 10px #fff!important
z-index: 10
line-height: .45em
&:hover
background: rgba(255, 255, 255, .5)
.bill
margin: 0
padding: 1em
font-size: 1.4em
line-height: 1.6em
background: #F1D5A5
color: #48320b
width: 100%
.total
font-weight: bold
font-size: 1.6em
tr
td
width: 50%
padding: .25em 20px
.label
text-align: right
.actions
text-align: center
position: relative
width: 100%
height: 6em
.big-button
position: absolute
cursor: pointer
user-select: none
padding: 1em
width: 100%
//background: #865127
//color: #f0dccd
font-size: 1.5em
transition: .1s all ease-in-out
box-shadow: 0 0 0 0 #6c411f
&:active
z-index: 10
font-size: 2em
&.return
background: #ad6932
color: #f0dccd
&:hover
background: #6c411f
&:before
content: "←"
&.go
background: #a0ce5a
color: #334715
font-size: 2em
&:hover
background: #7fb034
&:active
font-size: 2.5em
background: #bede8e
box-shadow: 0 0 0 10px #bede8e
$('.cart-container').on('mousemove', function(evt) {
var windowWidth = $(window).width();
var cartWidth = $('.product').length * 200;
if(windowWidth < cartWidth)
$('.cart').stop(false, true).animate({
left: - (evt.clientX / windowWidth) * (cartWidth - windowWidth)
});
else
$('.cart').stop(false, true).css({
left: 0
});
});
$('.plus').click( function() {
var product = $(this).closest('.product')
var q = product.data('quantity') + 1;
product.data('quantity', q);
updateProduct(product);
});
$('.minus').click( function() {
var product = $(this).closest('.product')
var q = Math.max(1, product.data('quantity') - 1);
product.data('quantity', q);
updateProduct(product);
});
$('.del').click( function() {
var product = $(this).closest('.product')
product.hide('blind', {direction:'left'}, 500, function() {
product.remove();
updateProduct(product);
if($('.product').length == 0) {
$('.cart-container .cart').hide();
$('.cart-container .empty').show();
}
});
});
function updateProduct(product) {
var quantity = product.data('quantity');
var price = product.data('price');
$('.product-quantity', product).text('x' + quantity);
$('.product-price', product).text('$ ' + (price * quantity).toFixed(2));
updateBill();
}
function updateBill() {
var subtotal = 0;
var salestax = 0;
var shipping = 5;
var total = 0;
$('.product').each(function () {
subtotal += $(this).data('quantity') * $(this).data('price');
});
salestax = subtotal * 0.05;
total = subtotal + salestax + shipping;
$('.subtotal .value').text('$ ' + subtotal.toFixed(2));
$('.salestax .value').text('$ ' + salestax.toFixed(2));
$('.total .value').text('$ ' + total.toFixed(2));
}
Also see: Tab Triggers