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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <h1>Example 1</h1>
<div class="wrap">
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus
          sodales elit sodales sodales eu sit amet quam. Curabitur feugiat nibh eu imperdiet porttitor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Cras auctor, tortor sed ornare vestibulum, erat erat semper ligula, at aliquam justo
          purus at massa. Vestibulum magna justo, dapibus blandit faucibus at, pharetra quis nulla. </p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap"  src="http://www.pmob.co.uk/temp2/images/villa.jpg" alt="pic1" width="640" height="478"> </a></div>
  </div>
  <div class="row">
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview.jpg" alt="pic2" width="597" height="317"> </a></div>
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.
          </p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview2.jpg" alt="pic3" width="440" height="524"> </a></div>
  </div>
  <div class="row">
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview.jpg" alt="pic2" width="597" height="317"> </a></div>
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview2.jpg" alt="pic3" width="440" height="524"> </a></div>
  </div>
</div>
<h2>Example 2 -wider image </h2>
<div class="wrap wrap2">
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus
          sodales elit sodales sodales eu sit amet quam. Curabitur feugiat nibh eu imperdiet porttitor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Cras auctor, tortor sed ornare vestibulum, erat erat semper ligula, at aliquam justo
          purus at massa. Vestibulum magna justo, dapibus blandit faucibus at, pharetra quis nulla. </p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap"  src="http://www.pmob.co.uk/temp2/images/villa.jpg" alt="pic1" width="640" height="478"> </a></div>
  </div>
  <div class="row">
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview.jpg" alt="pic2" width="597" height="317"> </a></div>
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.
          </p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview2.jpg" alt="pic3" width="440" height="524"> </a></div>
  </div>
  <div class="row">
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview.jpg" alt="pic2" width="597" height="317"> </a></div>
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. </p>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="w60 textbox-1">
      <div class="inner">
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus aliquid eius quia expedita illo sequi optio labore assumenda. Quisquam illo voluptatibus repellendus mollitia quos maxime quas laborum. Perspiciatis hic, accusamus.Aenean ut risus.</p>
      </div>
    </div>
    <div class="w30 object-fit"><a href="#"><img class="backgroundSwap" src="http://www.pmob.co.uk/temp2/images/cview2.jpg" alt="pic3" width="440" height="524"> </a></div>
  </div>
</div>
              
            
!

CSS

              
                html {
  box-sizing: border-box;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}
body {
  margin: 0;
  background-color: #ffeedd;
}
h1,h2{text-align:center;margin:1em 0;}
.wrap {
  margin: 0 10px;
}

.textbox-1 {
  font-size: 1.25em;
  text-align: justify;
  min-height: 250px;
  display: flex;
}
.inner {
  margin: auto;
}
.row {
  display: flex;
  justify-content: space-around;
  padding: 25px 0;
  max-width: 1280px;
  margin: 10px auto;
}
.w60 {
  flex: 1 0 55%;
  background: #f9f9f9;
  padding: 10px 20px;
}
.w30 {
  background: #fff;
  flex: 0 0 35%;
}
.wrap2 .w60{flex: 1 0 50%;}
.wrap2 .w30{ flex: 0 0 40%;}
.object-fit {
  overflow: hidden;
  position: relative;
}
.object-fit img {
  position: absolute;
  top: 50%;
  left: 50%;
  height: auto;
  width: auto;
  max-width: 100%;
  margin: auto;
  transform: translate(-50%, -50%);
}
@supports (object-fit: cover) {
  .object-fit img {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    transform: none;
    object-fit: cover;
  }
}

/* this class added by js */
img.modifiedImg {
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: cover;
  width: 100%;
  height: 100%;
}

@media screen and (max-width: 700px) {
  .row {
    flex-wrap: wrap;
  }
  .wrap .row > * {
    flex: 1 0 100%;
  }

  .object-fit img {
    position: static;
    height: auto;
    width: 100%;
    margin: auto;
    display: block;
    transform: none;
    border-bottom: 5px solid red;
    border-top: 5px solid #000;
  }
  .textbox-1 {
    order: 1;
    min-height: 0;
  }
}
              
            
!

JS

              
                // find all images with a certain class and remove the foreground image into a background image instead so that background-size:cover can be used.

// Now converted to vanilla js version

(function(d) {
  "use strict";
  if ("querySelector" in document && "addEventListener" in window) {
    var theImages = d.querySelectorAll(".backgroundSwap");
    for (var i = 0, len = theImages.length; i < len; i++) {
      var imageUrl = theImages[i].src;
      theImages[i].src =
        "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
      theImages[i].classList.add("modifiedImg");
      theImages[i].style.backgroundImage = "url(" + imageUrl + ")";
    }
  }
})(document);

// jquery version below
/*
(function(d) {
  "use strict";
  $(".backgroundSwap").each(function () {
    var imageUrl = $(this).attr('src');
    $(this).attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
    $(this).css('background-image','url(' + imageUrl + ')') ;
    $(this).addClass('modifiedImg');
});
})(document);
*/

              
            
!
999px

Console