Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="render-container">
	<div class="sizeScore">
		<span class="js-width">0px</span> X <span class="js-height">0px</span>
	</div>
	<img class="render-image js-render-image" src="https://purerandomcode.files.wordpress.com/2018/01/hnck3991.jpg?w=1000" />
	<img class="brand" src="https://purerandomcode.files.wordpress.com/2017/02/cropped-prcodelogosquare.jpg?w=100" />
</div>
              
            
!

CSS

              
                .render-image {
	display: block;
	margin: auto;
}
.render-container {
	width: 100%;
	position: relative;
}
body {
	margin: 0;
	padding: 0;
}
.sizeScore {
	position: absolute;
	top: 0px;
	left: 0px;
	background-color: black;
	opacity: 0.5;
	color: aqua;
	padding: 0.5em;
	font-family: sans-serif;
	letter-spacing: 0.1em;
}
.brand{
	position: absolute;
	top: -25px;
	right: 5px;
}

              
            
!

JS

              
                (function($) {
	function calIamgeSize(imageSelector, imageOriginWidth, imageOriginHeight) {
		// make image as big as it can to start
		$(imageSelector).width(
			$(imageSelector)
				.parent()
				.width()
		);

		// Get the one percent of the image width and height
		var widthOnePercent = imageOriginWidth / 100;
		var heightOnePercent = imageOriginHeight / 100;

		// Calculate the width percentage
		var imageCurrentWidth = $(imageSelector).width();
		var imageCurrentPercent = imageCurrentWidth / widthOnePercent;

		// Calculate the height relative to the percentage of the images width
		var imageNewHeight = heightOnePercent * imageCurrentPercent;

		// If the images height is off the page, then rescale
		if ($(window).height() < $(imageSelector).offset().top + imageNewHeight) {
			// Set the new height so it fit on the screen
			imageNewHeight = $(window).height() - $(imageSelector).offset().top;

			// Calculate out what percentage is the height at
			imageCurrentPercent = imageNewHeight / heightOnePercent;

			// Calculate the width relative to the percentage of the images height
			var imageNewWidth = widthOnePercent * imageCurrentPercent;

			// Set new width of image
			$(imageSelector).width(imageNewWidth);
		}

		// set new height of image
		$(imageSelector).height(imageNewHeight);
	}

	// Resize image
	var imageW = 1000;
	var imageH = 667;
	var imageClass = ".js-render-image";
	$(window).on("resize", function() {
		calIamgeSize(imageClass, imageW, imageH);
		sizes();
	});
	calIamgeSize(imageClass, imageW, imageH);
	sizes();

	function sizes() {
		$(".js-width").text(Math.ceil($(".js-render-image").width()) + "px");
		$(".js-height").text(Math.ceil($(".js-render-image").height()) + "px");
	}
})($);

              
            
!
999px

Console