Except where otherwise noted, the contents of this document are Copyright 2012–2013 Morgan Doocy. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
line-height
p {
font-size: 18px;
line-height: 3em;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut leo enim. Curabitur eleifend interdum enim, mattis dignissim lacus placerat gravida. Donec et eros et leo gravida condimentum et non lorem. Morbi velit quam, imperdiet a sodales in, laoreet in lectus. Vestibulum auctor massa sit amet metus ultricies nec vestibulum lacus adipiscing. Duis hendrerit malesuada diam ac porta.
line-height ≈ length of line (in ems) × 5% ≈ size of body font (in ems) × 1.5| property | description |
|---|---|
vertical-align
|
vertical offset from the line of text |
line-height
|
distance between lines of text |
word-spacing
|
distance between words |
letter-spacing
|
distance between letters |
text-indent
|
indents the first line only of a paragraph |
text-transform
|
alters the capitalization of text |
font-variant
|
switches to (or simulates) small caps variant |
white-space
|
controls how whitespace is handled within an element |
| Complete list of text properties | |
vertical-align property
Sphinx
þ
| property | description |
|---|---|
vertical-align
|
specifies inline element’s vertical position on the line of text;
can be top, middle, bottom, baseline (default), sub, super, text-top, text-bottom, or a length value or %
|
h1 { font-size: 5em; word-spacing: -.05em; letter-spacing: -.05em; }
h2 { letter-spacing: .03em; word-spacing: -.075em; }
abbr { font-size: 80%; letter-spacing: .075em; }
The W3C standards HTML, for content, and CSS for presentation.
text-indent property
p {
text-indent: 2em;
margin: 0;
}
p:first-child {
text-indent: 0;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ut leo enim. Curabitur eleifend interdum enim, mattis dignissim lacus placerat gravida. Donec et eros et leo gravida condimentum et non lorem.
Morbi velit quam, imperdiet a sodales in, laoreet in lectus. Vestibulum auctor massa sit amet metus ultricies nec vestibulum lacus adipiscing. Duis hendrerit malesuada diam ac porta.
text-indent or margin-top/margin-bottom (never both!)
text-indent, don’t indent the first paragraph in each section.text-transform property
dt.charactername {
text-transform: uppercase;
font-size: .8em;
letter-spacing: .075em;
}
uppercase, lowercase, capitalize (Title Caps)uppercase and reduce font size for mini-capsfont-variant property switches to (or poorly simulates) Small CapsStack: A list of similar, cross-platform, fallback typefaces in order of preference
body {
font-family: Garamond, "Hoefler Text", "Times New Roman", Times, serif;
}
h2 {
font-family: Garamond, "Hoefler Text", Palatino, "Palatino Linotype", serif;
}
@font-face {
font-family: 'Josefin Sans'; font-style: italic; font-weight: 100;
src: local('Josefin Sans Thin Italic'), local('JosefinSans-ThinItalic'),
url('http://themes.googleusercontent.com/static/fonts/josefinsans/v1/s7-P1gqRNRNn-YWdOYnAOUU4uDXlcIT8_0bdRGwoYww.woff')
format('woff');
}
h2 {
font-family: 'Josefin Sans', sans-serif;
font-weight: 100;
font-style: italic;
}
@import url(http://fonts.googleapis.com/css?family=Josefin+Sans:100italic,700);
h1 { color: #484848; /* embossed look */
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75); }
h2 { text-shadow: rgba(0, 0, 0, .5) .25em .25em .25em; /* drop shadow */
-webkit-text-stroke: 1px red; /* outline */
opacity: .5; /* transparency */ }
text-shadow: creates a drop shadow effect-webkit-text-stroke (Safari/Chrome only): creates a text outlineopacity: transparency (0.0–1.0); can be applied to more than just type
strong {
font-family: 'Open Sans';
font-weight: 100;
}
normal and bold.(*) Not available; rounded to nearest available weight
.before, .after {
margin: 0;
background-color: lightblue;
}
p {
font-size: 1em; /* default */
margin-top: 1em; /* default */
margin-bottom: 1em; /* default */
}
p, h2 {
line-height: 1em;
background-color: fuchsia;
}
h2 {
font-size: 1.5em; /* default */
margin-top: 1em;
margin-bottom: 1em;
}
Sphinx
Letterpress
margin, width, border, etc. specified in ems are relative to the font-size of that element.
.before, .after {
margin: 0;
background-color: lightblue;
}
p {
font-size: 1em; /* default */
margin-top: 1em; /* default */
margin-bottom: 1em; /* default */
}
p, h2 {
line-height: 1em;
background-color: fuchsia;
}
h2 {
font-size: 1.5em; /* default */
margin-top: 0.333em; /* = .5em/1.5em */
margin-bottom: 0.666em; /* = 1em/1.5em */
}
Sphinx
Letterpress
margin: 1em at font-size: 1em is equal to margin: .6667em at font-size: 1.5em
body {
font-size: 62.5%;
}
h2 {
font-size: 2em;
}
16px) are still common but cause problems in mobile browsers
pt) rarely usedDecide on a sequence (“scale”) of sizes:
Upcoming CSS3 standard includes features for affine transformations and animation.
transform propertyselector {
-webkit-transform: function1, function2, ...;
-moz-transform: function1, function2, ...;
-ms-transform: function1, function2, ...;
-o-transform: function1, function2, ...;
transform: function1, function2, ...;
}
translate, rotate, scale, skewtransform property does not work in most browsers
-webkit, -moz, -o, -ietranslate functionselector {
-prefix-transform: translate(x-dimension, y-dimension);
}
#original, #transformed { position: absolute; left: 0; }
#transformed {
/* (browser-prefixed properties omitted) */
transform: translate(50px, 25%);
}
pt, px, %, em, in, etc.position: absolute;
left: x-dimension; top: y-dimension;scale functionselector {
-prefix-transform: scale(x-factor, y-factor);
}
#transformed {
/* (browser-prefixed properties omitted) */
transform: scale(.5, 1.25);
}
1.0 = 100%, 0.5 = 50%, etc.rotate functionselector {
-prefix-transform: rotate(angle);
}
#transformed {
/* (browser-prefixed properties omitted) */
transform: rotate(30deg);
}
deg, grad, rad, or turnskew functionselector {
-prefix-transform: skew(x-angle, y-angle);
}
#transformed {
/* (browser-prefixed properties omitted) */
transform: skew(-45deg, 10deg);
}
deg, grad, rad, or turntransform-originselector {
-prefix-transform-origin: x-dimension y-dimension;
}
#transformed {
/* (browser-prefixed properties omitted) */
transform-origin: left bottom;
transform: rotate(-75deg);
}
transform functions are appliedpt, px, %, etc.) or a keyword: left/center/right, top/center/bottom50% 50% (= center center)In recent & upcoming browsers, can specify 3-dimensional transforms:
Interactive examples:
selector {
-prefix-transform: rotateX(angle);
-prefix-transform: rotateY(angle);
}
#transformedX {
/* (browser-prefixed properties omitted) */
transform: rotateX(30deg);
}
#transformedY {
/* (browser-prefixed properties omitted) */
transform: rotateY(-45deg);
}
deg, grad, rad, or turnselector {
-prefix-transform: translateZ(dimension);
-prefix-transform: scaleZ(factor);
}
#translatedZ {
/* (browser-prefixed properties omitted) */
transform: translateZ(-5em);
}
#scaledZ {
/* (browser-prefixed properties omitted) */
transform: rotateY(-45deg)
scaleZ(.1) translateZ(100em);
}
translateZ alters “depth” or distance from viewer (distance from origin if rotated)scaleZ primarily affects scale of translateZ dimensions (.1 × 100em = 10em)selector {
-prefix-perspective: pixels;
}
/* (browser-prefixed properties omitted) */
#container {
border: solid 2px blue;
background-color: gray;
perspective: ;
}
#transformed {
transform: rotateY(-45deg) translateZ(-5em);
}
transition propertyselector {
-prefix-transition: property duration timing function delay;
}
/* (browser-prefixed properties omitted) */
#transformed {
transform: rotate(-45deg);
transition: transform 2s ease-in-out,
background-color .5s ease 2s;
}
#transformed:hover {
font-size: 200%;
background-color: blue;
transform: rotate(10deg) scale(1.5);
}
font-size is not animated above)The timing function specifies how the transition will speed up and slow down across its lifecycle.
| timing function | description |
|---|---|
ease (default) |
quick start, gradual finish |
ease-in |
slow start, steady build to max speed |
ease-out |
start at max speed, steady slow to finish |
ease-in-out |
slow start, increase to max speed, slow to finish |
linear |
constant speed for entire duration |
cubic-bezier(n, n, n, n) |
specify your own custom Bézier curve function |
#foo {
width: 5em; height: 5em;
transition: width 1s ease, height 1s ease,
font-size 1s ease;
}
.enlarged {
width: 7.5em; height: 7.5em;
font-size: 1.5em;
}
$(document).ready(function() {
$('#foo').click(function() {
$(this).addClass('enlarged');
});
});
transform-style
#foo, #bar {
transition: transform 1s ease;
transform-style: ;
}
#foo:hover, #bar:hover {
transform: rotateY(-135deg);
}
#bar {
backface-visibility: hidden;
}
transform-style changes whether children are rendered in 2D or 3D
backface-visibility changes whether an element is visible from behindbackface-visibility, but it needs to be.
#foo {
-webkit-transition: -webkit-transform 1s ease;
-moz-transition: -moz-transform 1s ease;
-ms-transition: -ms-transform 1s ease;
-o-transition: -o-transform 1s ease;
transition: transform 1s ease;
}
#foo.altered {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
$('#foo').parent().css({
'-webkit-perspective': '600px',
'-moz-perspective': '600px',
'-ms-perspective': '600px',
'-o-perspective': '600px',
'perspective': '600px'
});
transform inside transition must match that of transition.
Layouts that adjust themselves (“respond”) to optimize for screen size

/* Three-column fluid layout with gutters */ /* 32% + 2% + 32% + 2% + 32% = 100% */ .col { float: left; width: 32%; margin-right: 2% } /* remove extra 2% at right of every 3rd column */ .col:nth-child(3n) { margin-right: 0; }
<head> ... <link rel="stylesheet" href="default.css" type="text/css" media="screen"> <link rel="stylesheet" href="mobile.css" type="text/css" media="screen and (max-width: 800px)"> <link rel="stylesheet" href="large.css" type="text/css" media="screen and (min-width: 1200px)"> ... </head>
/* default.css - 3-column */
.col { float: left; width: 32%; margin: 0 2% 1em 0; }
.col:nth-child(3n) { margin-right: 0 }
/* mobile.css - switch to 2-column */ .col { width: 48%; margin-right: 4%; } /* 48% + 4% + 48% = 100% */ .col:nth-child(3n) { margin-right: 4% } /* "undo" the 3n rule from default.css */ .col:nth-child(2n) { margin-right: 0 }
| 240px | 320px | 480px | 768px | 1024px | 1200px |
|---|---|---|---|---|---|
| small phone | iPhone portrait |
iPhone landscape small tablet portait |
iPad portrait |
iPad landscape standard desktop |
wide desktop |
<nav> <ul> <li><a href="/">Home</a></li> <li><a href="/blog/">Blog</a></li> <li><a href="/about/">About</a></li> </ul> <select> <option value="/">Home</option> <option value="/blog/">Blog</option> <option value="/about/">About</option> </select> </nav>
/* default.css */
nav ul { display: block; }
nav select { display: none; }
/* mobile.css */
nav ul { display: none; }
nav select { display: block; }
// scripts.js // handle dropdown nav using JS $('nav select').change(function() { window.location = this.value; });
select dropdown at smaller sizeswindow.location to manually navigate