css3 cores e transparencia

91
CSS3 COLORS

Upload: gabrielaspinola

Post on 26-Jun-2015

1.233 views

Category:

Design


0 download

DESCRIPTION

Veja como trabalhar com cores usando CSS3 RGB, RGBA, HSL, Transparencia e opacidade. Copyright Russ Weakley - Max Design.

TRANSCRIPT

Page 1: CSS3 cores e transparencia

CSS3COLORS

Page 2: CSS3 cores e transparencia

Before we talk about CSS3colors, we need to review

CSS2.1 colors.

Page 3: CSS3 cores e transparencia

CSS2.1Colors

Page 4: CSS3 cores e transparencia

CSS2.1 allowed colors to bedefined using six different types

of values.

Page 5: CSS3 cores e transparencia

KeywordsSix-digit hexadecimal notationThree-digit hexadecimal notationRGB numeric notationRGB percentage notationSystem colors

123456

Page 6: CSS3 cores e transparencia

1. Keywords

Page 7: CSS3 cores e transparencia

CSS2.1 allowed 17 keywords:aqua, black, blue, fuchsia, gray,green, lime, maroon, navy, olive,orange, purple, red, silver, teal,

white, and yellow.

Page 8: CSS3 cores e transparencia

Example keywords:

p { color: aqua; }p { color: black; }p { color: blue; }p { color: fuchsia; }p { color: gray; }p { color: green; }p { color: lime; }

Page 9: CSS3 cores e transparencia

2. Six-digithexadecimal

notation

Page 10: CSS3 cores e transparencia

Six-digit hexadecimal notation(#rrggbb):

p { color: #AE03FF; }

Page 11: CSS3 cores e transparencia

3. Three-digithexadecimal

notation

Page 12: CSS3 cores e transparencia

Three-digit hexadecimalnotation allows authors to

replace double ‘rr’, ‘gg’ or ‘bb’values with single values (#rgb):

p { color: #663399; }p { color: #639; }p { color: #aaff55; }p { color: #af5; }

Page 13: CSS3 cores e transparencia

The six-digit RGB notation(#rrggbb) can only by converted

into three-digit form (#rgb) if eachthe rr, gg, and bb values each

use duplicate digits. Many six-digit values cannot be converted.

p { color: #953d3d; }p { color: #34d209; } Cannot convert

Cannot convert

Page 14: CSS3 cores e transparencia

4. RGB numericnotation

Page 15: CSS3 cores e transparencia

RGB numeric notationuses 'rgb(' followed by a comma-

separated list of three integervalues, followed by ‘)’.

p { color: rgb(109, 22, 255); }

Page 16: CSS3 cores e transparencia

RGB numeric notation allowsvalues between 0 (black) and 255

(white). No unit identifier isrequired.

Page 17: CSS3 cores e transparencia

5. RGB percentagenotation

Page 18: CSS3 cores e transparencia

RGB percentage notation uses'rgb(' followed by a comma-

separated list of three percentagevalues, followed by ')'.

p { color: rgb(0%,10%,100%); }

Page 19: CSS3 cores e transparencia

RGB percentage notationallows values between 0%

(black) and 100% (white). Allvalues must include % symbol.

Page 20: CSS3 cores e transparencia

6. System colors

Page 21: CSS3 cores e transparencia

CSS2.1 allowed System colorsto be used to specify colors thatmatched the operating system's

graphic style.

p { color: ButtonFace; }

Page 22: CSS3 cores e transparencia

Note:System Colors have beendeprecated in favor of the

CSS3 UI “appearance’property for specifying the

complete look of userinterface related elements.

Page 23: CSS3 cores e transparencia

CSS3 Colors

Page 24: CSS3 cores e transparencia

With CSS3, we can now applycolours using eight new

methods:

Page 25: CSS3 cores e transparencia

Extended color keywords

Opacity

RGBA numeric notation

RGBA percentage notation

HSL notation

HSLA notation

The ‘currentColor’ keyword

The ‘transparent’ keyword

12345678

Page 26: CSS3 cores e transparencia

1. Extended ColorKeywords

Page 27: CSS3 cores e transparencia

While CSS2.1 allowed us to use17 basic color keywords, CSS3allows us to use and additional

130 extended color keywords.This is a total of 147 keywords.

Page 28: CSS3 cores e transparencia

Example color keywords:

p { color: peru; }p { color: salmon; }p { color: thisle; }p { color: firebrick; }p { color: ghostwhite; }p { color: goldenrod; }p { color: honeydew; }

Page 29: CSS3 cores e transparencia
Page 30: CSS3 cores e transparencia
Page 31: CSS3 cores e transparencia
Page 32: CSS3 cores e transparencia
Page 33: CSS3 cores e transparencia
Page 34: CSS3 cores e transparencia
Page 35: CSS3 cores e transparencia
Page 36: CSS3 cores e transparencia
Page 37: CSS3 cores e transparencia
Page 38: CSS3 cores e transparencia
Page 39: CSS3 cores e transparencia
Page 40: CSS3 cores e transparencia

Quick tip:Do you have trouble spelling the

keyword gray/grey?Well, CSS3 color keywords have

got you covered. They includegray, grey, darkgrey and

darkgray.

Page 41: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8, 9

SupportedYes

Yes

Yes

Yes

Yes

Page 42: CSS3 cores e transparencia

2. Opacity

Page 43: CSS3 cores e transparencia

Opacity allows us to dictate theopacity/transparency of

elements.

Page 44: CSS3 cores e transparencia

Opacity values range from 0 (or0.0), which is fully transparent to1 (or 1.0) which is 100% opaque.

p { opacity: 0.3; }

Page 45: CSS3 cores e transparencia

The opacity value must be anumber, which is zero or more

digits followed by a dot (.)followed by one or more digits.

For example:

0.5.5

Page 46: CSS3 cores e transparencia

Be aware that this property willset the opacity for the elementand all of it’s child elements.

Page 47: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 48: CSS3 cores e transparencia

3. RGBA numericnotation

Page 49: CSS3 cores e transparencia

With CSS3 we can add an alphachannel to RGB values. Thisallows us to set our colors to

specific levels of opacity.

Page 50: CSS3 cores e transparencia

While the ‘opacity’ propertysets the opacity/transparency ofentire elements, RGBA is used

to set the opacity of colorvalues only.

Page 51: CSS3 cores e transparencia

RGBA numeric notationuses 'rgba(' followed by a

comma-separated list of threeinteger values, followed by analpha value followed by a ‘)’.

p { color: rgba(100, 66, 255, 1); }

Page 52: CSS3 cores e transparencia

The three integer values must bebetween 0 (black) and 255(white). No unit identifier is

required. For example:

2550

Page 53: CSS3 cores e transparencia

This alpha value must be anumber, which is zero or more

digits followed by a dot (.)followed by one or more digits.

For example:

0.5.5

Page 54: CSS3 cores e transparencia

An alpha value of 1 meansthe color will be fully opaque(displayed as a solid color).An alpha value of 0.5 will be

half opaque.

Page 55: CSS3 cores e transparencia

You should always include abackup for browsers that do not

support this property.

p{

color: rgb(100, 66, 255); color: rgba(100, 66, 255, 0.5);

}

Page 56: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 57: CSS3 cores e transparencia

4. RGBA percentagenotation

Page 58: CSS3 cores e transparencia

RGBA percentage notation uses 'rgba(' followed by a

comma-separated list of threepercentage values, followed byan alpha value followed by a ‘)’.

p { color: rgba(10%, 6%, 20%, 1); }

Page 59: CSS3 cores e transparencia

The three percentage valuesmust be between 0% (black) and

100% (white). All values mustinclude % symbol. For example:

100%0%

Page 60: CSS3 cores e transparencia

This alpha value must be anumber, which is zero or more

digits followed by a dot (.)followed by one or more digits.

For example:

0.5.5

Page 61: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 62: CSS3 cores e transparencia

5. HSL notation

Page 63: CSS3 cores e transparencia

HSL notation allows us to definecolors using hue, saturation

and lightness.

Page 64: CSS3 cores e transparencia

HSL notation is written like this:

p { color: hsl(280,100%,50%); }

Page 65: CSS3 cores e transparencia

The first value is for Hue andmust be a integer value between

0 and 359.

p { color: hsl(280,100%,50%); }

Page 66: CSS3 cores e transparencia

The second value is forSaturation and must be defined

as a percentage value.

p { color: hsl(280,100%,50%); }

Page 67: CSS3 cores e transparencia

The third value is Lightnessand must also be defined as a

percentage value.

p { color: hsl(280,100%,50%); }

Page 68: CSS3 cores e transparencia

These three HSL values mustbe separated by commas.

Whitespace after the commasis optional.

p { color: hsl(280,100%,50%); }

Page 69: CSS3 cores e transparencia

You should always include abackup color that is not HSL for

older browsers.

p {

color: rgb(85,0,128);color: hsl(280,100%,50%);

}

Page 70: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 71: CSS3 cores e transparencia

6. HSLA notation

Page 72: CSS3 cores e transparencia

Like RGBA, we can add an alphachannel to HSL values. Thisallows us to set our colors to

specific levels of opacity.

Page 73: CSS3 cores e transparencia

First of all, we need to change theHSL to HSLA:

p { color: hsla(280,100%,50%); }

Page 74: CSS3 cores e transparencia

Then, we need to add a newvalue at the end of the threecomma-separated values.

p { color: hsla(280,100%,50%,0.5); }

Page 75: CSS3 cores e transparencia

The opacity value must be anumber, which is zero or more

digits followed by a dot (.)followed by one or more digits.

For example:

0.5.5

Page 76: CSS3 cores e transparencia

You should always include abackup color that is not HSL or

HSLA for older browsers.

p {

color: rgb(85,0,128);color: hsla(280,100%,50%,0.5);

}

Page 77: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 78: CSS3 cores e transparencia

Why use HSLor HSLA?

Page 79: CSS3 cores e transparencia

From the browsers point of view,there is no difference between

values defined in RGBAor HSLA.

Page 80: CSS3 cores e transparencia

Some designers find it easierto choose and adjust colors

using HSLA.

Page 81: CSS3 cores e transparencia

7. The ‘currentColor’keyword

Page 82: CSS3 cores e transparencia

CSS1 and CSS2 definedthe initial value of the ‘border-

color’ property to be “thevalue of the ‘color’ property” .

However, there is nocorresponding keyword.

Page 83: CSS3 cores e transparencia

We had no way of specifying aborder-color to match the color.

p{

color: red; border-width: 1px; border-style: solid;border-color: “the value of the ‘color’ property”;

}

Page 84: CSS3 cores e transparencia

CSS3 allows us to thecurrentColor keyword for this:

p{

color: red; border-width: 1px; border-style: solid;border-color: currentColor;

}

Page 85: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 8, 9, 10

Opera 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 86: CSS3 cores e transparencia

8. The ‘transparent’keyword

Page 87: CSS3 cores e transparencia

CSS1 introduced the ‘transparent’value for the background-color

property.

Page 88: CSS3 cores e transparencia

CSS2 allowed the ‘transparent’value to be applied to the ‘border-

color’ property.

Page 89: CSS3 cores e transparencia

CSS3 allows the ‘transparent’keyword to be applied to any

properties that acceptsa ‘color’ value.

p { color: transparent; }

Page 90: CSS3 cores e transparencia

BrowserFirefox 3.6, 4

Safari 4, 5

Chrome 9, 10

Opera 10, 11

IE 6, 7, 8

IE 9

SupportedYes

Yes

Yes

Yes

No

Yes

Page 91: CSS3 cores e transparencia

Russ WeakleyMax Design

Site: maxdesign.com.auTwitter: twitter.com/russmaxdesignSlideshare: slideshare.net/maxdesignLinkedin: linkedin.com/in/russweakley