Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 data-moveelem-source="hello-world" data-moveelem-breakpoint="1024">
  <span>Hello world</span>
</div>

<div data-moveelem-target="hello-world"></div>
              
            
!

CSS

              
                [data-moveelem-source] {
  border: 1px solid red;
}

[data-moveelem-target] {
  border: 1px solid blue;
}

[data-moveelem-source],
[data-moveelem-target] {
  width: 200px;
  height: 50px;
  margin: 10px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

              
            
!

JS

              
                (() => {
  const move = (sourceNode, targetTarget) => {
    // Get all child elements of the source element
    const sourceNodeChildren = Array.from(sourceNode.childNodes);

    // And append the to the target element
    for (let i = 0; i < sourceNodeChildren.length; i++) {
      targetTarget.appendChild(sourceNodeChildren[i]);
    }
  };

  // Listening to breakpoint and performing the move on breaktpoint hit
  const listenMatchMedia = (sourceNode, targetTarget, breakpoint) => {    
    const mediaQuery = window.matchMedia(`(min-width: ${breakpoint}px)`);
    const handleChange = (e) => {
      if (e.matches) {
        move(targetTarget, sourceNode);
      } else {
        move(sourceNode, targetTarget);
      }
    };
    mediaQuery.addEventListener('change', handleChange);
    handleChange(mediaQuery);
  };

  // Main function
  const moveElems = () => {
    // Get all source elements
    const moveElemSourceNodes = document.querySelectorAll('[data-moveelem-source]');

    // For all source elements
    for (let i = 0; i < moveElemSourceNodes.length; i++) {
      // Get breaktpoint number in px
      const breakpoint = parseInt(moveElemSourceNodes[i].getAttribute('data-moveelem-breakpoint'), 10);
      // Get codename that should be that same for source and target elements
      const moveElemSourceCodename = moveElemSourceNodes[i].getAttribute('data-moveelem-source');
      if (!moveElemSourceCodename || Number.isNaN(breakpoint)) continue;

      // Get appropriate target element
      const moveElemTargetNode = document.querySelector(`[data-moveelem-target="${moveElemSourceCodename}"]`);
      if (!moveElemTargetNode) continue;

      // When breakpoint is hit, move the elements
      listenMatchMedia(moveElemSourceNodes[i], moveElemTargetNode, breakpoint);
    }
  };

  moveElems();
})();
              
            
!
999px

Console