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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="pageWrapper">
  <h1>Scaling an image by 10% </h1>
  <h2>With content re-flowing properly around it</h2>
  <p>The goal is to scale an image by a given percentage regardless of its proportions. Just using transform:scale() by itself does not adjust the rest of a page's content to flow around the new size. The same thing happens with increasing an image's dimensions
    using calc() - and a container is required for calc to even be useful in resizing an image. </p>
  <p>These are the steps I came up with to achieve the scaling of the image <em>and</em> the re-flowing of the surrounding content. It involves both a container and some in-line styles. It's assumed that these styles would be added through javascript:</p>
  <ul>
    <li>Wrap each image in a containing span (.container), and set the display to inline-flex</li>
    <li>Take the image's width and set that as the font-size on the container. If an image is 200px wide, set it's container to a font-size of 200px.</li>
    <li>Take the image's height and set that as the font-size for the image (strange, I know). If an image is is 100px tall, the image's font-size would be 100px.</li>
    <li>Set the percentage you want to scale - 10% in this example - with the transform:scale(1.1) on .scaleMe. At this point, the image will be scaled to the new dimensions, but will still occupy its original dimension in the page flow.</li>
    <li>To make room for the newly scaled image vertically, add a margin to the top and bottom that equals 5% of the original image's height (5x2=10). Because we set the font-size on the image earlier equal to it's height, a margin of .05em works out to 5%.
      </li>
    <li>To fully occupy the newly scaled image's horizontal space, we set a transparent border on the left and right of the container also equal to 5% of the original image's width. Normally, we wouldn't be able to use percentages in borders, but because
      of the font-size we set earlier, we can again use the em unit and have it match up. </li>
  </ul>

  <h3>Some observations and comments</h3>
  <p>This is a pretty convoluted way to resize an image. Ideally, you would just change the values of the dimensions directly on the image itself. For this sample, I've kept the css as simple as possible, but if you were going to build this into a system,
    it would be pretty easy to use CSS variables to define your percentage, and then CSS calc() to convert the percentage you want scaled into the borders, margins and transform. <a href="https://codepen.io/spicedham/pen/MPgxxo">This pen shows how you could do that.</a></p>

  <p>Lorem ipsum dolor sit amet,
    <span class="container" style="font-size: 300px;"><img class="scaleMe" src="svg.svg" width="300" height="100" alt="" style="font-size: 100px"/></span>Aliquam bibendum malesuada ex, eu feugiat erat efficitur sit amet. Sed lacus felis, viverra euismod
    condimentum id, faucibus sit amet tellus. Quisque maximus justo et ultricies placerat. Etiam dapibus, augue eu tristique feugiat, lacus turpis faucibus massa, ut sagittis risus neque vitae neque. </p>
  <p>Lorem ipsum dolor sit amet,
    <span class="container" style="font-size: 100px"><img class="scaleMe" src="svg.svg" width="100" height="200" alt="" style="font-size: 200px"/></span>Aliquam bibendum malesuada ex, eu feugiat erat efficitur sit amet. Sed lacus felis, viverra euismod
    condimentum id, faucibus sit amet tellus. Quisque maximus justo et ultricies placerat. Etiam dapibus, augue eu tristique feugiat, lacus turpis faucibus massa, ut sagittis risus neque vitae neque. </p>
  <p>Lorem ipsum dolor sit amet,
    <span class="container" style="font-size: 20px"><img class="scaleMe" src="svg.svg" width="20" height="20" alt="" style="font-size: 20px"/></span>Aliquam bibendum malesuada ex, eu feugiat erat efficitur sit amet. Sed lacus felis, viverra euismod condimentum
    id, faucibus sit amet tellus. Quisque maximus justo et ultricies placerat. Etiam dapibus, augue eu tristique feugiat, lacus turpis faucibus massa, ut sagittis risus neque vitae neque. </p>
</div>
              
            
!

CSS

              
                .container {
			display: inline-flex;
			vertical-align: middle;
			border-left: solid .05em transparent;
			border-right: solid .05em transparent;
		}
		.scaleMe {
			background-color: orange;
			transform: scale(1.1);
			margin: .05em 0;
		}
              
            
!

JS

              
                
              
            
!
999px

Console