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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console