95
5 WAYS TO CUSTOMIZE YOUR WEBSITE WITH CSS December 13, 2012 #5WaysCSS

5 Ways to Customize Your Website with CSS

Embed Size (px)

DESCRIPTION

CSS is one of the primary building blocks of the Internet. But to the average person, it may just look like a bunch of random code. Wouldn't you like to know how to understand that code so you can make changes to your website without forking over hundreds of dollars to a web designer?

Citation preview

Page 1: 5 Ways to Customize Your Website with CSS

5 WAYS TO CUSTOMIZE YOUR WEBSITE WITH CSS

December 13, 2012 #5WaysCSS

Page 2: 5 Ways to Customize Your Website with CSS

WHO’S THIS GUY?

#5WaysCSS

Maurice Cherry Creative Principal, 3eighteen media

[email protected]

@3eighteenmedia

Page 3: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 4: 5 Ways to Customize Your Website with CSS

THE RUNDOWN • What is CSS? • 5 Ways to Customize Your Website With CSS • Wrap-Up • Questions

#5WaysCSS

Page 5: 5 Ways to Customize Your Website with CSS

WHAT IS CSS?

0

Page 6: 5 Ways to Customize Your Website with CSS

CSS = CASCADING STYLE SHEET • A style sheet language • A file that contains style rules which tell the

browser how to present HTML elements • CSS Example:

h1 { color: red; background-color: black}

#5WaysCSS

Page 7: 5 Ways to Customize Your Website with CSS

CSS = CASCADING STYLE SHEET

#5WaysCSS

Page 8: 5 Ways to Customize Your Website with CSS

CSS = CASCADING STYLE SHEET

#5WaysCSS

Page 9: 5 Ways to Customize Your Website with CSS

RULES, RULES, RULES

h1 { color: red; background-color: black; }

#5WaysCSS

Page 10: 5 Ways to Customize Your Website with CSS

RULES, RULES, RULES

h1 { color: red; background-color: black; }

#5WaysCSS

Page 11: 5 Ways to Customize Your Website with CSS

RULES, RULES, RULES

h1 { color: red; background-color: black; }

#5WaysCSS

selector

Page 12: 5 Ways to Customize Your Website with CSS

RULES, RULES, RULES

h1 { color: red; background-color: black; }

#5WaysCSS

declaration

Page 13: 5 Ways to Customize Your Website with CSS

RULES, RULES, RULES

h1 { color: red; background-color: black; }

#5WaysCSS

property property

value value

Page 14: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 15: 5 Ways to Customize Your Website with CSS

CASCADE (THE “C” IN “CSS”) • The cascade tells browsers the order in which

to process rules in CSS stylesheets to prevent conflicts and collisions.

• Browser, User, Author • External, Internal, Inline

#5WaysCSS

Page 16: 5 Ways to Customize Your Website with CSS

CASCADE (THE “C” IN “CSS”)

#5WaysCSS

Page 17: 5 Ways to Customize Your Website with CSS

CASCADE (THE “C” IN “CSS”)

#5WaysCSS

Page 18: 5 Ways to Customize Your Website with CSS

INHERITANCE • Inheritance means that child elements will

inherit properties from their parent element. • Inheritance works on a property by property

basis.

#5WaysCSS

Page 19: 5 Ways to Customize Your Website with CSS

INHERITANCE

#5WaysCSS

Page 20: 5 Ways to Customize Your Website with CSS

INHERITANCE CSS body { color: blue; } HTML <body> <h1>This is some text. What color am I?</h1> </body>

#5WaysCSS

Page 21: 5 Ways to Customize Your Website with CSS

INHERITANCE CSS body { color: blue; } HTML <body> <! -- parent element --> <h1>This is some text. What color am I?</h1> <!– child element --> </body>

NOTE: NOT ALL PROPERTIES ARE INHERITABLE, BUT INHERITANCE CAN BE FORCED.

#5WaysCSS

Page 22: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 23: 5 Ways to Customize Your Website with CSS

BEFORE YOU EDIT YOUR CSS… • Test your CSS in a “code sandbox” first. • Save a copy of the original .css file!

#5WaysCSS

Page 24: 5 Ways to Customize Your Website with CSS

BEFORE YOU EDIT YOUR CSS… • Codepen: http://codepen.io • CSSDesk: http://cssdesk.com • Dabblet: http://dabblet.com • JS Bin: http://jsbin.com • JSFiddle: http://jsfiddle.net • Tinkerbin: http://tinkerbin.com

#5WaysCSS

Page 25: 5 Ways to Customize Your Website with CSS

BOXES

1

Page 26: 5 Ways to Customize Your Website with CSS

EVERYTHING IN HTML IS A BOX

#5WaysCSS

Page 27: 5 Ways to Customize Your Website with CSS

EVERYTHING IN HTML IS A BOX

#5WaysCSS

• Links: <a href=“index.html”>Click here</a> • Text: <p>This is some text.</p> • Images: <img src=“image.jpg” /> • Boxes: several of these

• <div>, <blockquote>, <header>, <section>, <figure>, <aside>, <footer>, etc.

Page 28: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 29: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 30: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 31: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 32: 5 Ways to Customize Your Website with CSS

MARGIN PROPERTIES • margin-top, margin-right, margin-bottom, margin-left • CSS Example:

h1 { margin-top: 10px; margin-bottom: 10px; } • Remember: margins control space

outside of the border.

#5WaysCSS

Page 33: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 34: 5 Ways to Customize Your Website with CSS

• border-top-width, border-top-style, border-top-color, etc. • Shorter property: border-top, border-bottom, etc. • Default width: 1 pixel (px) • Default style: solid • Default color: black

• CSS Example: h1 { border-left-width: 10px; border-left-color: yellow; border-left-style: solid }

BORDER PROPERTIES

#5WaysCSS

Page 35: 5 Ways to Customize Your Website with CSS

• border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius

• Shorter property: border-radius • Creates rounded borders on boxes • CSS Example:

h1 { border-top-left-radius: 10px; background-color: red; } /* This will round the top left corner. */

BORDER PROPERTIES (CSS3)

#5WaysCSS

Page 36: 5 Ways to Customize Your Website with CSS

BORDER PROPERTIES (CSS3)

#5WaysCSS

Page 37: 5 Ways to Customize Your Website with CSS

• box-shadow • Creates drop shadows for boxes, can be stacked to create

multiple shadows • CSS Example:

p { box-shadow: 10px 10px 5px #888; } /* This creates a drop shadow that is underneath the box and to the right. */

BORDER PROPERTIES (CSS3)

#5WaysCSS

Page 38: 5 Ways to Customize Your Website with CSS

BORDER PROPERTIES (CSS3)

#5WaysCSS

Page 39: 5 Ways to Customize Your Website with CSS

#5WaysCSS

Page 40: 5 Ways to Customize Your Website with CSS

PADDING PROPERTIES • padding-top, padding-right, padding-bottom, padding-left

• CSS Example: h1 { padding-left: 10px; padding-right: 5px; }

• Remember: padding controls space inside of the border.

#5WaysCSS

Page 41: 5 Ways to Customize Your Website with CSS

OTHER BOX PROPERTIES • height (number with units of length or percentage) • width (number with units of length or percentage) • background-color (color name, hexadecimal code, RGB color

code) – Controls the background color of an element – Example: h1 { background-color: red; }

/* The background of this HTML element will be red. */

#5WaysCSS

Page 42: 5 Ways to Customize Your Website with CSS

TRY PUTTING IT ALL TOGETHER! • CSS

div { background-color: red; height: 200px; width: 200px; border: 2px solid blue; padding: 20px; margin: 40px; }

• HTML <div>This is an example of what you can do!</div>

#5WaysCSS

Page 43: 5 Ways to Customize Your Website with CSS

TEXT

2

Page 44: 5 Ways to Customize Your Website with CSS

TEXT AND FONT PROPERTIES • These apply to all text elements in HTML • Example: <p>, <blockquote>, <cite>,

<h1>, <h2>, etc.

#5WaysCSS

Page 45: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES • color, letter-spacing, text-align, text-

decoration, text-indent, text-transform, word-spacing

#5WaysCSS

Page 46: 5 Ways to Customize Your Website with CSS

• Color values – color names (red, black, yellow, etc.) – hexadecimal codes (#FF0000, #BADA55, etc.) – RGB color code (rgb(255,0,0))

• Example: h1 { color: rgb(255,0,0); } /* red */

TEXT PROPERTIES – COLOR

#5WaysCSS

Page 47: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – LETTER-SPACING • Adjusts the space between letters

– Values are numbers with units of length

• Example: h1 { letter-spacing: 0.5em; }

#5WaysCSS

Page 48: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – LETTER-SPACING

#5WaysCSS

Page 49: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-ALIGN • Controls the alignment of text within its

bounding box – Values are left, right, center, justify

• Example: h1 { text-align: center; }

#5WaysCSS

Page 50: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-ALIGN

#5WaysCSS

Page 51: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-DECORATION • Controls the “decoration” of text

– Values are underline, overline, line-through, blink

• Example: h1 { text-decoration: underline; } • Not to be confused with the border-bottom

property!

#5WaysCSS

Page 52: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-DECORATION

#5WaysCSS

Page 53: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-INDENT • Indents the first line of text in an element

– Values are numbers or percentages • Example: h1 { text-indent: 1em; }

#5WaysCSS

Page 54: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-INDENT

#5WaysCSS

Page 55: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-TRANSFORM • Controls the case of text

– Values are uppercase, lowercase, capitalize • Example: h1 { text-transform: capitalize; } • Capitalize is the same as title case

#5WaysCSS

Page 56: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – TEXT-TRANSFORM

#5WaysCSS

Page 57: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – WORD-SPACING • Controls the spacing between words

– Values are numbers with units of length • Example: h1 { word-spacing: 5px; }

#5WaysCSS

Page 58: 5 Ways to Customize Your Website with CSS

TEXT PROPERTIES – WORD-SPACING

#5WaysCSS

Page 59: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES • font-family, font-size, font-style, font-variant,

font-weight

#5WaysCSS

Page 60: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES • Shorter property: font

#5WaysCSS

Page 61: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-FAMILY • Changes the font

– Values are names of fonts, usually in a font stack, with a generic font family at the end

• Example: h1 { font-family: Arial, Helvetica, sans-serif; }

• Web fonts (Google Web Fonts, Typekit, etc.) #5WaysCSS

Page 62: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-FAMILY

#5WaysCSS

Page 63: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-SIZE • Changes the size of the font

– Values are numbers with units of length or percentages

• Example: h1 { font-size: 30px; }

#5WaysCSS

Page 64: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-SIZE

#5WaysCSS

Page 65: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-STYLE • Changes the style of the font

– Values are normal, italic, or oblique

• Example: h1 { font-style: italic; } • Italic and oblique look the same, but aren’t; when in

doubt go with italic

#5WaysCSS

Page 66: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-STYLE

#5WaysCSS

Page 67: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-VARIANT • Changes the variance of the font

– Values are normal or small-caps

• Example: h1 { font-variant: small-caps; }

#5WaysCSS

Page 68: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-VARIANT

#5WaysCSS

Page 69: 5 Ways to Customize Your Website with CSS

• Changes the weight of the font – Values are numbers (100-900), normal, lighter,

bold, bolder

• Example: h1 { font-weight: bold; } • You’ll really only use normal and bold.

FONT PROPERTIES – FONT-WEIGHT

#5WaysCSS

Page 70: 5 Ways to Customize Your Website with CSS

FONT PROPERTIES – FONT-WEIGHT

#5WaysCSS

Page 71: 5 Ways to Customize Your Website with CSS

LINKS

3

Page 72: 5 Ways to Customize Your Website with CSS

THE RUNDOWN HTML <a href=“page.html”>Click here!</a> CSS Example a { color: green; }

#5WaysCSS

Page 73: 5 Ways to Customize Your Website with CSS

• :link (normal state) • :visited (a link the user has already visited) • :hover (a link when the user mouses over it) • :active (a link when it’s clicked) • Examples: a:hover { color:red; }

a:visited { color:orange; }

PSEUDO-CLASSES

#5WaysCSS

Page 74: 5 Ways to Customize Your Website with CSS

• CSS box properties and text/font properties apply to links also!

• Experiment, mix and match, and find your own stylish combos!

LINKS ARE TEXT AND BOXES, TOO!

#5WaysCSS

Page 75: 5 Ways to Customize Your Website with CSS

JUST A FEW THINGS YOU CAN DO…

#5WaysCSS

Page 76: 5 Ways to Customize Your Website with CSS

• Link Pseudo-Classes (In Order): http://css-tricks.com/snippets/css/link-pseudo-classes-in-order

• Button Maker: http://css-tricks.com/examples/ButtonMaker • CSS Button Generator: http://www.cssbuttongenerator.com • CSS Button | CSS Generator: http://www.cssbutton.me/generator • CSS Gradient Button: http://cssgradientbutton.com • CSS3 Button Generator: http://css3button.net

CSS LINK RESOURCES

#5WaysCSS

Page 77: 5 Ways to Customize Your Website with CSS

IMAGES

4

Page 78: 5 Ways to Customize Your Website with CSS

HOW IMAGES ARE USED IN CSS • background-image (use for any element) • list-style-image (used for <ul> elements) • opacity (controls transparency)

#5WaysCSS

Page 79: 5 Ways to Customize Your Website with CSS

BACKGROUND-IMAGE PROPERTY • Uses an image in the background of an element • Image repeats horizontally and vertically by default • Repetition can be changed with background-repeat

property; position can be changed with background-position property

• Example: h1 { background-image: url(‘image.jpg); }

#5WaysCSS

Page 80: 5 Ways to Customize Your Website with CSS

BACKGROUND-IMAGE PROPERTY

#5WaysCSS

Page 81: 5 Ways to Customize Your Website with CSS

BACKGROUND-REPEAT PROPERTY • Controls horizontal or vertical repetition of

background-image – Values are repeat-x, repeat-y, no-repeat, repeat

• Example: h1 { background-repeat: repeat-x; } /* The background image will repeat horizontally. */

#5WaysCSS

Page 82: 5 Ways to Customize Your Website with CSS

BACKGROUND-REPEAT PROPERTY

#5WaysCSS

Page 83: 5 Ways to Customize Your Website with CSS

BACKGROUND-POSITION PROPERTY • Controls position of the background-image relative to

the element’s height and width – Values are repeat-x, repeat-y, no-repeat, repeat

• Example: h1 { background-repeat: repeat-x; } /* The background image will repeat horizontally. */

#5WaysCSS

Page 84: 5 Ways to Customize Your Website with CSS

BACKGROUND-POSITION PROPERTY

#5WaysCSS

Page 85: 5 Ways to Customize Your Website with CSS

LIST-STYLE-IMAGE PROPERTY • Changes the bullets in a bulleted list to an image of

your choice – Value is the URL of your image

• Example: ul { list-style-image: url(‘bullet.gif); } /* The bullets in the <ul> list will be replaced with bullet.gif. Use a small image. */

#5WaysCSS

Page 86: 5 Ways to Customize Your Website with CSS

LIST-STYLE-IMAGE PROPERTY

#5WaysCSS

Page 87: 5 Ways to Customize Your Website with CSS

OPACITY PROPERTY • Changes the transparency of your image

–Value is a decimal number from 0.00 to 1.00

• Example: img { opacity: 0.5; } /* This image will have 50% transparency. */

• Text is also affected by opacity, so use carefully! • Can be used in conjunction with pseudo-classes

#5WaysCSS

Page 88: 5 Ways to Customize Your Website with CSS

OPACITY PROPERTY

#5WaysCSS

Page 89: 5 Ways to Customize Your Website with CSS

IMAGES ARE BOXES, TOO! • CSS box properties apply to images also!

–padding –margin –border –background-color

• Experiment to find your own combinations!

#5WaysCSS

Page 90: 5 Ways to Customize Your Website with CSS

ANIMATION

5

Page 91: 5 Ways to Customize Your Website with CSS

ADVANCED, BUT IMPRESSIVE • 2D Transforms • 3D Transforms • Transitions • Animations NOTE: Support is mixed across browsers.

#5WaysCSS

Page 92: 5 Ways to Customize Your Website with CSS

CSS ANIMATION RESOURCES • 2D Transforms: http://westciv.com/tools/transforms/index.html • 3D Transforms: http://westciv.com/tools/3Dtransforms/index.html • CSS Transition: http://www.css3maker.com/css3-transition.html • CSS Animation: http://www.css3maker.com/css3-animation.html

#5WaysCSS

Page 93: 5 Ways to Customize Your Website with CSS

WRAP-UP • CSS is a powerful language that controls the presentation of

nearly every element on a web page. • Save your main CSS file before experimenting on your

website. • Learn the basics by practicing on code playgrounds. • Don’t reinvent the wheel – use code generators where

necessary to save time!

#5WaysCSS

Page 94: 5 Ways to Customize Your Website with CSS

#5WaysCSS

http://eepurl.com/sVmz9

Page 95: 5 Ways to Customize Your Website with CSS

QUESTIONS? #5WaysCSS

[email protected] | @3eighteenmedia