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="bg"></div>
<div class="thumbnail">
  <h4>THE ASSUME THE POSITIONER</h4>
  <p><strong>Click on the key image feature to get the background-position needed.</strong></p>
  <img src="https://images.unsplash.com/reserve/sZdXEWxTZ6BxcBuj6HZP_DSC_0090.JPG?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=fccd8e474f845626f7c23b214a2f9823" alt="" />
  <p class="info">background-position: center center</p>
  <hr>
  <p>Use your own Image<br>(paste in URL)</p>
  <input type="text" />
</div>
              
            
!

CSS

              
                * {box-sizing:border-box;}

.bg {
  transition:background-position 500ms ease-in-out;
  background: url(https://images.unsplash.com/reserve/sZdXEWxTZ6BxcBuj6HZP_DSC_0090.JPG?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=fccd8e474f845626f7c23b214a2f9823) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.thumbnail {
  background:#fff;  
  position:absolute;
  top:2em;
  left:2em;
  width:200px;
  border:10px solid #fff; 
  opacity:0.25;
  transition: all 250ms;
  text-align:center;
  box-shadow : 0 0 0px rgba(0,0,0,0.0);
  &:hover {
    opacity:1;
    box-shadow : 0 0 10px rgba(0,0,0,0.5);
  }
}


.thumbnail input {
  max-width:100%;
}

.thumbnail p {
  padding:1rem 0;
  margin:0.25rem auto;
  font-size:0.75em;
  
  &.info {
    padding: 0.5rem auto;
    background : rgba(0,0,0,0.1);
    font-family: monospace;
    font-weight:700;
  }
}

.thumbnail img {
  cursor:pointer;  
  width:100%;
  height:auto;
  display:block;
  border: 1px solid transparent;
  transition: border-color 0.5s;
  &:hover {
    border: 1px solid red;
  }
}

html, body, .bg {
  margin:0;padding:0;
  width:100%;
  height:100%;
}


              
            
!

JS

              
                var useRounding = true;

$('input').on('paste blur', function(e){
  var element = this;
  setTimeout(function () {
    var text = $(element).val();
    $(".thumbnail img").attr('src', text);
    $(".bg").css('background-image', "url("+text+")");
  }, 100);
});

$('.thumbnail img').click(function(e) {
  var width = $('.thumbnail img').width();
  var height = $('.thumbnail img').height();
  var offset = $(this).offset();
  var relativeX = ((e.pageX - offset.left)/width)*100;
  var relativeY = ((e.pageY - offset.top)/height)*100;
  if (useRounding) {
    relativeX = Math.round(relativeX);
    relativeY = Math.round(relativeY);
  }
  
  var cssBgPosition = relativeX + "% " + relativeY +"%";
  
  $('.info').html("background-position: " + cssBgPosition);
  
  $('.bg').css("background-position", cssBgPosition);
});
              
            
!
999px

Console