31
HTML5 AND CSS3 Neal Stublen [email protected]

Neal Stublen [email protected]. New Element Styling html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Embed Size (px)

Citation preview

Page 1: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

HTML5 AND CSS3

Neal Stublen

[email protected]

Page 2: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CHAPTER 6

INTRODUCING CSS3

Page 3: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

New Element Styling html5shiv.js provided support in older IE

browsers for new sectioning elementsaside, header, footer, article, etc.

We still need to make these render as block elements instead of inline elements (which is the default)

article, aside, figure, … {

display:block;

}

Page 4: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CSS3 Selectors

Page 5: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Relational Selectors article time

Descendant – time element within article element

article > timeChild – time element is an immediate child of an

article element article + time

Adjacent sibling – time element and article element share the same parent and the time element immediately follows the article element

Page 6: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Relational Selectors

article ~ timeGeneral sibling – time element and article

element share the same parent and time element appears anywhere after the article element

Page 7: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

What Does It Select?

li + liEvery element in a list except the first one

.clock timetime elements within an element using

class=“clock” #main > article

article elements that are direct

children of an element with the

id=“main”

Page 8: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Attribute Selectors

video[src]Matches any video element with a src

attribute (regardless of its value) audio[preload=“auto”]

Matches any audio element with a preload attribute set to “auto”

p[lang|=“en”]Matches any p element with a lang attribute

equal to “en” or starting with “en-”

Page 9: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Attribute Selectors

div[class~=“fancy”]Matches any div element with a class

attribute including the whole word “fancy” article[id^=“news”]

Matches any article element containing an id that starts with “news”

article[id$=“news”]Matches any article element containing an id

that ends with “news”

Page 10: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Attribute Selectors

article[id*=“news”]Matches any article element with the text

“news” appearing within its id attribute

Page 11: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

What Does It Select?

time[data-autofill]Any time element with the custom attribute

data-autofill article[class|=“playlist-entry”]

Any article element with a class that equals “playlist-entry” or starts “playlist-entry-”

[class~=“banner-ad”]Any element with the “banner-ad”

class

Page 12: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Pseudo-class Selectors

:enabled :disabled :checked :indeterminate :target (# anchor target in url) :default (among a set of elements) :valid (based on type/pattern attributes) :invalid (empty or invalid form elements)

Page 13: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Pseudo-class Selectors

:in-range (elements w/ min/max values) :out-of-range :required (form controls) :optional (non-required form controls) :read-only (not user alterable) :read-write (user alterable)

Page 14: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

What Does It Select?

time[data-autofill]Any time element with the custom attribute

data-autofill article[class|=“playlist-entry”]

Any article element with a class that equals “playlist-entry” or starts “playlist-entry-”

[class~=“banner-ad”]Any element with the “banner-ad”

class

Page 15: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Structural Pseudo-classes :root (the html element) ul li:nth-child(3)

Matches every li element that is the third child of a ul parent

ul li:nth-last-child(2)Matches the next to last li element that is a

child of a ul parent article:nth-of-type(5)

Matches the fifth article element within any parent element

Page 16: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Structural Pseudo-classes article:nth-last-of-type(2)

Matches the next to last article element within any parent element

:first-child :last-child :first-of-type :last-of-type :only-child

Page 17: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Structural Pseudo-classes div:empty

Matches any div element that has no child elements

p:lang(fr)Matches any p element in a language

denoted by the “fr” abbreviation :not(:disabled)

Matches all elements that are not disabled

Page 18: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

What is “n”?

ul > li:nth-child(2n)Matches every other li element that is an

immediate child of a ul element ul > li:nth-child(2n+1)

Matches every other li element that is an immediate child of a ul element, but offset by one

Page 19: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Pseudo-elements

Pseudo-classes target element attributes and states

Pseudo-elements target text that part of the document but not accessible as part of the document tree

Pseudo-elements are targeted with a double colon (::) instead of a single colon (:)

Page 20: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Text Nodes

All text nodes have a first letter and first line::first-letter::first-line

Make the first line of the paragraph

red. Double the size of the first

letter.

Page 21: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Selected Text

The page can have selected elements::selection::-moz-selection (Firefox)

Make selected text white.

Page 22: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Generating Content

Pseudo-elements can be used to insert content into a document::before::after

Add a PDF icon after a link. Insert “(PDF)” text after the

anchor content.

Page 23: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CSS3 Colors

Page 24: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Pre-CSS3 Colors

The color red could be expressed as:#f00#ff0000rgb(255, 0, 0)rgb(100%, 0%, 0%)red

Page 25: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CSS3 Color Additions

More color keywordsblanchedalmond, cornflowerblue,

mediumseagreen RGBA support adds alpha value to

specify the color’s opacityrgba(255, 0, 0, 0.4) – red, 40% opaque

Make standard text at 40%,

but selected text at 100%

Page 26: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CSS3 Color Additions

HSL, HSLAHue, saturation, lightness (and alpha)Hue is an integer valueSaturation and lightness are percentages

http://www.workwithcolor.com/

Page 27: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

CSS3 Color Additions opacity can also be set as a CSS property to adjust the

transparency of elements on the page

div.halfopaque {

color: black;

background-color: rgb(255, 0, 0);

opacity: 0.5;

}

div.halfalpha {

color: black;

background-color: rgba(255, 0, 0, 0.5);

}

Page 28: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Border Radius

Rounded corners can be specified on one or more corners of an element

border-radius: 25px;

border-radius: 10px 10px 5px 5px;

border-top-left-radius: 10px;

border-radius: 20px / 10px;

Page 29: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Drop Shadows Drop shadows can be added to any element

box-shadow: [inset] horz vert blur

spread color;

IE6-IE8 uses a plug-in filter (see text) Multiple shadows can be separated by

commas Shadows follow element edges

Page 30: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Text Shadows

Shadows can also be added to text content

text-shadow: top left blur color;

Page 31: Neal Stublen nstublen@jccc.edu. New Element Styling  html5shiv.js provided support in older IE browsers for new sectioning elements aside, header,

Ad Styling

Let’s try to add the CSS necessary to style the “Wanted” ad

border-radius box-shadow text-shadow