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.
<section class="bg-gray-100">
<script>
function initSliderComponent_5f7d6072c0a38() {
return {
active: 0,
products: [],
loading: true,
minHeight: function() {
return 'min-height: ' + ((this.loading && '491px') || 0);
},
query: "\n{\n products(\n filter: {\n \n sku: { in: [\"DTHE\"] },\n \n \n }\n pageSize: 8,\n sort: {position: ASC}\n ) {\n items {\n related_products {\n \n sku\n id\n name\n small_image {\n label\n url\n }\n url_key\n price_range {\n minimum_price {\n regular_price {\n value\n currency\n }\n final_price {\n value\n currency\n }\n }\n }\n }\n }\n }\n}",
getProducts: function getProducts($nextTick) { // normally a fetch using the above graphql query
$this = this;
this.products = [1, 2, 3, 4, 5, 6, 7].map(function(index) {
return {
"sku": "ANHE",
"id": index,
"name": "Product Name",
"small_image": {
"label": "Product name",
"url": "https://unsplash.com/photos/lbybdXUYWRs/download?force=true&w=640"
},
"url_key": "key",
"price_range": {
"minimum_price": {
"regular_price": {
"value": 1000,
"currency": "EUR"
},
"final_price": {
"value": 1000,
"currency": "EUR"
}
}
}
}
});
$nextTick(function() {
$this.calcPageSize()
});
},
getSlider: function getSlider() {
return this.$el.querySelector('.js_slides');
},
pageSize: 1,
pageFillers: 0,
calcPageSize: function calcPageSize() {
var slider = this.getSlider();
if (slider) {
this.pageSize = Math.round(slider.clientWidth / slider.querySelector('.js_slide').clientWidth);
this.pageFillers = (this.pageSize * Math.ceil(this.products.length / this.pageSize)) - this.products.length;
}
},
calcActive: function calcActive(event) {
var slider = this.getSlider();
this.active = Math.ceil(
Math.round(
slider.scrollLeft / (slider.scrollWidth / this.products.length)
) / this.pageSize
) * this.pageSize;
}
}
}
</script>
<section class="text-gray-700 body-font my-12" x-data="initSliderComponent_5f7d6072c0a38()" x-init="getProducts($nextTick);" style="min-height: 491px;" :style="minHeight()" @resize.window.debounce="calcPageSize()">
<template x-if="products && products.length">
<div class="relative container">
<div class="container mx-auto flex pt-6 pb-3 mb-6 md:flex-row flex-col items-center border-b-2 border-gray-300">
<h3 class="text-gray-900 text-2xl title-font font-medium">
Related Products: </h3>
</div>
<div class="w-full relative overflow-x-hidden">
<div class="js_slides w-full relative flex flex-no-wrap snap overflow-auto relative flex-no-wrap flex transition-all" id="slider_5f7d6072c0a38" x-on:scroll.debounce="active = Math.ceil(Math.round($event.target.scrollLeft / ($event.target.scrollWidth / products.length))/pageSize)*pageSize">
<template x-for="(product, index) in products" :key="index">
<div class="js_slide w-full md:w-1/2 lg:w-1/3 xl:w-1/4 flex-none shadow-md m-1">
<div class="md:mr-2 rounded-md text-center w-full">
<a :href="'#' + product.url_key + '.html'" class="relative w-full product photo product-item-photo flex items-center bg-white" style="padding-top:100%" tabindex="-1">
<span class="absolute h-full w-full align-center top-0 left-0 flex content-center flex-wrap p-2 overflow-hidden">
<img class="w-full h-auto self-center" :src="product.small_image.url" :alt="product.small_image.label" loading="lazy" width="500" height="500" />
</span>
</a>
<p class="pt-3 flex items-center justify-center text-primary px-1">
<a class="product-item-link truncate" :href="'https://latest.c-218.maxcluster.net/index.php/' + product.url_key + '.html'">
<span x-text="product.name + ' ' + index"></span>
</a>
</p>
<p class="pt-1 text-gray-900" x-text="new Intl.NumberFormat(document.documentElement.lang, { style: 'currency', currency: product.price_range.minimum_price.final_price.currency }).format(product.price_range.minimum_price.final_price.value)"></p>
<p class="p-3 flex flex-wrap inline justify-center">
<a class="w-auto bg-green-500 rounded p-2 shadow-md text-white hover:bg-green-600" :href="'https://hyva.io/' + product.url_key + '.html'">
View Product </a>
</p>
</div>
</div>
</template>
<div :class="{ 'js_dummy_slide w-full md:w-1/2 lg:w-1/3 xl:w-1/4 flex-none py-1' : pageFillers > 0 }" class=""></div>
<div :class="{ 'js_dummy_slide w-full md:w-1/2 lg:w-1/3 xl:w-1/4 flex-none py-1' : pageFillers > 1 }" class=""></div>
<div :class="{ 'js_dummy_slide w-full md:w-1/2 lg:w-1/3 xl:w-1/4 flex-none py-1' : pageFillers > 2 }"></div>
</div>
</div>
<template x-if="products.length && products.length > pageSize">
<div class="p-4 flex items-center justify-center flex-1" x-cloak>
<button class="w-8 h-8 outline-none focus:outline-none rounded-full mx-4 text-black" :class="{ 'invisible' : active === 0 }" x-on:click="getSlider().scrollLeft = (getSlider().scrollWidth / products.length) * (active-pageSize)">
<svg viewBox="0 0 1024 1024">
<path class="path1" d="M716.8 1024c6.552 0 13.102-2.499 18.101-7.499 9.998-9.997 9.998-26.206 0-36.203l-442.698-442.698 442.698-442.699c9.998-9.997 9.998-26.206 0-36.203s-26.206-9.998-36.203 0l-460.8 460.8c-9.998 9.997-9.998 26.206 0 36.203l460.8 460.8c5 5 11.55 7.499 18.102 7.499z"></path>
</svg>
</button>
<template x-for="(product,index) in products" :key="index">
<button class="bg-black w-3 h-3 block mx-1 bg-opacity-25 shadow rounded-full" :alt="index" :class="{'bg-opacity-100': active === index, 'hidden': (pageSize !== 1 && !!(index % pageSize)) }" x-on:click="getSlider().scrollLeft = (getSlider().scrollWidth / products.length) * index"></button>
</template>
<button class="w-8 h-8 outline-none focus:outline-none rounded-full mx-4 text-black" :class="{ 'invisible' : active === products.length-pageSize }" x-on:click="getSlider().scrollLeft = (getSlider().scrollWidth / products.length) * (active+pageSize)">
<svg id="lnr-chevron-right" viewBox="0 0 1024 1024">
<path class="path1" d="M256 1024c-6.552 0-13.102-2.499-18.101-7.499-9.998-9.997-9.998-26.206 0-36.203l442.698-442.698-442.698-442.699c-9.998-9.997-9.998-26.206 0-36.203s26.206-9.998 36.203 0l460.8 460.8c9.998 9.997 9.998 26.206 0 36.203l-460.8 460.8c-5 5-11.55 7.499-18.102 7.499z"></path>
</svg>
</button>
</div>
</template>
</div>
</template>
</section>
</section>
.images.snap,.images.snap>div {
min-width: 80vw;
margin-right: 2rem
}
@media (min-width: 768px) {
.images.snap,.images.snap>div {
min-width:0;
max-width: 80vw;
margin: 0 auto
}
}
.snap {
-ms-scroll-snap-type: x mandatory;
scroll-snap-type: x mandatory;
-ms-overflow-style: none;
scroll-behavior: smooth
}
.snap::-webkit-scrollbar {
display: none
}
.snap>div,.snap>img {
scroll-snap-align: start
}
Also see: Tab Triggers