css the definitive guide chapter 2 & review of some things in html5

36
CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Upload: magdalen-patrick

Post on 16-Dec-2015

235 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

CSS The Definitive GuideChapter 2

&Review of some things in HTML5

Page 2: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

CSS allows rules that are simple to change, edit and apply. Example: h2 {color: gray;}

By editing a single line of CSS you can change to colors of all your headings…

Lets you the designer focus on the design!

Page 3: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Look at page 24

◦ Two fundamental parts:Selector ~ Defines which part of the document will be

affected. And is on the left sideDeclaration ~ Found on the rights side and can contain a

combination of CSS property and a value.

Examples of elements of an HTML document:P, h3, em, a, h1, h2, h4, etc….

Page 4: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Can contain one or more declarations Always formatted as a property followed by

a colon and then a value followed by a semicolon.

◦ p {font: medium Helvetica;}◦ Remember~

the semicolon ; indicates that the declaration has been concluded.

Keywords are separated by a space, taken together they form the value of the property.

Page 5: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

The most common criterion for choosing which elements to format is the element’s name or type. As an example you may want to make all h2 elements red.

h2 { color: red;}

The above is the style for that to happen. The above style is saved to name.css

Page 6: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

<!DOCTYPE html><html lang="en"><head>

<meta charset="UTF-8" /><title>Antoni Gaudí - Introduction</title><link rel="stylesheet" href="name.css" />

</head><body><article id="gaudi">

<h1>Antoni Gaudí</h1> <p>Many tourists are drawn to Barcelona to see Antoni Gaudí's incredible

architecture.</p><p>Barcelona <a href="http://www.gaudi2002.bcn.es/english/"

rel="external">celebrated the 150th anniversary</a> of Gaudí's birth in 2002.</p>

<section class="project"><h2 lang="es">La Casa Milà</h2><p>Gaudí's work was essentially useful. <span lang="es">La Casa

Milà</span> is an apartment building and <em>real people</em> live there.</p></section><section class="project">

<h2 lang="es">La Sagrada Família</h2><p>The complicatedly named and curiously unfinished Expiatory Temple

of the Sacred Family is the <em>most visited</em> building in Barcelona.</p></section>

</article>

</body></html>

Page 7: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Antoni GaudíMany tourists are drawn to Barcelona to see Antoni Gaudí's incredible architecture.Barcelona celebrated the 150th anniversary of Gaudí's birth in 2002.La Casa MilàGaudí's work was essentially useful. La Casa Milà is an apartment building and real people live there.La Sagrada FamíliaThe complicatedly named and curiously unfinished Expiatory Temple of the Sacred Family is the most visited building in Barcelona.

(h2 shows up red)

Page 8: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

•Not all selectors need to specify an element’s name. If you want to apply formatting to an entire class of elements, regardless of which type of elements have been identified with that class, you’d want to leave the name out of the selector.

•Also you can choose a group of element names for a selector by using a comma to separate them.

Page 9: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Lets look at a HTML5 document and the CSS that is applied using class.

Page 10: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Separated by spaces CSS property font is the exception.

◦ Here a forward slash (/) is used to separate two specific keywords.

◦ Example: H2 {font: large/150% sans-serif;} The slash separates the keywords that set the

element’s font size and line height. This is the only place the slash is allowed to appear in the font declaration.

Page 11: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

You can group selectors! By placing multiple selectors on the left side

of the rule and separating them with a comma, you can have the style on the right effect the multiple selectors given.

Example:◦ h2, p {color: gray;}

Page 12: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

There is no limit on how many selectors you can group together.

Allows for compacting certain types of style assignments which makes for a shorter style sheet.

Universal selector is displayed as an asterisk *◦ Example ~ *{color; red;} would make every

single element in a document red

Page 13: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Using semi colons at the end of each declaration is crucial when grouping.

Browsers ignore whitespace in style sheetsExample:h1 {font; 18px Helvetica; color: purple; background:

aqua;}Or

H1 { font: 18px Helvetica; color: purple; background; aqua; }

Page 14: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Allow you to assign styles in a way that is independent of document elements.

To use them takes planning Using class selectors is the most common

way to apply styles without worrying about the elements involved.

So remember in your html document you need to mark it up so class selectors will work.

Page 15: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Let’s look at the code Below is class.css

.about { color: red; }

To select elements to format based on their class:

1. Type . (that is a period)2. With no intervening space, immediately

type classname, where classname identifies the class to which you’d like to apply the styles.

Page 16: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

1. Type # (a hash or pound sign)2. With no intervening space, immediately

type id, where id uniquely identifies the element to which you’d like to apply the styles.

Page 17: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

.news {color: red; } would effect all elements with the news class,

while h1.news {color: red;} would affect only the h1 elements with the news class.

Page 18: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

If the css was written instead as #gaudi {color: red;}, only the text in the

first article would be red, because it’s the only one with id=“gaudi”. Each id must be unique, so you can’t reuse that id on the article about Luis Domenech I Montaner.

Let’s look

Page 19: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

The name of the class was about whichconveys the meaning of the content to whichit’s applied rather than calling it red.

It’s best to avoid creating a class name thatdescribes how something looks, because youmight change the styles later, like making the text green in this case.

Classes add semantic value to your HTML5 likeelements do.

Page 20: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

It is recommended to use classes whenever possible, because you can reuse them. But ultimately it is your choice.

Two issues that ID Selectors have:◦ Their associated styles can’t be reused on other

elements. An ID may appear on only one element in a page

◦ They are more specific than class selectors. This means if you ever need to override styling that was defined with an id selector, you’ll need to write a CSS rule that’s even more specific.

Page 21: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

The CSS would be:

p:first-line { color: red; }

The first line in every paragraph would be red.

Page 22: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

You can also select just the first letter or first line of an element and then apply formatting to that.

Antoni GaudíMany tourists are drawn to Barcelona to see Antoni Gaudí'sincredible architecture.Barcelona celebrated the 150th anniversary of Gaudí's birth in 2002.La Casa MilàGaudí's work was essentially useful. La Casa Milà is an apartment building and real people live there.La Sagrada FamíliaThe complicatedly named and curiously unfinished Expiatory Templeof the Sacred Family is the most visited building in Barcelona.

Page 23: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

HTML5 first letter

CSS document for the above HTML5

p:first-letter { color: red; }

Page 24: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

In CSS, you can pinpoint elements depending on their ancestors, their parents, or their siblings.

An ancestor is any element that contains the desired element regardless of the number of generations that separate them.

Page 25: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Review

Page 26: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 26

Page 27: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 27

Page 28: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 3: Creating Web Pages with Links, Images, and Embedded Style

Sheets 28

Page 29: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5
Page 30: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Content placed in a footer generally has to do with the company’s address, copyright, or contact information

Chapter 2: Creating and Editing a Web Page Using Inline Styles 30

Page 31: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 31

Page 32: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 32

Page 33: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 3: Creating Web Pages with Links, Images, and Embedded Style

Sheets 33

Page 34: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 34

Page 35: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Chapter 2: Creating and Editing a Web Page Using Inline Styles 35

Page 36: CSS The Definitive Guide Chapter 2 & Review of some things in HTML5

Please update your styles with groupings. You must provide three groupings somewhere in your code.

1) Group selectors2) Group declarations3) Universal selector

Please provide an additional information page explaining Class selectors and ID selectors◦ Must provide content for this additional page◦ On this page please provide a CSS page that will make the first letter a different

color.◦ Please include one CSS using print media. I will be viewing it in Print preview to

determine if you were successful. Also please use the HTML5 elements we have discussed in class

so far on each page. <Header><nav><article><section><footer>