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.
<!--
Container for the images.
-->
<div class="container">
<!--
The markup for each image is a div with the class of card.
-->
<div class="card">
<!--
Each "card" has an image container, this is because you need the image to scale and move, we want the scaling to have a smooth transition. However if you add a transition for transform the transform property it will apply to both the scaling and the translation, causeing the translation to "lag" because as it updates where the mouse position is.
-->
<div class="img-container">
<img id="street" class="img" src="http://themenectar.com/demo/salient-frostwave/wp-content/uploads/2013/06/night-to-remember1-600x400.jpg" alt="street" />
</div>
</div>
<div class="card">
<div class="img-container">
<img id="hill" class="img" src="http://themenectar.com/demo/salient-frostwave/wp-content/uploads/2013/06/great-valley1-600x400.jpg" alt="hill" />
</div>
</div>
<div class="card">
<div class="img-container">
<img id="lake" class="img" src="http://themenectar.com/demo/salient-frostwave/wp-content/uploads/2013/06/on-the-lake1-600x400.jpg" alt="lake" />
</div>
</div>
</div>
body {
background-color: #4C4C4C;
}
.container {
font-size: 0;
width: 100%;
margin-top: 50px;
text-align: center;
}
.card {
overflow: hidden;
position: relative;
display: inline-block;
height: 400px;
width: 600px;
/*
Each "card" is set to 600x400px because that is the size of the image, adjust as needed. Make sure the overflow is set to hidden or else when the img scales it will clip with the other images.
*/
}
.img-container {
transition: transform .1s ease;
}
.img-container:hover {
transform: scale(1.1);
/*
Change the scale value as much as you want to change the amount of zoom on hover.
*/
}
.card img {
opacity: .5;
transform: translate(0,0);
/*
Change the opacity value to change how "faded" you want the image to appear when it is not hovered.
*/
transition: opacity .25s ease-in-out;
}
.card img:hover {
opacity: 1;
}
//Creates an event that fires every time the mouse moves over any div with the class of "img".
$(".img").mousemove(function(event){
//Both the x and y value are calculated by taking the mouse x,y position on the page and subtracting it from the x,y position of the image on the page. "this" is the hovered element with the class of "img"
var mousex = event.pageX - $(this).offset().left;
var mousey = event.pageY - $(this).offset().top;
//If you just used the mouse position values the translation effect will only go up and to the right, by subtracting half of the length / width of the imagevfrom the values we get either a positive or negitive number so that the image will move in any direction.
//The 40 controls the amount of "movement" that will happen by giving us a smaller number, feel free to change it to get the effect that you want.
var imgx = (mousex - 300) / 40;
var imgy = (mousey - 200) / 40;
//Adds a translation css styles to the image element
$(this).css("transform", "translate(" + imgx + "px," + imgy + "px)");
});
//This function will fire every time the user mouses off of the image. It resets the translation back to 0.
$(".img").mouseout(function(){
$(this).css("transform", "translate(0px,0px)");
});
Also see: Tab Triggers