+ All Categories
Home > Documents > 1 Introduction to CSS3 - Denise...

1 Introduction to CSS3 - Denise...

Date post: 24-May-2020
Category:
Upload: others
View: 17 times
Download: 0 times
Share this document with a friend
37
1 1 Introduction to CSS3 Client: Intuit (Menlo Park Office); Instructor: Denise R. Jacobs; Company: Knowledge United; Dates: 12-13 April 2012; Day: 1; 2 Meet the Instructor: Me! I’m an author, web designer, speaker and trainer, and creativity evangelist. I wrote The CSS Detective Guide, and co-authored InterAct with Web Standards as well as the upcoming Smashing Book #3. I’ve contributed articles to NetMagazine and A List Apart. 3 About the Course 4 Prerequisites • Knowledge of HTML • Knowledge of basic CSS syntax, functionality, and characteristics (cascade, order, inheritance, specificity) • General knowledge of CSS1 and CSS2 properties • Knowledge of standards-based coding practices (separation of content and presentation) • Familiarity with doctypes and coding validation • Some knowledge of code troubleshooting techniques 5 Course Structure This class is approximately 50/50 lab/lecture. There will be hands-on lab exercise time after most topics to practice the concepts covered. 6 Course Outcomes 1 After completing this course students will: be able to recognize CSS3 selectors, properties and values be able to employ CSS3 selectors, properties and values in HTML-based pages understand the differences between CSS1, CSS2, and CSS3 selectors be able to recognize and employ all of the CSS selector combinators be able to utilize advanced CSS2 and CSS3 selectors to better target page elements 2 understand the difference between and uses for the various @ rules be able to use various CSS3 properties such as border-radius, @font-face, transform and transition, gradient, box- and text- shadow, opacity and rbga, etc. in HTML-based pages learn CSS3 cross-browser and graceful degradation coding techniques learn the concepts of responsive design for multiple devices 7 Lab Tools Computers must have all of the major browsers on them: Firefox, Safari, Google Chrome, Opera, and IE8. An objective is to able to cross-browser test to see how the different browsers render the code. If there is a large user base that uses IE7, it will help to have a stand-alone version of IE7 installed on the computers as well so that we can test the fallbacks that are taught. 8 Resources: General Course
Transcript
Page 1: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

1

1 Introduction to CSS3Client: Intuit (Menlo Park Office);Instructor: Denise R. Jacobs;Company: Knowledge United;Dates: 12-13 April 2012;Day: 1;

2 Meet the Instructor: Me!I’m an author, web designer, speaker and trainer, and creativity evangelist. I wrote The CSS Detective Guide, and co-authored InterAct with Web Standards as well as the upcoming Smashing Book #3. I’ve contributed articles to NetMagazine and A List Apart.

3 About the Course4 Prerequisites

• Knowledge of HTML • Knowledge of basic CSS syntax, functionality, and characteristics (cascade, order, inheritance, specificity) • General knowledge of CSS1 and CSS2 properties • Knowledge of standards-based coding practices (separation of content and presentation) • Familiarity with doctypes and coding validation • Some knowledge of code troubleshooting techniques

5 Course StructureThis class is approximately 50/50 lab/lecture.

There will be hands-on lab exercise time after most topics to practice the concepts covered.

6 Course Outcomes1 After completing this course students will:

• be able to recognize CSS3 selectors, properties and values• be able to employ CSS3 selectors, properties and values in HTML-based pages• understand the differences between CSS1, CSS2, and CSS3 selectors• be able to recognize and employ all of the CSS selector combinators• be able to utilize advanced CSS2 and CSS3 selectors to better target page elements

2 • understand the difference between and uses for the various @ rules• be able to use various CSS3 properties such as border-radius, @font-face, transform and transition, gradient, box- and text-

shadow, opacity and rbga, etc. in HTML-based pages• learn CSS3 cross-browser and graceful degradation coding techniques• learn the concepts of responsive design for multiple devices

7 Lab Tools• Computers must have all of the major browsers on them: Firefox, Safari, Google Chrome,

Opera, and IE8.

• An objective is to able to cross-browser test to see how the different browsers render the code. If there is a large user base that uses IE7, it will help to have a stand-alone version of IE7 installed on the computers as well so that we can test the fallbacks that are taught.

8 Resources: General Course

Page 2: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

2

• http://www.delicious.com/denisejacobs/css3training

• http://reference.sitepoint.com/css

9 Agenda

10 Agenda: Day 1Course, Instructor and Student Introduction• Course prereqs, structure, outcome, tools• Class roll, and student intros

Introduction• About CSS3

– What’s new in CSS3?– CSS3 Modularity – CSS3: Values

11 Agenda: Day 1Getting Started With CSS3: Rules of the Road and Tools of the Trade• CSS3 Across the Browsers

– CSS3 browser compatibility – Cross-browser coding

• CSS3 Tools– Generators– Polyfills/Helper Scripts– Browser Detection– Templates & Frameworks

12 Agenda: Day 1Laying the Foundation: CSS Page Layout• Foundations

– Initial Page Set-up• Review of page layout wireframe and final design Document Hierarchy

– Styling• Resets• Float-clearing & Display review• Optimization

13

Advanced Selectors• CSS2 Selectors• CSS3 Selectors

– General Sibling E~F– Attribute presence– Attribute substrings– Hands-on Lab

Page 3: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

3

• Pseudo-elements– (now use :: instead of :)

• Lab: Continue Page Set-up

14 Agenda: Day 1CSS3 Properties, part I• Web Fonts

– @font-face– Webfont services– Google Font API – Hands-on Lab

• New Visual Effects– border-radius– opacity– rgba– box-shadow– text-shadow

Intensive Hands-on Lab

15 Introduction

16 What’s New in CSS3

17 What’s New in CSS3?CSS3 is the third generation of the CSS specification recommendations from the W3C.

18 What’s New in CSS3?In CSS3 there are new selectors, pseudo-elements and classes, properties, and values specifically created to answer the needs and solve the problems of modern web design and development.

19 CSS3 Modules

20 CSS3 ModularityCSS3 has been broken up into different unique modules. This means is that, for example, the particular CSS properties and values for layout is grouped into one specific module.

From a browser and implementation perspective, the benefit is that browser developers can now implement CSS3 module by module, instead of implementing entire CSS specification. This helps speed up the entire implementation process.

21 The CSS3 Modules1 • Template Layout

• Backgrounds and Borders • Ruby • Basic User Interface • Basic Box Model • Grid Positioning • Speech

Page 4: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

4

• Marquee • Style Attribute Syntax • Cascading and Inheritance • Color • Fonts • Text• Generated Content for Paged Media• Generated and Replaced Content

2 • Values and Units• Web Fonts • Behavioral Extensions to CSS • Line Layout • Flexible Box Layout • Image Values • 2D Transformations • Multi-column Layout • 3D Transformations • Namespaces • Transitions • Animations • View Module • Media Queries • Paged Media • Selectors

22 Resources: New in CSS3• http://www.w3.org/TR/tr-groups-all#

tr_Cascading_Style_Sheets__CSS__Working_Group

23 CSS3 Values & Colors

24 Units in CSS (common)Ones you’ll use all of the time:• px: pixels (a dot on the computer screen)

• %: percentage

• em: 1em is equal to the current font size.

2em means 2 times the size of the current font. e.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt.

The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses.

25 Colors in CSS1 & CSS2.1• color_name:

A color name, ex. red

• #rrggbb: A hexidecimal number, ex. #ff0000

• #rgb: A hexidecimal shorthand number, ex. #fc0

• rgb(x, x, x): An RGB value, ex. rgb(255, 0, 0)

• rgb(x%, x%, x%): An RGB percentage value, ex. rgb(100%, 0%, 0%)

Page 5: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

5

26 Colors in CSS3: RGB• Regular RGB

rgb(x, x, x): ex. rgb(255, 0, 0)

• RBG with alpha-opacity rgba(x, x, x, y): An RGB value ex. rgba(255, 0, 0, 0.2)

27 RGBA ColorAlpha opacity:0.0 = 0% = no opacity1.0 = 100% = full opacity

28 Colors in CSS3: HSLHSL stands for hue, saturation, and luminosity (lightness)

• Regular HSLhsl(x%, x%, x%): ex. hsl(0, 100%, 50%)

• HSL with alpha-opacityhsla(x%, x%, x%, y): ex. hsla(0, 100%, 50%, 0.5)

29 Colorzilla.com

30 HSL Color Wheel

• 0º – Red• 60º – Yellow• 120º – Green• 180º – Cyan• 240º – Blue• 300º – Magenta

31 HSL Color Picker Toolhttp://www.workwithcolor.com/hsl-color-picker-01.htm

32 Getting Started with CSS3:The Rules of the Road

33 CSS3 Browser Compatibility

Page 6: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

6

34 The reality• Many properties are browser-specific, requiring vendor prefixes

• Plus there is a standard property

• There are syntax differences between browser-specific properties and the standard property

• All of this causes an increase in the amount of CSS

35 = Code bloat1 Ideally:

a.polaroid:active {z-index: 999;border-color: #6A6A6A;box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4);transform: rotate(0deg) scale(1.05);}

2 Reality:

a.polaroid:active {z-index: 999;border-color: #6A6A6A;-webkit-box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4);-moz-box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4);box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4);-webkit-transform: rotate(0deg) scale(1.05);-moz-transform: rotate(0deg) scale(1.05);transform: rotate(0deg) scale(1.05);

}

36 Doesn’t Validate

37

Standard maturation steps1.Working Draft (WD)2.Candidate Recommendation (CR)3.Proposed Recommendation (PR)4.W3C Recommendation (REC)

38

• Working Draft (WD)

• At the working draft level, the standard is published for review by "the community". A WD document is the first form of a standard that is publicly available. Commentary by virtually anyone is accepted, though no promises are made with regard to action on any particular element of said commentary.

• At this stage, the standard document may likely have significant differences from its final form. As such, any who implement WD standards should be ready to significantly modify their implementations as the standard matures.• [edit] Candidate Recommendation (CR)

• A candidate recommendation is a version of the standard that is more firm than the WD. At this point, the group responsible for the standard is satisfied that the standard does what is needed of it. The purpose of the CR is to elicit aid from the development community as to how implementable the standard is.

• The standard document may change further, but at this point, significant features are mostly locked. The design of those features can still change due to feedback from implementors.• [edit] Proposed Recommendation (PR)

• A proposed recommendation is the version of the standard that has passed the prior two levels. The users of said standard have had their say, and the implementors of the standard have likewise had a chance at providing input. At this stage, the document has been submitted to the W3C Advisory Council for final approval.

• While this step is important, it rarely causes any significant changes to a standard as it passes to the next phase.• [edit] W3C Recommendation (REC)

• This is the most mature stage of development. At this point, the standard has undergone extensive review and testing, under both theoretical and practical conditions. This standard is now endorsed by the W3C as a standard for wide deployment in its problem domain.

39 None of the older IEs support CSS3…as in “not any.”

Page 7: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

7

40 However, IE9 has some support of CSS3

Finally!41 Although the reality is a bit…underwhelming

42 IE9 now supports CSS3…but only these properties:• @font-face• RGBa and HSLa• background-size• multiple backgrounds• border-radius• box-shadow• opacity• CSS transforms• CSS3 selectors (all)

43 Support in IE10 will be *much* better

44 Download and Play!

45 Know Your Browser Support

46 HTML5Please.com

47 CSS3ClickChart.com

48 Browser Support Charts: Properties

http://www.findmebyip.com/litmus

49 Browser Support Charts: Selectors

http://www.standardista.com/css3/css3-selector-browser-support

50 ISO: CSS3 Specifications

The CSS3 Specifications are THE resource for finding out exactly is the intented behavior and use of any given property.

http://www.w3.org/standards/techs/css#w3c_all

51 ISO: good cross-browser testershttp://tredosoft.com/Multiple_IE

Page 8: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

8

http://crossbrowsertesting.com/(paid)

http://browsershots.org/(free)

52 Cross-browser Coding53 The Goal: Code that works in all browsers

54 Not all browsers are equal

55 How can we achieve this?

56 Steps to get as close as possible1.Leverage source order2.Exercise multiplicity3.Be conditional4.Filter it5.Be defensive6.Let tools do all of the work (polyfills/libraries)

57 Leverage source order• Place default properties first

• Place browser-specific properties ahead of standard properties

• The standard properties will override the vendor’s when the standard is established.

58 A Proper Stack.gradient {color: #000;

59 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */

60 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */

61 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);

Page 9: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

9

/* Chrome10+,Safari5.1+ */

62 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */

63 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */background: -ms-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* IE10+ */

64 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */background: -ms-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* IE10+ */background: linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* W3C */

65 A Proper Stack.gradient {color: #000;background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*fallback color and image */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */background: -ms-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* IE10+ */background: linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* W3C */filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ccc9ba', endColorstr='#f7f6f4',GradientType=0 ); /* IE6-9 */}

66 Styling in multiplesYou can use multiple stylesheets to add layers of style complexity for multiple platforms

@import 'reset.css'; @import 'structure.css'; @import 'typography.css'; @import 'widgets.css';

Page 10: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

10

See:http://www.alistapart.com/articles/progressiveenhancementwithcss

67 Get ConditionalYou can use conditional comments to serve code straight to the IEs if so desired.

Example:<!--[if gte IE 6]><link href="ie_stylesheet.css" rel="stylesheet"><![endif]-->

(place after the regular stylesheet link to override styles)

68 Apply a Filter• If you must have the effect in IE, such as alpha opacity, gradient, shadow, transitions etc. you could use

a proprietary IE filter.

• The -ms-filter attribute is an extension to CSS. This syntax will allow other CSS parsers to skip the value of this unknown property completely and safely. It also avoids future name clashes with other CSS parsers.

• In Internet Explorer 8 mode, filters must be prefixed with "-ms-" and the PROGID must be in single or double quotes to make sure Internet Explorer 8 renders the filters properly.

69 Filters: {Caveat Coder}• IE filters work, but are essentially hacks

– IE filters are proprietary and thus not part of any standard specification, and never will be

70 Coding for Older BrowsersPractice preventive/defensive coding

– Focused & efficient code– Be prepared for bugs– Quickly and easily identify and solve problems when they come up

71 Admit it, you like the challenge

72 Let the tools do the work• We’ll talk about those next!

73 Resources: Cross-browser codingAbout Conditional Commentshttp://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

Microsoft Visual Filters and Transitions Referencehttp://msdn.microsoft.com/en-us/library/ms532853%28v=VS.85%29.aspx

74 CSS3 Tools

Page 11: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

11

75 Useful CSS3 Tools1.CSS3 Generators2.Helper Scripts3.Browser Feature Detection4.Templates

76 CSS3 Generators

77 CSS3Please.com

78 CSS3Generator.com

79 CSS3-Maker.com

80 CSS3 Tools at WestCiv

81 CSS3.me

82 Tools: CSS3 Generators• http://css3please.com/• http://css3generator.com/• http://westciv.com/tools/gradients/

index.html• http://border-radius.com/• http://www.css3maker.com/index.html• http://www.colorzilla.com/

gradient-editor/• http://csscorners.com/• http://border-image.com/

83 Polyfills/Helper Scripts

84 What the %$#! is a Polyfill?• Polyfills are code tools, usually javascript, which allow for modern HTML/CSS functionality

in older browsers.

85 Get a helping hand…These scripts help IE lt 8 behave like CSS3-compliant browsers. However, support of

CSS3 properties varies, between scripts.

86 Ie-7.js

87 CSS Sandpaper

88 CSS3Pie.com

89 CSS3 Pie support is limited to…

Page 12: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

12

• border-radius• box-shadow• border-image• multiple background images• linear-gradient as background image

90 PrefixFree.com

91 Selectivizr.com

92 Using selectivizr is easySelectivzr' code:

<script type="text/javascript" src="[JS library]"></script><!--[if (gte IE 6)&(lte IE 8)]>

<script type="text/javascript" src="selectivizr.js"></script><noscript><link rel="stylesheet" href="[fallback css]" /></noscript>

<![endif]-->

93 Browser Feature Detection

94 Modernizr.com

95 What does Modernizr do?Modernizr detects which CSS3 (and HTML5) properties are supported by the browser,

and appends classes to the <html> tag, which then allows you to create styles to target specific properties to individual browsers.

It is a premier progressive enhancement tool!

96 How to use Modernizrhttp://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/

http://webdesignernotebook.com/css/how-to-use-modernizr

http://www.ericlightbody.com/2010/modernizr-your-tool-for-html5-and-css3-functionality/

97 Templates & Frameworks

98 HTML5Boilerplate.com

99 How to use the HTML5 BoilerplateHOW TO: Get Started with HTML5 Boilerplate• http://mashable.com/2010/09/02/html5-boilerplate-guide/

Getting Started Using HTML5 Boilerplate

Page 13: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

13

• http://weblogs.asp.net/dwahlin/archive/2011/06/05/getting-started-using-html5-boilerplate.aspx

20 Snippets You should be using from Html5 Boilerplate• http://www.1stwebdesigner.com/design/snippets-html5-boilerplate/

100 Bootstrap

101 Laying the Foundation: CSS Page Layout

102 Initial Page Set-up: Wireframe and Code

103 Lab TimeLet’s get our example page all set-up.

1.Get the files.

2.Add any extra html pieces we may need here:http://html-ipsum.com/

104 MyCorpIntro – finished page

105 MyCorpIntro – wireframe

106 Initial Page Set-up: Styling

107 CSS Resets108 Foundation 3: Create a Baseline

1.The CSS Reset All-star2.DIY Resets3.CSS Reset Compendia

109 Why Reset?By deliberately establishing an element’s properties, you can:• Better control the elements on the page• More quickly determine the source of problems when they arise

110 CSS Reset All-Star: Eric Meyer’s Pro’s

– One of the most popular, well thought-out– Neutralizes almost every element

Page 14: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

14

Con’s– Can be too far-reaching– Extra work to establish the values for the elements you want

111 Resource: Eric Meyer’s ResetEric Meyer’s Reset:

http://meyerweb.com/eric/tools/css/reset/

112 DIY Resets• You can determine exactly which elements you want to reset• May save on reestablishing properties• You know exactly what is changed and why you changed it• Problems will be that much more obvious

113 Top Properties to Reset• Margin and padding• Borders, especially on linked images• Link text underlining• Vertical alignment• Font size and line-height

114 Resource: DIY Resets

Article on DIY resets: http://bit.ly/1D4jSB

115 Resource: CSS Reset CompendiaKiller Collection of CSS Resetshttp://tinyurl.com/5bdoj2

More Killer CSS Resetshttp://tinyurl.com/n746dl

116 Normalize.css

117 Normalize v. ResetNormalize.css preserves useful defaults

• Resets impose a homogenous visual style by flattening the default styles for almost all elements. In contrast, normalize.css retains many useful default browser styles. This means that you don’t have to redeclare styles for all the common typographic elements.

• When an element has different default styles in different browsers, normalize.css aims to make those styles consistent and in line with modern standards when possible.

• Normalize.css corrects common bugs

• It fixes common desktop and mobile browser bugs that are out of scope for resets. This includes display settings for HTML5

Page 15: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

15

elements, correcting font-size for preformatted text, SVG overflow in IE9, and many form-related bugs across browsers and operating systems.

118 Using Normalize.css• http://stackoverflow.com/questions/6887336/what-is-the-different-between-normalize-

css-and-reset-css

119 Elements of page layout

120 Layout Technique:Floats

121 The Float Property• The float property is used to move elements on the page to either the far left or far right of the

containing element.

• Floating an element makes an element a block box, pushes it to the farthest edge of its containing element, takes it out of the flow of the document, and forces the other elements to wrap around it unless otherwise specified.

• Once floated, an element becomes a block box, even if it is an inline element by definition.

122 clear: (value)• To make a float move to the next line of an adjacent float, you need to clear it.

• Values: left, right, both

123 Containing floats• Because floats are taken out of the flow, they are not contained by their parent element

unless the parent contains an element that is cleared.

• Otherwise the parent will collapse.

124 Float Clearing125 Float Clearing Approaches

1)overflow: hidden

2)Clearfix3)Float Nearly Everything (FnE)

126 Overflow: float clearing127 Clearing floats: overflow: hidden

Almost everyone’s favorite float-clearing technique.

However, there can be problems:• Content is hidden with no scrollbars when browser window is smaller than container• Potential interference with margins, borders, outlines, and absolutely-positioned PNGs

Page 16: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

16

• Application of CSS3 properties, such as box-shadow, text-shadow & transform

128 Overflow: hiddenoverflow: hidden makes the content in the element box to disappear if it extends past the boundaries of the box.

129 Overflow: visibleoverflow: visible allows the content to be rendered regardless of the element box’s dimensions.

130 Overflow: scrolloverflow: scroll, the browser creates scrollbars to let the user view the content of the element while maintaining the specified dimensions.

131 Overflow: autooverflow: auto lets the browser determine whether scrollbars are needed, and will only create them if and where necessary.

132 overflow: hidden - StandardExample:.container {border: 1px solid #000000;overflow: hidden;}

133 overflow: hidden ImprovedExample:.container {border: 1px solid #000000;overflow: auto;/* hidden & scroll also work*/width: 100%; /* some width or height required */}

134 “Clearfix”: float clearing

135 Clearing floats: ClearfixClearfix uses the :after pseudo-element to generate a character at the end of the content in the parent container (after the floated elements) that is made into a block element, cleared, and is hidden from view.

136 Clearfix Issues1.Remember where to put it:

Apply .clearfix to the element containing the floats, so that the cleared content is generated after the content inside of it.

2.Be aware of support: Neither IE6 nor IE7 support the :after pseudo-class, so a trigger of hasLayout is necessary.

• Most/all of the clearfixes come with an IE6 & IE7 hack

Page 17: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

17

137 Clearfix Issues3.Be mindful of the generated content:

Sometimes the generated period can be a problem

4.Be aware of collapsing margins: New clearfixes speak to this.

138 The New Clearfix

.clearfix:after {clear: both;content: " ";display: block;font-size: 0;height: 0;visibility: hidden;}

*html .clearfix {zoom: 1;} /* IE6 */

*:first-child+html .clearfix {zoom: 1;} /* IE7 */

139 On Reloaded & Magnificent ClearfixesAddresses hasLayout in IE lt 7 and fixes margin collapse in multiple browsers.

140 Clearfix Reloaded

.clearfix:before, .clearfix:after {content: ".";display: block;height: 0; overflow: hidden;}

.clearfix:after {clear: both;}

.clearfix {zoom: 1;} /* IE lt 8 */

141 The Magnificent Clearfix

.clearfix:before, .clearfix:after {content: "\0020"; /*this is a space*/ display: block; height: 0; visibility: hidden;}

.clearfix:after {clear: both;}

.clearfix {zoom: 1;}/* IE fix for extra margin at bottom of page */

142 The Top Clearfix

.clearfix:after {clear: both;content: " ";display: block;font-size: 0;height: 0;visibility: hidden;}

.clearfix {display: inline-block;}

Page 18: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

18

143 FnE: float clearing144 Clearing Floats: FnE

Float Nearly Everything (aka “FnE”): floating the parent container contains the children.

FnE still a viable option:• Contains and clears

Potential issue:• Watch for how it affects the rest of the page layout and structure

145 Resources: Floats• http://www.delicious.com/denisejacobs/float+css3training

• http://www.smashingmagazine.com/2009/10/19/the-mystery-of-css-float-property/

146 Layout Technique:The Display Property

147 Display: InlineSetting the display: inline of a block element will cause to display as an inline element, putting it on the same line as other elements and taking up only the width of its contents.

148 Reminder: display: block & inline-block1 Block:

With display: block an element will display as a block element, with whitespace above and below it, and no elements next to it.

2 Inline-block:With display: inline-block, an element can have a width assigned to it like a block element, while still appearing the in the horizontal flow with its surrounding inline elements.

149 “Give floats the flick”http://www.sitepoint.com/give-floats-the-flick-in-css-layouts/

150 Resources: page layouthttp://www.delicious.com/denisejacobs/layout+css

151 Resources: Display Propertyhttp://www.quirksmode.org/css/display.html

152 CSS Optimization

153 Optimization Tips FTW!Here are some tips for optimizing your code on both a micro- and macro-level, as well as

Page 19: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

19

ways to make sure you are targeting the elements you want on the page.

154 Macro-Optimize: Annotate Your Markup

Example:<div id="content">

<div class="promo">...</div><!-- /end .promo -->

</div><!-- /end #content -->

155 Macro-Optimize: Annotate Your CSS/* Comments are good, mmkay? */

Notation is your friend. For:• Overriding styles• Creating stylesheet sections• Listing the color scheme• Resources and contact info

156 Macro-Optimize: Annotate Your CSS/* made by you on some date */

/* section of the stylesheet */p {border-color: #cf0;border-color-bottom: #ccc; /*this property overrides the previous one */}

157 Macro-optimize: Reduce, Reuse, & Recycle

• Identify content patterns• Use classes instead of ids & elements• Define defaults

158 Micro-Optimize: CSS LengthLess is more:• Use shortest properties and values• Avoid duplicate properties• Use shorthand properties• Condense values and units• (Avoid multiple lines and indenting)

159 Micro-optimize: CSS SpeedUp the efficiency:• ID selectors are speedier than element or universal• Drop element qualifiers• Ditch descendent selectors when and where you can

Page 20: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

20

160 Micro-Optimization in ActionExample:#sidebar {background: #fff url(bg.png) repeat-x 0 0;font: normal 1.33em/1.33 Georgia, serif;border: 1px solid #f96;margin: 10px 20px;padding: .1em;}

161 Resources: OOCSShttp://www.stubbornella.org/content/2009/02/28/object-oriented-css-grids-on-github/

https://github.com/stubbornella/oocss

http://www.typesett.com/2010/01/object-oriented-css-oocss-the-lowdown/

162 CSSLint.net

163 Resource: CSS Optimizershttp://www.cleancss.com/

http://www.codebeautifier.com/

164 Tools: CSS Compressorshttp://www.csscompressor.com/

http://www.cssdrive.com/index.php/main/csscompressoradvanced/

165 Tools: CSS Redundancy Checkershttp://www.sitepoint.com/dustmeselectors/(firefox extension)

166 Element Targeting TechniquesMy favorite:

outline: 1px solid red;

Why?• outline does not add to dimensions of the element• Color names used only for troubleshooting

167 Resources: Code Optimizing• http://www.delicious.com/denisejacobs/

css+optimization

168 Lab TimeWhile doing the basic layout, we will:• Optimize css, target styles

Page 21: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

21

• Establish the page layout with floats, float-clearing techniques, change displays, and use overflow.

169 Lab TimeBe sure to validate your code with the CSS validator:http://jigsaw.w3.org/css-validator/

170 CSS Selectors

171 Document Hierarchy

172 HTML Hierarchy<html><head><title>Mikey Spillane vs. Mike Hammer</title></head><body><h1>Mikey Spillane vs. Mike Hammer</h1><p>Who is the toughest, smartest, and most steely? <em>You</em> get to be the judge by taking this <a href="survey.html">survey</a>.</p><p>Next month's survey: Sir Arthur Conan Doyle or Sherlock Holmes? <imgsrc="doyle.jpg" alt="Doyle vs. Holmes"></p></body></html>

173 HTML Hierarchy

174 The Hierarchy “Family Tree”• An ancestor is any element that is connected to other elements but is higher up the document tree, no matter how many levels up. For example,

in the document above, both the <html> and <body> tags are ancestors of the <p> tag.

• A descendant is any element connected to an ancestor, but lower in the document tree, no matter how many levels down. In our example, the <em>, <a>, and <img> are descendants of the <body> tag.

• A parent is an element directly above a connected element in the document tree. A parent element is also an ancestor, but an element can have ancestors that are not its parents.

• A child element is directly below a connected element. A child is a descendant, but an element can have descendants that are not its children.

• Sibling elements share the same parent, and are on the same level as each other in the hierarchy.

175 Combinator Selectors: Descendent Descendant selectors select the element that is a descendant of another element in the document tree.

Syntax:ancestor selector (space) descendant selector

E F

Example:div h2 {color: green;}

Page 22: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

22

176 Kick the habit… of reliance upon descendent selectors!

177 Getting AdvancedAdvanced selectors are a good way to specifically target styles for modern browsers.

The right selector will help you achieve targeting nirvana, so it’s important to know which selectors you can use now.

178 Advanced CSS Selectors179 Advanced Selectors: Usage Tips

• All of the CSS2 selectors are supported by the modern browsers, and almost all of the CSS3 ones are, so use them!

• It’s easy to target styles away from the IEs, but target them to the IEs with simpler combinator selectors

• There are “hacks” to target styles to specific browsers, other than the IEs

180 CSS 2.1 Selectors1 • Universal *

• Child CombinatorE > F

• Adjacent/Sibling CombinatorE + F

• Attribute E[~attribute]

• At Rules– @font-face– @media– @page– @charset

2 • Pseudo elements– :before– :after

• State pseudo-classes– Dynamic

• :hover• :active• :focus

– Language• :lang

– Structural• :first-child

181 CSS2 & CSS3 Selector Support

182 CSS2.1 Selectors & IE Support

Page 23: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

23

• Universal * (ie7/8 – yes)• Child: e > f (ie7/8 – yes)• Sibling/Adjacent: e + f (ie7 no, ie8 – yes)• Attribute: e[attrib] (ie7/8 – yes)• Pseudo elements (ie7/8 – no)

– ::before– ::after

• State pseudo-classes, v2.1– :first-child (ie7/8 – yes)– :hover (ie7/8 – yes)– :active (ie7/8 – yes)– :focus (ie7/8 – no)– :lang (ie7/8 – no)

183 Combinator Selectors: Child• A child selector targets an element that is a child of another element.

• A child is a direct descendant of an element in the document tree (as opposed to a more distant descendant).

Syntax:parent selector > descendant selectorE > F

Example:p > strong {font-family: Tahoma, sans-serif;}

184 Selector: Universal• The universal selector is the asterisk (*).

• This selector lets you select every element on the page and apply the style rules to them.

Example:* {font-family: Arial, sans-serif;}

185 Combinator Selectors: Sibling/AdjacentA sibling selector (also known as adjacent) selects an element that is next to another element in the document tree.

Syntax:sibling selector + sibling selector {property: value; }E + F

Example:p + ol {font-family: Georgia, serif;}

186 Combinator Selectors: AttributeAn attribute selector targets a selector with a particular attribute.

Syntax:selector[attribute]

Page 24: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

24

Example:•a[title] {font-variant: italic;}

187 What is a pseudo-element?The pseudo-element selector does not match any real HTML element in the document tree, but affects only part of a selector’s element.

188 Pseudo-elements: :first-letter:first-letter targets the first letter of text within an element.

Example:h1 + p:first-letter {font-size: 110%;}

189 Resources: CSS2 Selectors• http://www.bostonwebstudio.com/

presentation/intro-css2.1-css3/demo/

190 CSS3 Selectors,part 1

191 HTML Hierarchy Reminder

192 The Hierarchy “Family Tree”• An ancestor is any element that is connected to other elements but is higher up the document tree, no matter how many levels up. For example,

in the document above, both the <html> and <body> tags are ancestors of the <p> tag.

• A descendant is any element connected to an ancestor, but lower in the document tree, no matter how many levels down. In our example, the <em>, <a>, and <img> are descendants of the <body> tag.

• A parent is an element directly above a connected element in the document tree. A parent element is also an ancestor, but an element can have ancestors that are not its parents.

• A child element is directly below a connected element. A child is a descendant, but an element can have descendants that are not its children.

• Sibling elements share the same parent, and are on the same level as each other in the hierarchy.

193 CSS3 Selector Specification1 • General sibling

E ~ F

• Attribute presence– a[attribute="value"]– a[attribute~="value"]– a[attribute|="value"]

• Attribute substrings– a[attribute^="value"]– a[attribute$="value"]– a[attribute*="value"]

2 • Pseudo-elements*

Page 25: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

25

*all pseudo-elements indicated with :: in CSS3

194 CSS3 Selector Specification1 • Pseudo-classes

– Target• :target

– Negation• :not(s)

– State• :enabled• :disabled• :checked • :indeterminate

2 – Structural• :nth-child(n)• :nth-last-child(n)• :nth-of-type(n)• :nth-last-of-type(n)• :last-child• :first-of-type• :last-of-type• :only-child • :only-of-type• :empty

195 CSS3 Selector Support

196 Combinator Selectors: General SiblingA general sibling selector (also known as adjacent) selects an element that shares the same parent as another element in the document tree.

Syntax:sibling selector ~ sibling selector {property: value; }E ~ F

Example:p ~ dd {font-family: Georgia, serif;}

197 Combinator Selectors: Attribute presence

selector[attribute="value"] targets a selector with a particular attribute and specific value.Example:img[src=“catchathief.jpg”] {border: 1px solid #999; }

selector [attribute~="value"] targets a selector with a particular attribute and value where the value is one of multiple values separated by a space.Exampleimg[alt~="CSI"] {border: 1px #ff8000 solid;}

198 Combinator Selectors: Attribute presence

selector [attribute|="value"] targets an element with an attribute that contains values separated

Page 26: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

26

by a hypen in a list.

Example:img[title|="large"] {border: 1px solid #000; }

199 Combinator Selectors: Attribute substrings

selector [attribute^="value"] targets an element with an attribute that begins with a prefix of “value”. Example:img[title^=“th_"] { border: 1px solid #000; }

selector [attribute$="value"] targets an element with an attribute which ends with a suffix of “value.”Example:img[title$=“png"] { border: 1px solid #000; }

200 Combinator Selectors: Attribute substrings

selector [attribute*="value"] targets an element with an attribute that contains “value” as any part of a value string.

Example:img[title*="large"] {border: 1px solid #000; }

201 Tools: CSS3 Selectors• http://www.quirksmode.org/

compatibility.html

• http://www.evotech.net/blog/2009/02/css-browser-support/

• http://www.findmebyip.com/litmus

202 Resources: CSS3 Selectors• http://www.delicious.com/denisejacobs/selectors+css3

• http://inspectelement.com/tutorials/a-look-at-some-of-the-new-selectors-introduced-in-css3/

• http://24ways.org/2009/cleaner-code-with-css3-selectors

203 Lab TimeWhere appropriate, let’s add styles to our example page using some of the advanced CSS2.1 selectors such as: • Child: E > F• Sibling: E + F• Attribute: selector[attribute]

204 CSS3 Properties:

Page 27: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

27

Part I

205 Web Fonts

206 @font-face

207 @font-face

208 @font-face• Note:

– Actually part of the CSS2.1 specification. – Therefore, the IEs do support it!

• Browser Support– However, the older IEs require fonts to be in EOT format– IE9 now supports WOFF!

209 @font-face@font-face { font-family: 'Graublau Web'; src: local('Graublau'), url('GraublauWeb.woff') format('woff'), url('GraublauWeb.ttf') format('truetype'); url('GraublauWeb.eot'), format('eot');}

210 @font-face bug: IE lt 8@font-face super bullet-proofing

The problem:@font-face doesn’t work, even with the proper normal syntax. What gives?

211 @font-face bug: Webkit@font-face bold and italics “bug”

The problem:Applying font-weight:bold or font-style: italic to @font-face'd text doesn’t work.

212 Solution: IE proof @font-face

+ faux variationsExample:@font-face {font-family: 'MyFontFamily';src: url('myfont-webfont.eot?#iefix‘) format('embedded-opentype'), url('myfont-webfont.woff') format('woff'), url('myfont-webfont.ttf')format('truetype'),url('myfont-webfont.svg#svgFontName') format('svg');font-weight:normal;font-style:normal;

Page 28: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

28

font-variant:normal;}

213 Graceful degradation: @font-face• Desired font should display in all browsers. If not, fallback fonts will display

• Extra credit: image replacement through conditional comments

214 Graceful degradation: @font-faceIn modern browsers

215 Font Licensing• When you decide to use a font as a webfont, you have to be sure that the EULA supports

it.

• One way to avoid that is to use ONLY fonts that are listed as approved webfonts.

216 FontSquirrel.com

217 Webfont Services

218 Webfont Services• You can pay a service where the webfonts are hosted elsewhere, and you link to them

and use the fonts on their server.

219 Webfont Services1 http://www.typotheque.com/webfonts

http://typekit.com

http://fontdeck.com

http://kernest.com

http://www.ascenderfonts.com/webfonts/2 http://www.webtype.com

http://www.fontslive.com

http://webfonts.fonts.com

http://www.extensis.com/en/WebINK/

http://webfonts.info/wiki/index.php?title=Category:Webfont_Services

220 Typekit

221 Google Font API• The Google Font API helps you add web fonts to any web page.

Page 29: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

29

• The number of fonts is currently limited.– http://code.google.com/webfonts

222 Google Font Directoryhttp://code.google.com/webfonts

223 Google Font APIMethod 1: Head Link<link href='http://fonts.googleapis.com/css?family=IM+Fell+DW+Pica' rel='stylesheet' type='text/css'>

#headline h1 {text-align: center;font-size: 8em;color: #111;text-shadow: 0px 2px 3px #555;font-family: 'IM Fell DW Pica', Arial, serif;

}

That’s it! Just two copy and paste actions and you’ve got yourself a fancy new webfont.

224 Google Font APIMethod 2: @Import@import url(http://fonts.googleapis.com/css?family=Inconsolata);

Simply paste this into the very top of your CSS page, then copy the font-family CSS snippet and paste.

225 Resources: @font-face• http://www.delicious.com/denisejacobs/font-face• http://www.fontsquirrel.com/

• http://www.fontsquirrel.com/fontface/generator

• http://code.google.com/apis/webfonts/docs/getting_started.html

226 Lab TimeLet’s add @font-face to our example page using • the Google API• A FontSquirel @font-face kit

227 New Visual Effects in CSS3

228 New Visual Effects in CSS31.border-radius2.opacity3.rgba color4.box-shadow

Page 30: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

30

5.text-shadow6.gradient

229 border-radius

230 Old-skool: code contortions

231 border-radius• Tips & issues

– Different syntax for older versions of webkit browsers

• Browser Support– IE does not support, Opera: 10.50+ only

232 border-radius

#contentcolumn {-moz-border-radius-topleft: 20px;-moz-border-radius-topright: 20px;-webkit-border-top-left-radius: 20px;-webkit-border-top-right-radius: 20px;border-radius: 20px 20px 0 0;}

233 border-radius

#contentcolumn {-moz-border-radius: 20px 20px 0 0;-webkit-border-top-left-radius: 20px;-webkit-border-top-right-radius: 20px;border-radius: 20px 20px 0 0;}

234 Graceful Degradation: border-radius• Square corners are okay

• Extra credit: serve images through conditional comments

235 Graceful Degradation: border-radiusIn modern browsers

236 Graceful Degradation: border-radiusIn modern browsers

237 Full solution: border-radius#contentcolumn {

margin: -40px 3% 0 3%;width: 42%;-moz-border-radius: 20px 20px 0 0;-webkit-border-top-left-radius: 20px;-webkit-border-top-right-radius: 20px;-moz-box-shadow: 0 5px 20px rgba(0,0,0,0.6);-webkit-box-shadow: 0 5px 20px rgba(0,0,0,0.6); box-shadow: 0 5px 20px rgba(0,0,0,0.6);

Page 31: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

31

}

238 Full solution: border-radiusConditional Comment:<!--[if gte IE 6]><link rel="stylesheet" type="text/css" href="ohhai_ie78.css" /><![endif]-->

IE7/8 CSS#contentcolumn {background: url(bg_content_left.png) top left no-repeat;display: inline; margin: -40px 3% 0 3%;padding: 0 0 0 0;width: 41.9%;}

#content {background: url(bg_content_right.png) top right no-repeat;margin: 7px auto 0 26px;padding: 0 0 50px 0;}

239 Full solution: border-radiusConditional Comment:<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="ohhai_ie6.css" /><![endif]-->

IE6 CSS#contentcolumn {background: transparent url(bg_content_left_nds.gif) top left no-repeat; margin: -40px 3% 0 3%;width: 41.9%;}

#content {background: transparent url(bg_content_right_nds.gif) top right no-repeat;margin: 0 -5px 0 17px;padding: 0 0 0 8px;}

240 Border-radius.com

241 Tools: border-radiushttp://border-radius.com/

http://css3please.com/

http://css3generator.com/

http://www.css3maker.com/index.html

242 border-radius Resourceshttp://www.delicious.com/denisejacobs/border-radius

243 Lab Time• Let’s add border-radius to our example page.

244 rgba

245 rgba

Page 32: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

32

• Tips & issues– Granular control of elements

• Browser Support– IE lt 8 does not support, IE 9 does– You can use the gradient IE filter to give transparency with a color: just make the beginning and

end colors the same.

246 Cross-browser: rgba• Place after regular rgb color property to override in modern browsers; older browsers

will ignore it

• IE bug: use the property background instead of background-color for the regular color

247 Graceful degradation: rgbaIn modern browsers

248 Full solution: rgba.rgba {background-color: #ff0000; /* fallback color in hexidecimal */background-color: transparent; /* transparent is key for the filter to work in IE8. best done through conditional comments */background-color: rgba(255, 0, 0, 0.3);-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#4CFF0000, endColorstr=#4CFF0000)";

/* filter for IE8 */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#4CFF0000, endColorstr=#4CFF0000);

/* filter for older IEs */}

249 Inspiration: rgbahttp://aarronwalter.com/2010/11/01/color-mixing-with-rgba/

250 box-shadow

251 box-shadow• Tips & issues

– Different syntax for mozilla, webkit, and opera browsers

• Browser Support– IE does not support, Opera only 10.5

252 box-shadow.portfolio {-moz-box-shadow: 0 5px 20px rgba(0,0,0,0.6);-webkit-box-shadow: 0 5px 20px rgba(0,0,0,0.6); box-shadow: 0 5px 20px rgba(0,0,0,0.6);}

253 Graceful degradation:

Page 33: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

33

box-shadow

• Okay if users don’t see effect, doesn’t affect usability of the page.

• However, there is a filter for IE: shadow (actually there are 2: dropshadow as well, but shadow is said to be better)

• Extra credit: serve images through conditional comments if you didn’t want to use the filter.

254 Graceful degradation: box-shadowIn modern browsers

255 Full solution: box-shadow.boxshadow {-moz-box-shadow: 3px 3px 10px #333;-webkit-box-shadow: 3px 3px 10px #333;box-shadow: 3px 3px 10px #333; /*standard*/-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#333333')"; /* For IE 8 */filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#333333'); /* For IE 5.5 - 7 */}

256 Inspiration: box-shadow

257 Tools: box-shadowhttp://css3please.com/

http://css3generator.com/

http://www.css3maker.com/index.html

http://westciv.com/tools/box-properties/index.html

258 Resources: box-shadowhttp://www.delicious.com/denisejacobs/box-shadow

259 Lab Time• Let’s add box-shadow to our example page.

260 text-shadow

261 text-shadow• Tips & issues

– Can help accentuate text and improve readability and visual importance

Page 34: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

34

• Browser Support– IE does not support, but you could use a ie filter

262 Graceful degradation: text-shadow• If it doesn’t show up, that’s okay

- No impact on accessibility

• However, there is an IE filter: shadow.

• Extra credit: image replacement

263 Graceful degradation: text-shadowIn modern browsers

264 Full solution: text-shadow.textshadow h2 {text-shadow:1px 1px 2px rgba(48,80,82,0.8);-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#305052')";/* For IE 5.5 - 7 */filter: progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#305052');}

265 Inspiration: text shadowhttp://www.midwinter-dg.com/blog_demos/css-text-shadows/

266 Inspiration: text shadowhttp://desandro.com/articles/the-new-lens-flare/

267 Tools: text-shadowhttp://css3please.com/

http://css3generator.com/

http://www.css3maker.com/index.html

http://westciv.com/tools/text-properties/index.html

268 Resources: text-shadowhttp://www.delicious.com/denisejacobs/text-shadow

269 Lab Time• Let’s add text-shadow to our example page.

270 gradient

271 Old skool: image sprites

Page 35: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

35

272 gradient• Browser Support

– IE does not support (quelle surprise!)– Opera: support of linear from 11.10, radial support will be in 12.0. Below 11.10, no

support– Ergo, so will still need a fallback image* for those browsers.

*which may make you think “then why use it at all?”

273 gradient#mainnav li a {background: #ccc9ba; /* Old browsers */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */background: -ms-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* IE10+ */background: linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* W3C */}

274 Graceful degradation: gradient• Gradient will not appear older browsers

• Establish fallback background image first in code

275 Graceful degradation: gradientIn modern browsers

276 gradient.gradient {background: #f7f6f4; url(gradient_slice.jpg) 0 0 x-repeat; /*background color matches one of the stop colors. The gradient_slice.jpg is 1px wide */background: -moz-linear-gradient(top, #ccc9ba 0%, #f7f6f4 100%); /* FF3.6+ */background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ccc9ba), color-stop(100%,#f7f6f4));

/* Chrome,Safari4+ */background: -webkit-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* Opera 11.10+ */background: -ms-linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%); /* IE10+ */background: linear-gradient(top, #ccc9ba 0%,#f7f6f4 100%);/* W3C */filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ccc9ba', endColorstr='#f7f6f4',GradientType=0 ); /* IE6-9 */}

277 Inspiration: gradientshttp://leaverou.me/css3patterns/

278 Inspiration: gradientshttp://www.standardista.com/cssgradients/

279 Inspiration: gradientshttp://leaverou.me/2011/03/beveled-corners-negative-border-radius-with-css3-gradients/

Page 36: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

36

280 Colorzilla gradient tool

281 Tools: gradienthttp://www.colorzilla.com/gradient-editor/

http://www.westciv.com/tools/gradients/

http://css3please.com/

http://css3generator.com/

282 Resources: gradienthttp://www.delicious.com/denisejacobs/gradient

283 Lab Time• Let’s add a gradient to the example page.

284 Lab TimeWe are going to apply all of the selectors to a page that has already been created with descendent selectors.

Let’s see how we can make the page look exactly the same but with the new CSS3 selectors.

285 Tools: CSS3 Selectors• http://www.quirksmode.org/

compatibility.html

• http://www.evotech.net/blog/2009/02/css-browser-support/

• http://www.findmebyip.com/litmus

286 Resources: CSS3 Selectors• http://www.delicious.com/denisejacobs/

selectors+css3

• http://inspectelement.com/tutorials/a-look-at-some-of-the-new-selectors-introduced-in-css3/

• http://24ways.org/2009/cleaner-code-with-css3-selectors

287 Intensive Hands-On Lab Time

288 Lab TimeLet’s spend the rest of the day playing with our page so far.

Page 37: 1 Introduction to CSS3 - Denise Jacobsdenisejacobs.com/training/css3/2012-04/notes_CSS3intro_day1_04122012.pdf · • be able to recognize CSS3 selectors, properties and values •

37

I will be available for individual questions and help.

289 Tomorrow: More CSS3 Properties, Intro to Responsive Design, and completing page


Recommended