+ All Categories
Home > Documents > One of Those Things You Have To Know -...

One of Those Things You Have To Know -...

Date post: 16-May-2018
Category:
Upload: vuongnguyet
View: 214 times
Download: 1 times
Share this document with a friend
64
CSS Data Types One of Those Things You Have To Know © 2013 R. Scott Granneman Last updated 2105-01-24 You are free to use this work, with certain restrictions. For full licensing information, please see the last slide/page. R. Scott Granneman Jans Carton 1.3
Transcript
Page 1: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

CSS Data TypesOne of Those Things You Have To Know

© 2013 R. Scott GrannemanLast updated 2105-01-24

You are free to use this work, with certain restrictions.For full licensing information, please see the last slide/page.

R. Scott Granneman

Jans Carton

1.3

Page 2: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Notes & URLs for this presentation can be found…

» underneath the link to this slide on granneman.com » at files.granneman.com/presentations/webdev/CSS-

Data-Types.txt

Page 3: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Basics

Page 4: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

What’s a data type?

A way to classify various kinds of data that are allowed as values for CSS properties

Page 5: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<angle>

<blend-mode>

<color>

<frequency>

<gradient>

<image>

<integer>

<length>

<number>

<percentage>

<position>

<ratio>

<resolution>

<shape>

<string>

<time>

<timing-function>

<uri>

<user-ident>

Page 6: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Images

Page 7: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<url>

<gradient>

<image>

Page 8: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<url>

Represents a pointer to a web resource

Covered later in Styling Shapes

Page 9: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<gradient>

Represents a CSS <image> made from a progressive transition between two or more colors

Covered later in Styling Shapes

Page 10: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<image>

Represents a 2D image, either static (<url>) or dynamically generated (<gradient>)

Covered later in Styling Shapes

Page 11: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Text

Page 12: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<string>

Represents a quoted string of Unicode characters

Covered earlier in CSS Selectors

Page 13: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Wide Usage

Page 14: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<integer>

<number>

<percentage>

<length>

<color>

Page 15: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<integer>

Represents a positive or negative integer number: 1 or several decimal digits (0 to 9), optionally preceded by a single + or −

No units after <integer>!

All <integer>s are <number>s, but not all <number>s are <integer>s

Page 16: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Valid Invalid

7 7.0

+7 +-7

-7 \37

0 七

Seven

Only 1 + or -

Escaped Unicode

Non-Arabic

Page 17: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<integer> 3 1 1 1 Y Y

Page 18: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<number>

Represents a number, either <integer> or fractional

No units after <number>!

Page 19: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Valid Invalid

7 7.

7.7 +-7.7

+7.7 7.7.7

-7.7 7e+03

0

0.77

Only 1 + or -

Only 1 .

No e notation

Page 20: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<number> <5 1 1 1 Y Y

Page 21: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<percentage>

Represents a percentage: a <number> immediately followed by %

Page 22: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<percentage> <5 1 1 1 Y Y

Page 23: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<length>

Represents distance measurements: a <number> immediately followed by a unit

Units » Absolute » Font-relative » Viewport-percentage

Page 24: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Pixel means picture element

Pixels are not just for computers!

Page 25: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

The basic unit of an electronic display is a pixel

All length measurements eventually get counted in pixels

Page 26: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

For years, computer pixels were all 1/72 of an inch

Apple introduced the first high resolution devices that have much smaller pixels (300+ in an inch!)

The size of pixels in modern high resolution devices varies hugely

Thanks to these 2 changes, the size of a pixel in CSS had to be redefined

Page 27: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

For good old “standard resolution” displays, a pixel is (still a device pixel, which is) 1/72 inch

For high resolution displays (& other high resolution media like print) a CSS pixel is now about 1/96 inch

So now it may take several device pixels to equal 1 CSS pixel

Page 28: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Absolute

Page 29: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

px

mm

cm

in

pt

pc

Page 30: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

in = 96px (about an inch)

cm = 37.8px (about a centimeter)

mm = 3.78px (about a millimeter)

pt = 1.33px (about a point, or 1/72 inch)

pc = 16px (about a pica, or 1/6 inch)

Page 31: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Font-Relative

Page 32: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

em

ex

ch

rem

Page 33: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

em

Represents the calculated font-size of an element

1 em is the height of a font

Page 34: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath
Page 35: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

rem

Represents the font-size of the root element (<html>)

Great for creating perfectly scalable layouts

Page 36: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath
Page 37: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

em 5.5 1 1 1 1 1

ex 5.5 1 1 1 1 1

ch 9 — 27 1 — ?

rem 9 4.1 4 3.6 2.1 4

Page 38: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<color>

Represents a color in the sRGB color space

Page 39: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Ways to describe colors

» keyword » #hex » rgb() » rgba() » hsl() » hsla()

More info when we get to Fonts & Formatting

Page 40: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

keywords 3 1 1 1 1 1

#RRGGBB

#RGB3 1 1 1 1 1

rgb() 4 1 1 1 1 1

hsl() 9 3.1 1 1 2.3 5.1

rgba() 9 3.1 1 3 2.3 5.1

hsla() 9 3.1 1 3 2.3 5.1

transparent 9 3.1 1 3 ? ?

currentColor 9 4 1 1.5 ? ?

Page 41: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Media Queries

Page 42: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<ratio>

<resolution>

Page 43: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<ratio>

Represents aspect ratios (proportions) in media queries: a positive <integer>, followed by /, followed by a positive <integer>

No units!

Page 44: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Examples

4/3: traditional TV

16/9: widescreen TV

185/100: traditional movies

239/100: widescreen movies

Page 45: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<ratio> 9 1 <4 3.5 Y Y

Page 46: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<resolution>

Represents the resolution of a device: its density of pixels, expressed as a <number> immediately followed by a unit of resolution

Units » dpi: dots per inch » dpcm: dots per centimeter » dppx: dots per px unit

Page 47: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<resolution> 9 —* 29 3.5 —* —*

dppx ? — 29 16 — —*

* Requires the non-standard device-pixel-ratio query

Page 48: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Animation & Transformation

Page 49: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<shape>

<time>

<timing-function>

<angle>

Page 50: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<shape>

Represents a rectangular region to which the clip property is applied

Covered later in CSS Animation & Transformation

Page 51: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<time>

Represents time, which keeps on slipping into the future

Covered later in CSS Animation & Transformation

Page 52: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<timing-function>

Represents speed of change over time during animations & transitions

Covered later in CSS Animation & Transformation

Page 53: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<angle>

Represents angle values

Covered later in CSS Animation & Transformation

Page 54: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Future

Page 55: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<blend-mode>

<frequency>

Page 56: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<blend-mode>

Method for blending overlapping images or colors (as in Photoshop or Illustrator)

Not yet supported

Page 57: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

color

color-burn

color-dodge

darken

difference

exclusion

hard-light

hue

lighten

luminosity

multiply

normal

overlay

saturation

screen

soft-light

Page 58: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<blend-mode>

Page 59: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<frequency>

Represents a frequency dimension, like the pitch of a speaking voice

<number> immediately followed by a unit

Units » Hz: Hertz » kHz: kilohertz

Page 60: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

<frequency> — — — — — —

Page 61: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Thank you!

[email protected] www.granneman.com ChainsawOnATireSwing.com @scottgranneman

[email protected] websanity.com

Page 62: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

CSS Data TypesOne of Those Things You Just Have To Know

© 2014 R. Scott GrannemanLast updated 2105-01-24

You are free to use this work, with certain restrictions.For full licensing information, please see the last slide/page.

R. Scott Granneman

Jans Carton

1.3

Page 63: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Changelog

2015-01-24 1.3: Added screenshots for em & rem 2014-10-20 1.2: Added <integer> to list 2014-08-06 1.1: Included browser support for <color>

Page 64: One of Those Things You Have To Know - files.granneman.comfiles.granneman.com/presentations/webdev/CSS-Data-Types.pdf · Notes & URLs for this presentation can be found… » underneath

Licensing of this work

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.

You are free to:

» Share — copy and redistribute the material in any medium or format » Adapt — remix, transform, and build upon the material for any purpose, even commercially

Under the following terms:

Attribution. You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. Give credit to:

Scott Granneman • www.granneman.com • [email protected]

Share Alike. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

No additional restrictions. You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Questions? Email [email protected]


Recommended