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

              
                <h1>CSS Grid & flexbox EAN-13 Generator</h1>

<input id="input" type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' maxlength="12" value="871125300120">
</input>
<p id="test"></p>

<div class="box" id="capture">
	<div class="fd inp0">
		<div class="bar"></div>
		<div id="fd" class="digit">8</div>
	</div>
	
	<div class="space sp1">
		<div class="bar w"></div>
		<div class="bar w"></div>
		<div class="bar b"></div>
		<div class="bar w"></div>
		<div class="bar b"></div>
	</div>
	
	<div class="f6"><!-- First group of 6 -->
		<div id="fc1" class="f6c inp1">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">7</div>
		</div>
		
		<div id="fc2" class="f6c inp2">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">1</div>
		</div>
		
		<div id="fc3" class="f6c inp3">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">1</div>
		</div>
		
		<div id="fc4" class="f6c inp4">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">2</div>
		</div>
		
		<div id="fc5" class="f6c inp5">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">5</div>
		</div>
		
		<div id="fc6" class="f6c inp6">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">3</div>
		</div>
	</div><!-- /First group of 6 -->
	
	<div class="space sp2">
		<div class="bar w"></div>
		<div class="bar b"></div>
		<div class="bar w"></div>
		<div class="bar b"></div>
		<div class="bar w"></div>
	</div>
	
	<div class="l6"><!-- Last group of 6 -->
		<div id="lc1" class="l6c inp7">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">0</div>
		</div>
		
		<div id="lc2" class="l6c inp8">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">0</div>
		</div>
		
		<div id="lc3" class="l6c inp9">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">1</div>
		</div>
		
		<div id="lc4" class="l6c inp10">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">2</div>
		</div>
		
		<div id="lc5" class="l6c inp11">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">0</div>
		</div>
		
		<div id="lc6" class="l6c inp12">
			<div class="bar">
				<div class="d1"></div>
				<div class="d2"></div>
				<div class="d3"></div>
				<div class="d4"></div>
				<div class="d5"></div>
				<div class="d6"></div>
				<div class="d7"></div>
			</div>
			<div class="digit">2</div>
		</div>
	</div><!-- /Last group of 6 -->
	
	<div class="space sp3">
		<div class="bar b"></div>
		<div class="bar w"></div>
		<div class="bar b"></div>
		<div class="bar w"></div>
		<div class="bar w"></div>
	</div>
</div>

<div class="close">X</div>
<div class="overlay"></div>

<a class="btn" href="#!" id="capturebtn">generate image</a>

<p class="lt">There are some white lines between the bars (especially in firefox) in the generated image</p>
<p>fixed it with margin: 0 -1px;</p>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto+Mono');

* {
	font-family: 'Roboto Mono', monospace;
}

h1, p {
	text-align: center;
}

.lt {
	text-decoration: line-through;
}

// https://codepen.io/thebabydino/pen/mRrPwB/
input {
  border: none;
  width: 18.1ch;
	display: block;
	margin: 40px auto;
  background: 
    repeating-linear-gradient(90deg, 
        dimgrey 0, 
        dimgrey 1ch, 
        transparent 0, 
        transparent 1.5ch) 
      0 100%/100% 2px no-repeat;
  font-family: 'Roboto Mono', monospace;
  letter-spacing: .5ch;
	font-size: 40px;
	box-shadow: inset -5px 0 0 0 #fff;
	color: dodgerblue;
}

input:focus {
  outline: none;
}

.box {
	width: 90%;
	margin: 0 auto;
	display: grid;
	min-height: 400px;
	border: 1px solid rgba(0,0,0,.1);
	grid: 
		"fd space1 f6 space2 l6 space3"
		/ .5fr 1fr 6fr 1fr 6fr 1fr;
}

@media only screen and (min-width: 1200px) {
	.box {
		width: 50%;
	}
}

.box > div:not(.f6):not(.l6) {
	display: flex;
	flex-direction: column;
}

.bar {
	flex: 1;
	
	& > div {
		margin: 0 -1px 0 0;
		
		&:first-child {
			margin: 0;
		}
	}
}

.space {
	padding-bottom: 30px;
}

.box > div.space {
	flex-direction: row !important;
	
	& .w {
		background: #fff;
	}
	
	& .b {
		background: #000;
	}
}

.digit {
	text-align: center;
	font-size: 50px;
}

.sp1 {
	grid-area: space1;
}
.sp2 {
	grid-area: space2;
}
.sp3 {
	grid-area: space3;
}

.fd {
	grid-area: fd;
}

.f6 {
	grid-area: f6;
	display: grid;
	grid-template-columns: repeat(6, 1fr);
}

.l6 {
	grid-area: l6;
	display: grid;
	grid-template-columns: repeat(6, 1fr);
}

.f6c, .l6c {
	display: flex;
	flex-direction: column;
}

.f6c > .bar, .l6c > .bar {
	display: grid;
	grid-template-columns: repeat(7, 1fr);
}

.btn {
	display: block;
	margin: 20px auto;
	padding: 10px 40px;
	background: dodgerblue;
	width: fit-content;
	font-size: 30px;
	text-decoration: none;
	color: #fff;
	
	&:hover {
		background: darken(dodgerblue, 10);
	}
}

canvas {
	position: absolute;
	margin: auto;
	top: 0; bottom: 0;
	left: 0; right: 0;
	-webkit-box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.3);
	box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.3);
	z-index: 100;
}

.close {
	position: absolute;
	right:0; top:0;
	width: 48px;
	height: 48px;
	background: dodgerblue;
	color: #fff;
	line-height: 48px;
	text-align: center;
	font-size: 30px;
	cursor: pointer;
	display: none;
	z-index: 10;
	
	&.show {
		display: block;
	}
	
	&:hover {
		background: darken(dodgerblue, 10);
	}
}

.overlay {
	position: absolute;
	left:0; top:0;
	width: 100%;
	height: 100%;
	background: rgba(0,0,0,.4);
	display: none;
	z-index: 5;
	
	&.show {
		display: block;
	}
}
              
            
!

JS

              
                // default input
$(document).ready(function() {
	var firstdigit = $('#fd').text();
	getStructure(firstdigit);
});


$('#input').keyup(function() {
	var input = $(this).val();
	input = input.padEnd(12, "0");
	
	var i = 0;
	var checksum = 0;
	
	while (i < 12) {
		var digit = input.charAt(i);
		$('.inp' + i + ' > .digit').html(digit);
		
		var psum = parseInt(digit);
		
		// check if i = odd or even
		(i%2 == 0) ? psum = psum * 1 : psum = psum *3;
		// if (i%2 == 0) {
		// 	// the even data digits are always weight of 1
		// 	psum = psum * 1;
		// } else {
		// 	// the odd data digits are always weight of 3
		// 	psum = psum * 3;
		// }
		
		// add all digits together
		checksum = checksum + psum;
		i++;
	}
	
	// find nearest multiple of 10
	var check = Math.round(checksum / 10) * 10;
	// calculate the checksum (last digit)
	var check = check - checksum;
	
	if (check == 0 || check < 0) {
		check = check * -1;
		check = 10 - check;
	}
	
	if (check == 10) {
		check = 0;
	}
	
	$('.inp12 > .digit').html(check);
	var fdin = input.charAt(0);
	getStructure(fdin);
});

function getStructure(fd) {
	// find pattern with first digit
	if (fd == 0) {
		var f6 = 'LLLLLL';
	} else if (fd == 1) {
		var f6 = 'LLGLGG';
		
	} else if (fd == 2) {
		var f6 = 'LLGGLG';
		
	} else if (fd == 3) {
		var f6 = 'LLGGGL';
		
	} else if (fd == 4) {
		var f6 = 'LGLLGG';
		
	} else if (fd == 5) {
		var f6 = 'LGGLLG';
		
	} else if (fd == 6) {
		var f6 = 'LGGGLL';
		
	} else if (fd == 7) {
		var f6 = 'LGLGLG';
		
	} else if (fd == 8) {
		var f6 = 'LGLGGL';
		
	} else if (fd == 9) {
		var f6 = 'LGGLGL';
	}
	
	$('.f6').removeClass(function (index, className) {
			return (className.match (/(^|\s)L\S+/g) || []).join(' ');
		}).removeClass(function (index, className) {
			return (className.match (/(^|\s)G\S+/g) || []).join(' ');
		}).addClass(f6);
	
	var i = 1;
	
	while (i <= 7) {
		var x = i - 1;
		var fcx = f6.charAt(x);
		var target = '#fc' + i;
		var targetl = '#lc' + i;
		
		i++;
		
		var digit = $(target).children('.digit').text();
		var digitl = $(targetl).children('.digit').text();
		$(target).removeClass(function (index, className) {
			return (className.match (/(^|\s)L\S+/g) || []).join(' ');
		}).removeClass(function (index, className) {
			return (className.match (/(^|\s)G\S+/g) || []).join(' ');
		}).addClass(fcx + digit);
		
		// L Bars
		if (fcx == 'L') {
			$(target + ' > .bar > div').css('background', '#fff');
			// 1
			if (digit == '3' || digit == '4' || digit == '5' || digit == '6' || digit == '7' || digit == '8') {
				$(target + ' > .bar .d2').css('background', '#000');
			}
			
			// 2
			if (digit == '1' || digit == '2' || digit == '3' || digit == '5' || digit == '7' || digit == '8') {
				$(target + ' > .bar .d3').css('background', '#000');
			}
			
			// 3
			if (digit == '0' || digit == '1' || digit == '3' || digit == '6' || digit == '7' || digit == '9') {
				$(target + ' > .bar .d4').css('background', '#000');
			}
			
			// 4
			if (digit == '0' || digit == '3' || digit == '6' || digit == '8') {
				$(target + ' > .bar .d5').css('background', '#000');
			}
			
			// 5
			if (digit == '2' || digit == '4' || digit == '6' || digit == '7' || digit == '8' || digit == '9') {
				$(target + ' > .bar .d6').css('background', '#000');
			}
			
			$(target + ' > .bar .d7').css('background', '#000');
			
		} else if (fcx == 'G') { // G Bars
			$(target + ' > .bar > div').css('background', '#fff');
			// 1
			if (digit == '0' || digit == '1' || digit == '3' || digit == '5') {
				$(target + ' > .bar .d2').css('background', '#000');
			}
			
			// 2
			if (digit == '1' || digit == '2' || digit == '4' || digit == '5' || digit == '7' || digit == '9') {
				$(target + ' > .bar .d3').css('background', '#000');
			}
			
			// 3
			if (digit == '2' || digit == '4' || digit == '5' || digit == '8') {
				$(target + ' > .bar .d4').css('background', '#000');
			}
			
			// 4
			if (digit == '0' || digit == '4' || digit == '6' || digit == '9') {
				$(target + ' > .bar .d5').css('background', '#000');
			}
			
			// 5
			if (digit == '0' || digit == '1' || digit == '2' || digit == '9') {
				$(target + ' > .bar .d6').css('background', '#000');
			}
			
			$(target + ' > .bar .d7').css('background', '#000');
		}
		
		
		//
		// Last 6
		$(targetl + ' > .bar > div').addClass('R' + digitl);
		$(targetl + ' > .bar > div').css('background', '#fff');
		// 1
		if (digitl == '0' || digitl == '1' || digitl == '2' || digitl == '9') {
			$(targetl + ' > .bar .d2').css('background', '#000');
		}
		
		// 2
		if (digitl == '0' || digitl == '4' || digitl == '6' || digitl == '9') {
			$(targetl + ' > .bar .d3').css('background', '#000');
		}
		
		// 3
		if (digitl == '2' || digitl == '4' || digitl == '5' || digitl == '8') {
			$(targetl + ' > .bar .d4').css('background', '#000');
		}
		
		// 4
		if (digitl == '1' || digitl == '2' || digitl == '4' || digitl == '5' || digitl == '7' || digitl == '9') {
			$(targetl + ' > .bar .d5').css('background', '#000');
		}
		
		// 5
		if (digitl == '0' || digitl == '1' || digitl == '3' || digitl == '5' || digitl == '7') {
			$(targetl + ' > .bar .d6').css('background', '#000');
		}
		
		$(targetl + ' > .bar .d1').css('background', '#000');
	}
	
}

$('#capturebtn').click(function() {
	html2canvas(document.querySelector("#capture")).then(canvas => {
			document.body.appendChild(canvas)
	});
	$('.close').addClass('show');
	$('.overlay').addClass('show');
});

$('.close').click(function() {
	$('canvas').remove();
	$(this).removeClass('show');
	$('.overlay').removeClass('show');
});
              
            
!
999px

Console