123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="wrapper">
  <header><h1>Right click any element to change it</h1></header>
  <content><p>You can change me aswell and even my parent</p></content>
  <footer><ul><li>and me</li><li>and me</li><li>even me</li></ul></footer>
</div>


<div class="overlay"></div>
<div class="textChange">
  <input type="textarea" placeholder="Type new text in here">
</div>

<div class="colorpicker">
  <div class="color" style="background-color:#1abc9c"></div>
  <div class="color" style="background-color:#16a085"></div>
  <div class="color" style="background-color:#2ecc71"></div>
  <div class="color" style="background-color:#27ae60"></div>
  <div class="color" style="background-color:#3498db"></div>
  <div class="color" style="background-color:#2980b9"></div>
  <div class="color" style="background-color:#9b59b6"></div>
  <div class="color" style="background-color:#8e44ad"></div>
  <div class="color" style="background-color:#e74c3c"></div>
  <div class="color" style="background-color:#c0392b"></div>
  <div class="color" style="background-color:#e67e22"></div>
  <div class="color" style="background-color:#d35400"></div>
  <div class="color" style="background-color:#f1c40f"></div>
  <div class="color" style="background-color:#f39c12"></div>
  <div class="color" style="background-color:#ecf0f1"></div>
  <div class="color" style="background-color:#bdc3c7"></div>
  <div class="color" style="background-color:#95a5a6"></div>
  <div class="color" style="background-color:#7f8c8d"></div>
  <div class="color" style="background-color:#34495e"></div>
  <div class="color" style="background-color:#2c3e50"></div>
</div>

<ul class='custom-menu'>
  <li>Customize</li><hr>
  <li data-action="color">Change color</li>
  <li data-action="bgcolor">Change background-color</li>
  <li data-action="text">Change text</li>
  <li data-action="bcolor">Add/Change border</li><hr>
  <li data-action="remove">Remove this element</li>
  <li data-action="bremove">Remove border</li>
</ul>
            
          
!
            
              *{
  margin:0;
  padding:0;
  box-sizing:border-box;
  font-family: 'Exo', sans-serif;
}
header,content,footer{
  display:block;
  width:100%;
  height:200px;
  padding:50px 20%;
}
header{
  background:#efefef;
}
content{
  background-color:#cccccc;
}
footer{
  background-color:#afafaf
}
p, h1{
  display:inline-block;
  padding:5px;
}
.custom-menu {
  display: none;
  z-index: 1000;
  position: absolute;
  overflow: hidden;
  border: 1px solid #bdc3c7;
  white-space: nowrap;
  background: #303030;
  color: #fff;
}
.custom-menu li {
  padding: 9px 15px;
  cursor: pointer;
  list-style-type: none;
  transition: all .3s ease;
  user-select: none;
  font-weight:200;
}
.custom-menu li:nth-child(1){
  pointer-events:none;
  color:#b2b2b2;
}
.custom-menu hr{
  margin:0 12px;
  border:none;
  background-color:#545454;
  height:1px;
}
.custom-menu li:hover {
  background-color: #545454;
}
.colorpicker{
  position:fixed;
  z-index:20;
  display:none;
  flex-wrap:wrap;
  top:10%;
  left:10%;
  height:80%;
  width:80%;
  background-color:white;
  -webkit-box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.5);
  -moz-box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.5);
  box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.5);
}
.color{
  display:block;
  flex-grow:1;
  transition:.5s ease-in-out;
  cursor:pointer;
}
.textChange{
  display:none;
  position:fixed;
  z-index:20;
  top:calc(50% - 25px);
  width:20%;
  height:50px;
  left:40%;
}
.textChange input{
  height:100%;
  width:100%;
  padding:10px;
  font-size:1.1em;
}
.overlay{
  display:none;
  position:fixed;
  z-index:10;
  width:100%;
  background-color:black;
  height:100%;
  opacity:.5;
  top:0;
}
.disabled{
  pointer-events:none;
  color:#a3a3a3;
}
            
          
!
            
              $(document).on("contextmenu", function(e){
  $('.custom-menu li').show(0);
  e.preventDefault();
  // get the tag name and the exact element
  var el = e.target.nodeName.toLowerCase();
  $('li:nth-child(1) span').remove();
  $('li:nth-child(1)').append("<span> " + el + " </span>");
  var x = e.clientX, y = e.clientY,
      efp = document.elementFromPoint(x, y);
  switch(el){ 
  // define the editable elements here (in caps) and set, which options to hide
    case "p":
    case "h1":
    case "h2":
    case "h3":
    case "li":
      tc();
      break;
    default :
      $('.custom-menu li[data-action=color]').hide();
      $('.custom-menu li[data-action=text]').hide();
  }
  if($(efp).prop('style').border == ''){
    $('.custom-menu li[data-action=bremove]').hide();
  }
  function tc(){
    $('.custom-menu li[data-action=bgcolor]').hide();
  }
  $(".custom-menu li").on("click", function(){
    var da = $(this).attr("data-action");
    switch(da){
    // define function to call when clicking context menu item
      case "color": 
        colorPick();
        break;
      case "bgcolor": 
        bgcolorPick();
        break;
      case "text": 
        textChange();
        break;
      case "bcolor":
        bcolorPick();
        break;
      case "remove":
        removeEl();
        break;
      case "bremove":
        bremove();
        break;
    }
    $(".custom-menu").fadeOut(100);
  });
  $(".custom-menu").finish().fadeIn(100).css({
    top: e.pageY + "px",
    left: e.pageX + "px"
  });
  // color picker
  function colorPick(){
    $(".overlay").fadeIn();
    $(".colorpicker").fadeIn().css('display', 'flex');
    $(".color").off("click").on("click", function(){
      var color = $(this).css('background-color');
      console.log("colorPick - efp = ", efp)
      $(efp).css('color', color);
      $(".colorpicker, .overlay").fadeOut();
    });
  }
  // background color picker
  function bgcolorPick(){
    $(".overlay").fadeIn();
    $(".colorpicker").fadeIn().css('display', 'flex');
    $(".color").off("click").on("click", function(){
      var color = $(this).css('background-color');
      $(efp).css('background-color', color);
      $(".colorpicker, .overlay").fadeOut();
    });
  }
  function bcolorPick(){
    $(".overlay").fadeIn();
    $(".colorpicker").fadeIn().css('display', 'flex');
    $(".color").off("click").on("click", function(){
      var color = $(this).css('background-color');
      $(efp).css({
        'border': '2px solid',
        'border-color': color
      });
      $(".colorpicker, .overlay").fadeOut();
    });
  }
  // make text editable
  function textChange(){
    $(efp).attr('contenteditable','true');
    $(efp).get(0).focus();
    $(efp).focusout(function(){
        $(efp).attr('contenteditable','false');
    });
  }
  function removeEl(){
    $(efp).fadeOut();
  }
  function bremove(){
    $(efp).css("border", "");
  }
});
// fade color picker out when clicking outside of it
$('.overlay').click(function(){
  $('.overlay, .colorpicker').fadeOut();
});
// if the context menu is open, close it when clicking anywhere
$(document).click(function(e){    
  if (!$(e.target).parents(".custom-menu").length > 0) {
    $(".custom-menu").fadeOut(100);
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console