├── .gitignore
├── LICENSE.txt
├── README.md
└── src
├── qube.css
└── qube.min.css
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Zachstronaut LLC
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `.qube`
2 |
3 | ## Quintessential Responsive 3D CSS Cube
4 |
5 | _Created by [@zacharyjohnson](http://twitter.com/zacharyjohnson) — [zachstronaut.com](http://www.zachstronaut.com/)_
6 |
7 | 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.
8 |
9 | ### Examples / Demo
10 |
11 | [View the Examples / Demo](https://zachstronaut.github.io/quintessential-css-cube/)
12 |
13 | ### Features
14 |
15 | 1. **Flexible markup!** — Build your cubes using `
` tags, `
`, or whatever markup you prefer. And, put your cube faces in whatever source order you need by using face classes.
16 |
17 | ```html
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | ```
30 |
31 | 2. **Specify the size and color/texture of your cube with _just two_ simple CSS rules.**
32 |
33 | ```css
34 | /* Make your cube red and 200 x 200 x 200px */
35 | .my-cube {
36 | width: 200px;
37 | height: 200px;
38 | }
39 |
40 | .my-cube > * {
41 | background: red;
42 | }
43 | ```
44 |
45 | 3. **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`)_
46 |
47 | 
48 |
49 | 4. **Create responsively resizing cubes!** — Really easy with the surprisingly well supported CSS [viewport units](http://caniuse.com/#search=viewport%20unit).
50 |
51 | ```css
52 | /* This responsive cube will be 25% of the viewport width */
53 | .my-viewport-responsive-cube {
54 | width: 25vw;
55 | height: 25vw; /* Cubes need 1:1 ratio! */
56 | }
57 | ```
58 |
59 | 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.
60 |
61 | ```html
62 |
63 |
64 | ... faces ...
65 |
66 |
67 | ```
68 |
69 | ```css
70 | .one-half {
71 | position: relative;
72 | width: 50%;
73 | padding-top: 100%;
74 | /* Sets height to 100% of width, forcing a 1:1 aspect ratio */
75 | }
76 |
77 | .one-half .qube {
78 | /* Center this cube in the parent */
79 | position: absolute;
80 | left: 0;
81 | right: 0;
82 | top: 0;
83 | bottom: 0;
84 | margin: auto;
85 |
86 | /* Each of this cube's faces will be
87 | a responsive 25% of the parent */
88 | width: 25%;
89 | height: 25%;
90 | }
91 | ```
92 |
93 | 5. **Easily rotate your cube along the X, Y, or Z-axis!** — Your cube will neatly rotate about its center.
94 |
95 | ```css
96 | .my-cube {
97 | transition: transform 1500ms ease;
98 | }
99 |
100 | .my-cube:hover {
101 | transform: rotateY(359deg);
102 | }
103 | ```
104 |
105 | 6. **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.
106 |
107 | ```html
108 |
109 |
My front
110 |
My left
111 |
My back
112 |
My right
113 |
My top
114 |
My bottom
115 |
116 | ```
117 |
118 | 7. **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.
119 |
120 | 8. **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.
121 |
122 | ```css
123 | /* Make just the front blue */
124 | .my-cube > .front {
125 | background: blue;
126 | }
127 | ```
128 |
129 | ```html
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | ```
139 |
140 | ### Usage
141 |
142 | 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 ``.
143 |
144 | ```html
145 |
146 | ```
147 |
148 | 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.
149 |
150 | ```html
151 |
152 |
153 |
Hey!
154 |
Howdy!
155 |
Hi!
156 |
Hello!
157 |
Foo
158 |
Bar
159 |
160 |
161 | ```
162 |
163 | Style your cube.
164 |
165 | ```css
166 | /* Create a 200 by 200 by 200px cube... */
167 | .my-cube {
168 | width: 200px;
169 | height: 200px;
170 | /* (It is a CUBE, so the width/height are EQUAL.) */
171 | }
172 |
173 | /* ...that is red. */
174 | .my-cube > * {
175 | background: #f00;
176 | }
177 | ```
178 |
179 | ### Browser Support
180 |
181 | * Tested in Chrome 16+, Firefox 10+, Safari 5+, Android 3+, and iOS 4+
182 | * Compatible with browsers that fully support [CSS3 3D Transforms](http://caniuse.com/#search=3d%20transform).
183 |
184 | ### Intro to 3D CSS3 (Helpful Prerequisites)
185 |
186 | I recommend that you read this very helpful [intro to 3D CSS3 properties](http://24ways.org/2010/intro-to-css-3d-transforms) and this [CSS cube reference](http://desandro.github.io/3dtransforms/docs/cube.html). You are going to have a lot fewer headaches if you already understand how and when to use these CSS properties:
187 |
188 | * `perspective: 1234px;`
189 | * `transform-style: preserve-3d;`
190 | * `transform: translateZ(0);`
191 |
192 | ### Change Log
193 |
194 | **2015-03-04**
195 | * GitHub Release
196 |
197 | ### Author / License ##
198 |
199 | This project was created by Zachary Johnson. You can find him on Twitter [@zacharyjohnson](http://twitter.com/zacharyjohnson) and also at [zachstronaut.com](http://www.zachstronaut.com/).
200 |
201 | This code is released under an MIT style license. See `LICENSE.txt`.
202 |
--------------------------------------------------------------------------------
/src/qube.css:
--------------------------------------------------------------------------------
1 | /*!
2 | /**
3 | * Quintessential Responsive 3D CSS Cube
4 | * https://github.com/zachstronaut/quintessential-css-cube/
5 | * 2015-03-04 Release
6 | * MIT License
7 | *
8 | * Zachary Johnson, @zacharyjohnson
9 | * Zachstronaut LLC, http://www.zachstronaut.com
10 | *
11 | */
12 |
13 | /*
14 |
15 |
16 | Features:
17 | =========
18 | -Specify the size of your cube in a single CSS rule
19 | -Specify the color/texture of your cube with a single CSS rule
20 | -Automatic flat shading (make the cube whatever color or texture or DOM content you want, it'll be given basic shading for you via :after pseudo element)
21 | -Flexible tags for cube faces (your cube can be div tags or a ul list or whatever)
22 | -Excellent responsive design support
23 |
24 |
25 | Example Usage:
26 | A red 200 x 200 x 200px cube
27 | ============================
28 |
29 |
36 |
37 |