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

              
                %h1.title Half-byte Calculator
%p.instructions Click the circles to change the values of the 'nibbles' and get their sum.<br />Oh Yeah! This is pure CSS....

%form.binary-calculator
	- (1...6).each do |i|
		%input.control-bit{type: "checkbox", name: "d#{((i - 1)*2 + 2)}", id: "d#{((i - 1)*2 + 1)}"}
		%label.display-bit{for: "d#{((i - 1)*2 + 1)}", class: "display-#{((i - 1)*2 + 1)}"}
			%span.display-bit__value--zero 0
			%span.display-bit__value--one 1
		%input.control-bit{type: "checkbox", name: "d#{((i - 1)*2 + 2)}", id: "d#{((i - 1)*2 + 2)}"}
		%label.display-bit{for: "d#{((i - 1)*2 + 2)}", class: "display-#{((i - 1)*2 + 2)}"}
			%span.display-bit__value--zero 0
			%span.display-bit__value--one 1
		%span.result-bit{class: "result-#{i}"}
			%span.display-bit__value--zero 0
			%span.display-bit__value--one 1
	.operator-bar

              
            
!

CSS

              
                @import bourbon
	
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400)
@import url(https://fonts.googleapis.com/css?family=Courgette)

// fonts
$font-number: 'Ubuntu Mono', monospace
$font-text: 'Courgette', cursive

// core vars
$block-size: 85px
$gutter: 10px
$columns: 5
$rows: 3

// colors
$background: #87cdd4
$text-color: #319298
$interface: yellow
$highlight: white


// interface
.title
	font-family: $font-text
	font-size: 2.6em
	text-align: center
	color: $highlight
	text-shadow: 3px 3px 0 rgba($highlight, .3)
	padding: 1em
	box-sizing: border-box

.instructions
	width: 45vw
	max-width: 600px
	font-family: $font-text
	line-height: 1.4
	margin: 0 auto
	text-align: center
	color: $text-color

// bit state control
=on-state()
	.display-bit__value--zero
		margin-top: $block-size*-1

=off-state()
	.display-bit__value--zero
		margin-top: 0
	
// general styles
body
	background: $background

	
// main calculator style
.binary-calculator
	display: block
	width: $columns * ($block-size + $gutter)
	height: $rows * $block-size
	position: relative
	left: 50vw
	margin-top: 15vh
	+transform(translateX(-55%))

// hidden form elements
.control-bit
	display: none

// layout elements
.display-bit,
.result-bit
	display: block
	width: $block-size
	height: $block-size
	position: absolute
	overflow: hidden
	box-sizing: border-box
	font-family: $font-number
	font-size: $block-size*.4

.display-bit
	cursor: pointer
	background: lighten($background, 10%)
	border-radius: 50%
	+transition(font-size, .2s)
	
	&:hover
		font-size: $block-size*.5

%display-bit__value
	display: block
	float: left
	width: $block-size
	height: $block-size
	text-align: center
	line-height: $block-size

.display-bit__value--zero,
.display-bit__value--one,
	@extend %display-bit__value
	color: $text-color

.display-bit__value--zero
	+transition(margin-top .6s)

.result-bit
	.display-bit__value--zero,
	.display-bit__value--one
		color: $highlight
	
// User Selected digit
.control-bit:checked + .display-bit
	+on-state

.operator-bar
	position: absolute
	display: block
	width: 100%
	height: $gutter/2
	background: $interface
	top: ($block-size + $gutter) * ($rows - 1) + $gutter/2
	left: 0
	border-radius: 5px

	&:before
		content: '+'
		font-size: $block-size
		position: absolute
		top: $block-size * -1
		left: 25px
		font-family: $font-text
		color: $interface

	

// Number positioning

@for $i from 0 through $columns
	.display-bit:nth-of-type(#{$i*2 + 1})
		top: 0
		right: $i * ($block-size + $gutter)
	.display-bit:nth-of-type(#{$i*2 + 2})
		top: $block-size + $gutter
		right: $i * ($block-size + $gutter)
	.result-bit:nth-of-type(#{$i + 1})
		top: ($block-size + $gutter*1.5) * 2
		right: $i * ($block-size + $gutter)

// carry holders
.display-9, 
.display-10
	visibility: hidden

// special styling for carry
.result-5
	border-bottom: 5px solid lighten($background, 10%)
	
	&:after
		content: 'carry'
		position: absolute
		bottom: 5px
		left: 0
		text-align: center
		font-size: .5em
		font-family: $font-text
		width: 100%
		color: $highlight
		

// logic selectors
$value0: '.control-bit:not(:checked) + .display-bit +.control-bit:not(:checked) + .display-bit +.result-bit'
$value1a: '.control-bit:checked + .display-bit +.control-bit:not(:checked) + .display-bit +.result-bit'
$value1b: '.control-bit:not(:checked) + .display-bit +.control-bit:checked + .display-bit +.result-bit'
$value2: '.control-bit:checked + .display-bit + .control-bit:checked + .display-bit +.result-bit'

// Calculator Logic
#{$value1a},
#{$value1b},
#{$value2} + #{$value0}
	+on-state

#{$value2},
#{$value2} + #{$value1a},
#{$value2} + #{$value1b}
	+off-state

#{$value2} + #{$value1a} + #{$value0},
#{$value2} + #{$value1b} + #{$value0},
#{$value2} + #{$value1a} + #{$value2},
#{$value2} + #{$value1b} + #{$value2},
#{$value2} + #{$value2}
	+on-state

#{$value2} + #{$value1a} + #{$value1b},
#{$value2} + #{$value1b} + #{$value1a},
#{$value2} + #{$value1a} + #{$value1a},
#{$value2} + #{$value1b} + #{$value1b},
#{$value2} + #{$value1a} + #{$value1b} + #{$value1b},
#{$value2} + #{$value1a} + #{$value1b} + #{$value1a},
#{$value2} + #{$value1a} + #{$value1a} + #{$value1a},
#{$value2} + #{$value1a} + #{$value1a} + #{$value1b},
#{$value2} + #{$value1b} + #{$value1a} + #{$value1a},
#{$value2} + #{$value1b} + #{$value1a} + #{$value1b},
#{$value2} + #{$value1b} + #{$value1b} + #{$value1b},
#{$value2} + #{$value1b} + #{$value1b} + #{$value1a}
	+off-state

#{$value2} + #{$value1a} + #{$value1b} + #{$value0},
#{$value2} + #{$value1b} + #{$value1a} + #{$value0},
#{$value2} + #{$value1a} + #{$value1a} + #{$value0},
#{$value2} + #{$value1b} + #{$value1b} + #{$value0},
#{$value2} + #{$value1a} + #{$value1b} + #{$value2},
#{$value2} + #{$value1b} + #{$value1a} + #{$value2},
#{$value2} + #{$value1a} + #{$value1a} + #{$value2},
#{$value2} + #{$value1b} + #{$value1b} + #{$value2},
#{$value2} + #{$value1a} + #{$value1b} + #{$value1b} + #{$value0},
#{$value2} + #{$value1a} + #{$value1b} + #{$value1a} + #{$value0},
#{$value2} + #{$value1a} + #{$value1a} + #{$value1a} + #{$value0},
#{$value2} + #{$value1a} + #{$value1a} + #{$value1b} + #{$value0},
#{$value2} + #{$value1b} + #{$value1a} + #{$value1a} + #{$value0},
#{$value2} + #{$value1b} + #{$value1a} + #{$value1b} + #{$value0},
#{$value2} + #{$value1b} + #{$value1b} + #{$value1b} + #{$value0},
#{$value2} + #{$value1b} + #{$value1b} + #{$value1a} + #{$value0},
	+on-state
              
            
!

JS

              
                ###
	I really love the challenge of creating complex things 
	within limited systems.

	CSS nowadays feels like the perfect medium for that.
	Javascript is fun enough, but it makes things too easy. 

	Read my blog posts and what not at williamanderson.io
	And of course follow me here, on Codepen.
###
              
            
!
999px

Console