cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              %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

            
          
!
            
              @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
            
          
!
            
              ###
	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
🕑 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.
Loading ..................

Console