.qube -- The Quintessential Responsive 3D CSS Cube

Overview

.qube

Quintessential Responsive 3D CSS Cube

Created by @zacharyjohnsonzachstronaut.com

Hello web friend! The styles defined in "src/qube.css" provide you with an ideal way to create 3D CSS3 cubes that are exceptionally easy to work with and very extensible.

Examples / Demo

View the Examples / Demo

Features

  1. Flexible markup! — Build your cubes using <div> tags, <ul> <li>, or whatever markup you prefer. And, put your cube faces in whatever source order you need by using face classes.
<div class="qube-perspective">
	<!-- Your first cube! -->
	<ul class="qube my-cube">
		<li class="front"></li>
		<li class="left"></li>
		<li class="back"></li>
		<li class="right"></li>
		<li class="top"></li>
		<li class="bottom"></li>
	</ul>
</div>
  1. Specify the size and color/texture of your cube with just two simple CSS rules.
/* Make your cube red and 200 x 200 x 200px */
.my-cube {
	width: 200px;
	height: 200px;
}

	.my-cube > * {
		background: red;
	}
  1. Automatic flat shading! — Your cubes will automatically get basic shading, regardless of the color, image texture, or HTML content you define for the cube faces. (This can be easily customized or disabled entirely with: .qube.no-shading)

Rotating Shaded Cube

  1. Create responsively resizing cubes! — Really easy with the surprisingly well supported CSS viewport units.
/* This responsive cube will be 25% of the viewport width */
.my-viewport-responsive-cube {
	width: 25vw;
	height: 25vw; /* Cubes need 1:1 ratio! */
}

For more conventional responsive design, you can set your cube's width and height to a percentage of its parent element. (By default, .qube is actually 100% width and 100% height.) However, some care must be taken to make sure that the container element maintains a 1:1 aspect ratio.

<div class="qube-perspective one-half">
	<div class="qube">
		... faces ...
	</div>
</div>
.one-half {
	position: relative;
	width: 50%;
	padding-top: 100%;
	/* Sets height to 100% of width, forcing a 1:1 aspect ratio */
}

	.one-half .qube {
		/* Center this cube in the parent */
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		margin: auto;

		/* Each of this cube's faces will be
		   a responsive 25% of the parent */
		width: 25%;
		height: 25%;
	}
  1. Easily rotate your cube along the X, Y, or Z-axis! — Your cube will neatly rotate about its center.
.my-cube {
	transition: transform 1500ms ease;
}

	.my-cube:hover {
		transform: rotateY(359deg);
	}
  1. Optionally, you can skip the face name classes. — Use .qube.faces to turn your elements into faces automatically. Note: This does dictate the source order of your cube faces.
<ul class="qube faces my-automatic-cube">
	<li>My front</li>
	<li>My left</li>
	<li>My back</li>
	<li>My right</li>
	<li>My top</li>
	<li>My bottom</li>
</ul>
  1. Handy utilities and optimizations! — Use .qube-perspective on a parent element to setup your 3D viewport. Use .qube-preserve3d as a shortcut if you need it. Use .qube.solid as an optimization when your cube is not semi-transparent, and you are not displaying the inside of your cube.

  2. Customize individual cube faces! — It's a snap to change the color or other styles of a single cube face. You can even skip a cube face so people can peek inside.

/* Make just the front blue */
.my-cube > .front {
	background: blue;
}
<ul class="qube my-peekaboo-cube">
	<!-- Skipped the front so we can look inside -->
	<li class="left"></li>
	<li class="back"></li>
	<li class="right"></li>
	<li class="top"></li>
	<li class="bottom"></li>
</ul>

Usage

Download this GitHub project, add the "src/qube.css" or "src/qube.min.css" CSS file to your project, and include the file in your <head>.

<link href="/my/path/qube.min.css" rel="stylesheet" type="text/css" />

Define your cube using your preferred markup. Note: If you do not use .qube-perspective it will be important to establish your own CSS perspective settings or your cubes will look flat.

<div class="qube-perspective">
	<div class="qube my-cube">
		<div class="front">Hey!</div>
		<div class="left">Howdy!</div>
		<div class="back">Hi!</div>
		<div class="right">Hello!</div>
		<div class="top">Foo</div>
		<div class="bottom">Bar</div>
	</div>
</div>

Style your cube.

/* Create a 200 by 200 by 200px cube... */
.my-cube {
	width: 200px;
	height: 200px;
	/* (It is a CUBE, so the width/height are EQUAL.) */
}

	/* ...that is red. */
	.my-cube > * {
		background: #f00;
	}

Browser Support

  • Tested in Chrome 16+, Firefox 10+, Safari 5+, Android 3+, and iOS 4+
  • Compatible with browsers that fully support CSS3 3D Transforms.

Intro to 3D CSS3 (Helpful Prerequisites)

I recommend that you read this very helpful intro to 3D CSS3 properties and this CSS cube reference. You are going to have a lot fewer headaches if you already understand how and when to use these CSS properties:

  • perspective: 1234px;
  • transform-style: preserve-3d;
  • transform: translateZ(0);

Change Log

2015-03-04

  • GitHub Release

Author / License

This project was created by Zachary Johnson. You can find him on Twitter @zacharyjohnson and also at zachstronaut.com.

This code is released under an MIT style license. See LICENSE.txt.

You might also like...

Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Pure CSS (no JavaScript) implementation of Android Material design

Pure CSS ripple effect (no JavaScript) CSS-only implementation of Android Material design "ripple" animation on click event Main advantage of this sol

Dec 11, 2022

CSS loading animations with minimal effort!

Whirl CSS loading animations with minimal effort! whirl is a curation of CSS loading animations(whirls! 😅 ). It started as a drop in CSS file to get

Jan 4, 2023

🔮 CSS loading animations made by single element.

Three Dots The project is a set of CSS loading animations created with three dots which made by just single element. I think the project can not only

Dec 29, 2022

Pure css cross-browser loading animations.

[ArtWorx] xLoader Pure css cross-browser loading animations. xLoader is part of the ArtWorx collection. Most of the loaders made by community, You can

Nov 15, 2021

Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. This is a porting to Web Animation API of the fabulous animate.css project.

Animatelo Just-add-water Web Animations Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emp

Nov 12, 2022

⚡️The Fullstack React Framework — built on Next.js

⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

Jan 4, 2023

3D (animated) cube using only CSS (Less), originally used by LeanCloud (aka. AVOS Cloud)

cube.less 3D (animated) cube using only CSS (LESS). Demo See this demo page. There's also a live production site (WIP) using these cubes. Install $ bo

Nov 14, 2022

A sliding puzzle with a Rubik's cube-like feel.

A sliding puzzle with a Rubik's cube-like feel.

Alok's Sliding Puzzle A sliding puzzle with a Rubik's cube-like feel. Play: https://www.quaxio.com/sliding_puzzle/puzzle.html Screenshot: Building loc

Jun 7, 2022

A stack-based esolang that only uses moves from a Rubiks Cube.

Cubestack Cubestack (from "Rubiks Cube" and "stack-based") is a stack based esolang which serves absolutely no purpose. The whole language has a total

Nov 18, 2022

Responsive Tabs is a jQuery plugin that provides responsive tab functionality.

Responsive Tabs is a jQuery plugin that provides responsive tab functionality. The tabs transform to an accordion when it reaches a CSS breakpoint. You can use this plugin as a solution for displaying tabs elegantly on desktop, tablet and mobile.

Dec 8, 2022

Spectre.css - A Lightweight, Responsive and Modern CSS Framework

Spectre.css Spectre.css is a lightweight, responsive and modern CSS framework. Lightweight (~10KB gzipped) starting point for your projects Flexbox-ba

Jan 8, 2023

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

Bootstrap Sleek, intuitive, and powerful front-end framework for faster and easier web development. Explore Bootstrap docs » Report bug · Request feat

Jan 1, 2023

A set of small, responsive CSS modules that you can use in every web project.

A set of small, responsive CSS modules that you can use in every web project.

Pure A set of small, responsive CSS modules that you can use in every web project. http://purecss.io/ This project is looking for maintainers to suppo

Jan 3, 2023

The worlds smallest fully-responsive css framework

FLUIDITY A fully responsive css framework that is impossibly small HTML is almost 100% responsive out of the box. This stylesheet patches the remainin

Sep 24, 2022

The responsive CSS animation framework for creating unique sliders, presentations, banners, and other step-based applications.

Sequence.js The responsive CSS animation framework for creating unique sliders, presentations, banners, and other step-based applications. Sequence.js

Dec 20, 2022

:snowboarder: A responsive slider jQuery plugin with CSS animations

:snowboarder: A responsive slider jQuery plugin with CSS animations

A responsive slider jQuery plugin with CSS animations Animations from animate.css Online demo Visit plugin website. Appszoom for developers also uses

Dec 12, 2022

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

Bootstrap Sleek, intuitive, and powerful front-end framework for faster and easier web development. Explore Bootstrap docs » Report bug · Request feat

Jan 4, 2023

Create responsive design with the help of css queries

react-native-css-stylesheet Create responsive design with the help of css queries Installation npm install react-native-css-stylesheet Usage Define st

May 9, 2022

A set of small, responsive CSS modules that you can use in every web project.

A set of small, responsive CSS modules that you can use in every web project.

Pure A set of small, responsive CSS modules that you can use in every web project. https://purecss.io/ This project is looking for maintainers to supp

Jan 9, 2023
Owner
Zachary Johnson
Zachary Johnson
Recreation of the background scale hover effect seen on the DDD Hotel website using CSS clip paths.

Background Scale Hover Effect Recreation of the background scale hover effect seen on the DDD Hotel menu using CSS clip paths. Article on Codrops Demo

Codrops 98 Dec 6, 2022
:package: Introduction to CSS 3D transforms

Intro to CSS 3D transforms By David DeSandro 3dtransforms.desandro.com Tutorial, examples, and discussion all about CSS 3D transforms. Originally writ

David DeSandro 998 Jan 2, 2023
CSS 3D Dropdown Concept

Makisu An experimental CSS 3D dropdown concept, wrapped up in a jQuery plugin. Check out the demo (you'll need a CSS 3D capable browser, such as Chrom

Justin Windle 1.5k Nov 28, 2022
Pure CSS animated 3D Super Mario Icon

Pure CSS Super Mario This is the transferred source of a little sideproject I did in 2010. I initially did this without any CSS preprocessor and event

Andreas Jacob 14 Apr 15, 2021
CSS 3D renderer for Three.js.

CSS3D.js by Steven Wittens CSS 3D renderer for Three.js Note: this library is mostly obsolete now that Three.js has its own CSS 3D renderer which is i

null 365 Aug 27, 2022
An old-school arcade-style 3D shoot-em-up rendered entirely with CSS 3D transforms

CSS Space Shooter Play The Game This is an experiment I made to investigate the capabilities of CSS 3D transforms. Having played about with this techn

Michael Bromley 162 Oct 2, 2022
sync CSS 3D transformations to a WebGL scene

gl-css3d Synchronize CSS 3D transformations to a WebGL scene Usage: var createCSS3D = require('gl-css3d'); // pass an HTML DOM element node, such as

null 30 Oct 17, 2022
Pure CSS Image Hover Effect Library

imagehover.css A Scaleable & Light Image Hover CSS Library Imagehover.css is a lovingly crafted CSS library allowing you to easily implement scaleable

Ciaran Walsh 1.8k Dec 21, 2022
A slideshow that uses a CSS glitch effect for slide transitions.

Glitch Slideshow A slideshow that uses the CSS Glitch Effect to transition between slides. Article on Codrops Demo Credits Images by Unsplash.com imag

Codrops 111 Dec 16, 2022
Some ideas for modern multi-layer page transitions using CSS Animations.

Multi-Layer Page Reveal Effects Some ideas for modern multi-layer page transitions using CSS Animations. Article on Codrops Demo Sponsor Demo sponsore

Codrops 117 Nov 1, 2022