Show Menu
Cheatography

Odin's project CSS Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

To include CSS

Inline
As an attribute of a tag like style=­"­color: red". Avoid this!
Internal
Inside head tag use this <st­yle­></­sty­le> and add your CSS. Avoid this!
External
Use this code in head tag to add an external CSS <link rel="st­yle­she­et" type="t­ext­/cs­s" href="s­tyl­e.c­ss">

Basic ideas in CSS

Body is a selector, font and color are properties to be applied, 14px and navy are values, separated by semico­lons.
body {
font-size: 14px;
color: navy;
}
Some common units to measure in CSS, px are not necesarily pixels when zoom.
px, em pt, %, pc, cm, mm, in.
Colors in hex
For colors we use hex, start with # and divide in 3, 2 digits for red, 2 for green and 2 for blue. For example: #ff000­0=#f00
Comments
/* This is a comment*/

Text properties

font-f­amily
This is the font itself, such as Times New Roman, Arial, or Verdana.
font-size
Sets the size of the font.
font-w­eight
States whether the text is bold or not. Try: bold, normal, 100-900
font-style
Posible: italic and normal
text-decoration
Posible: underline, overline, line-t­hrough
text-t­ran­sform
Will change the case of the text. Posible: capita­lize, uppercase, lowercase, none
text-i­ndent
Property will indent the first line of a paragraph, lenght or percen­tage.
text-align
Will align the text inside an element to left, right, center, or justify.
line-h­eight
Sets the height of the lines in an element.
letter­-sp­acing
For spacing between letters.
word-s­pacing
For spacing between words.

Box Model

Properties of margins and padding

margin:
Defines the length of margin, check box model. Use length units
padding:
Defines the length of padding, check box model. Use length units
margin-top:
can add -top, -bottom, -left and -right to any of those

Borders

border­-style:
The values can be solid, dotted, dashed, double, groove, ridge, inset and outset.
border­-width:
Sets the width of the border, most commonly using pixels as a value.
border-top-width:
Can be top, right, bottom or left.
border­-color:
Sets the color.
 

Interm­edate CSS

tag.name
This dot will define a class, tag here is optional, properties will be applied to tags with attribute class=­"­nam­e".
#name
Properties here will be applied to tags with attribute id="­nam­e".
h1, p, h2
Can give properties to multiple selectors at the same time.
#top h1
Can nest selectors, makes h1 have extra poperties on #top
select­or:­pse­udo­-class
Gives properties to selectors with special perope­rties such as: "­visited links"(­vis­ited) and unvisited links(­link)
s:dyna­mic­pse­udo­class
Those apply when something happens to something, posible: active, hoover, focus.
select­or:­pse­udo­cla­ss_­childs
"­fir­st-­chi­ld" will select only the first tag, inside another tag.
margin: top right bottom left;
Margin or padding properties can be grouped like that.
padding: tb lr;
by stating two measures, first is top bottom, second is left right.
border: width color style;
Not sure if width can contain top left right and left.
font: style weight size/height family;
For the family: start with font family of choice, then som others to choice from.
select­or:­pse­udo­-el­ement
first-­letter, first-­line, self explan­atory.
select­or:­before (or after)
A pseudo­element to add content even without touching html.
the property "­con­tent: "
When using pseudo­ele­ments before or after are used, you add content, can be "any string­", open-q­uote, close-­quote or url( ). Also can add style as a block.

Specif­icity

If the selectors are the same then the last one will always take preced­enc­e.(if you select red, and then blue, you will see blue)
Calcul­ating specif­icity: HTML selectors value: 1. Class selectors value: 10. ID selector value: 100. Sum all the values in your selectors to know preced­ence. Higher value, Higher precedence

Display

display: inline
Like hiperl­inks, makes things appear directly in the same line.
display: block
Gives a break before and after the block so it will fill the entire line. This allows greater manipu­lation of padding margins and stuff.
display: none
It will not appear.
Missing tables, said they are rarely used.