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="wrapper">
	<div class="box-left">
		<div data-tpl="header1" data-title="Header 1">
			Header 1
		</div>
		<div data-tpl="header2" data-title="Header 2">
			Header 2
		</div>
		<div data-tpl="header3" data-title="Header 3">
			Header 3
		</div>
		<div data-tpl="shortparagraph" data-title="Short paragraph">
			Short paragraph
		</div>
		<div data-tpl="mediumparagraph" data-title="Medium paragraph">
			Medium paragraph
		</div>
		<div data-tpl="largeparagraph" data-title="Large paragraph">
			Large paragraph
		</div>
		<div data-tpl="ullist" data-title="Ordened list">
			Ordened list
		</div>
		<div data-tpl="ollist" data-title="Unordened list">
			Unordened list
		</div>
		<div data-tpl="image" data-title="Image">
			Image
		</div>
    <div data-tpl="code" data-title="Code">
			Code
		</div>
	</div>
	<div class="box-right"></div>
	<div class="options">
		<buttom class="reset">Reset</buttom>
		<buttom class="save">Save File</buttom>
	</div>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html,
body {
  position: relative;
  height: 100%;
  background: #333;
}
img{
  max-width:100%;
}
.wrapper {
  position: relative;
  height: 100%;
}

pre {
  max-width: 30em;
  display: block;
  background: #1f1f1f;
  color: white;
  padding: 0.5em;
  border: 1px solid black;
  word-break: break-all;
  word-wrap: break-word;
}


/* box */

.box-left {
  width: 10rem;
  height: 100%;
  float: left;
  margin: 9;
  padding: 0.5rem;
  background: #333;
  font-size:12px;
}

.box-right {
  position: relative;
  width: calc(100% - 10rem);
  height: calc(100% - 5em);
  float: left;
  margin: 0;
  margin-bottom: 1em;
  padding: 0.5rem;
  background: #fdfdfd;
  overflow-y: auto;
}


/* left boxes */

.box-left div {
  display: block;
  padding: 0.5rem;
  margin: 0;
  margin-bottom: 0.2em;
  text-align: center;
  line-height: 2rem;
  background: #1f1f1f;
  border: 1px solid #252525;
  color: white;
  cursor: all-scroll;
}

.box-left div:hover. .box-left div:focus {
  background: #222;
}

.reset,
.save {
  text-align: right;
  padding: 0.5em 1em;
  background: #1f1f1f;
  border: 1px solid #252525;
  color: white;
  margin: 0.8em 0.2em;
  cursor: pointer;
}

.reset:hover,
.save:hover,
.reset:focus,
.save:focus {
  background: #222;
}

.gu-mirror {
  position: fixed !important;
  margin: 0 !important;
  z-index: 9999 !important;
  opacity: 0.8;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
  filter: alpha(opacity=80);
  background: blue !important;
  display: block !important;
  padding: 0.5rem !important;
  text-align: center !important;
  line-height: 2rem !important;
  border: 1px solid red !important;
  color: white !important;
  overflow:hidden;
}

.gu-hide {
  display: none !important;
}

.gu-unselectable {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
}

.gu-transit {
  opacity: 0.2;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
  filter: alpha(opacity=20);
  background: blue !important;
  line-height:1.2em;
  min-height:5em;
}
              
            
!

JS

              
                /**
 * short localStorage
 */
const db = localStorage;

/**
 * short query selector
 *
 * @param      {<type>}  el      { parameter_description }
 * @return     {string}  { description_of_the_return_value }
 */
const _ = (el) => {
	return document.querySelector(el);
};
/**
 * Gets the tpl.
 *
 * @param      {<type>}  element  The element
 * @return     {string}  The tpl.
 */
const getTpl = (element) => {
	return tpl[element];
};

/**
 * Makes an editable.
 *
 * @return     {string}  { description_of_the_return_value }
 */
const makeEditable = () => {
	let elements = document.querySelectorAll('.drop-element');
	let toArr = Array.prototype.slice.call(elements);
	Array.prototype.forEach.call(toArr, (obj, index) => {
		if (obj.querySelector('img')) {
			return false;
		} else {
			obj.addEventListener('click', (e) => {
				e.preventDefault();
				obj.children[0].setAttribute('contenteditable', '');
				obj.focus();
			});
			obj.children[0].addEventListener('blur', (e) => {
				e.preventDefault();
				obj.children[0].removeAttribute('contenteditable');
			});
		}
	});
};
/**
 * Removes a divs to save.
 *
 * @return     {string}  { description_of_the_return_value }
 */
const removeDivsToSave = () => {
	let elements = document.querySelectorAll('.drop-element');
	let toArr = Array.prototype.slice.call(elements);
	let html = '';
	Array.prototype.forEach.call(toArr, (obj, index) => {
    obj.children[0].removeAttribute('contenteditable');
		html += obj.innerHTML;
	});
	return html;
};

/**
 * Templates
 *
 * @type  string
 */
const tpl = {
	'header1': '<h1>I am header 1</h1>',
	'header2': '<h2>I am header 2</h2>',
	'header3': '<h3>I am header 3</h3>',
	'shortparagraph': '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et</p>',
	'mediumparagraph': '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate</p>',
	'largeparagraph': '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a,</p>',
	'ullist': '<ul><li>item 1</li><li>item 2</li><li>item 3</li><li>item 4</li></ul>',
	'ollist': '<ol><li>item 1</li><li>item 2</li><li>item 3</li><li>item 4</li></ol>',
	'image': '<img src="https://source.unsplash.com/random" alt="Unsplash image random">',
  'code': '<pre>function say(name){\n return name;\n}</pre>'
};

/**
 * init dragula
 *
 * @type  function
 */
const containers = [_('.box-left'), _('.box-right')];
const drake = dragula(containers, {
	copy(el, source) {
		return source === _('.box-left');
	},
	accepts(el, target) {
		return target !== _('.box-left');
	}
});

drake.on('out', (el, container) => {
	if (container == _('.box-right')) {
		el.innerHTML = getTpl(el.getAttribute('data-tpl'));
		el.className = 'drop-element';
		makeEditable();
		db.setItem('savedData', _('.box-right').innerHTML);
	}
	if (container == _('.box-left')) {
		el.innerHTML = el.getAttribute('data-title');
	}
});

/**
 * save in local storage
 */
if (typeof db.getItem('savedData') !== 'undefined') {
	_('.box-right').innerHTML = db.getItem('savedData');
  makeEditable();
};

/**
 * reset
 */
_('.reset').addEventListener('click', (e) => {
	e.preventDefault
	if (confirm('Are you sure !')) {
		_('.box-right').innerHTML = '';
	}
});

/**
 * save to file
 */
_('.save').addEventListener('click', (e) => {
	e.preventDefault();
	var blob = new Blob([removeDivsToSave()], {
		type: 'text/html;charset=utf-8'
	});
  db.setItem('savedData', _('.box-right').innerHTML);
	saveAs(blob, 'file.html');
});

              
            
!
999px

Console