unauthorized evaluation - itcourseware · 2018-03-23 · technologies for the firm include php and...

90
Modernizing Your CSS Skills EVALUATION COPY Unauthorized reproduction or distribution is prohibitied

Upload: others

Post on 14-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Modernizing Your CSS Skills

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 2: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Modernizing Your CSS Skills

(CSS301 version 1.0.0)

Copyright Information

© Copyright 2018 Webucator. All rights reserved.

The Author

Brian Hoke

Brian Hoke is Principal of Bentley Hoke, a web consultancy in Syracuse, New York.The firm serves the professional services, education, government, nonprofit, andretail sectors with a variety of development, design, and marketing services. Coretechnologies for the firm include PHP and Wordpress, JavaScript and jQuery, Rubyon Rails, and HTML5/CSS3. Previously, Brian served as Director of Technology,Chair of the Computer and Information Science Department, and Dean of Studentsat Manlius Pebble Hill School, an independent day school in DeWitt, NY. Beforethat, Brian taught at Insitut auf dem Rosenberg, an international boarding schoolin St. Gallen, Switzerland. Brian holds degrees from Hamilton and Dartmouthcolleges.

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 3: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Accompanying Class Files

This manual comes with accompanying class files, which your instructor or salesrepresentative will point out to you. Most code samples and exercise and solutionfiles found in the manual can also be found in the class files at the locations indicatedat the top of the code listings.

Due to space limitations, the code listings sometimes have line wrapping, whereno line wrapping occurs in the actual code sample. This is indicated in the manualusing three greater than signs: >>> at the beginning of each wrapped line.

In other cases, the space limitations are such that we have inserted a forced linebreak in the middle of a word. When this occurs, we append the following symbolat the end of the line before the actual break: »»

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 4: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Table of Contents1. The Power of CSS..................................................................................1

The Power of CSS............................................................................................1Doing More with Less...............................................................................1A First Example.........................................................................................1Challenges................................................................................................8

CSS Level 3 and CSS Level 4..........................................................................9CSS Level 3..............................................................................................9

CSS Level 4....................................................................................................11Image Values..........................................................................................11Background and Borders........................................................................11Browser Support.....................................................................................12

2. Selectors and Pseudo Classes..........................................................15

Selectors, Pseudo-Classes, and Pseudo-Elements.......................................15Attribute Selectors...................................................................................15

Exercise 1: Styling a Document Using Attribute Selectors..............................19The ::before and ::after Selectors............................................................22The target Pseudo-Class........................................................................25

Exercise 2: Using CSS Target.........................................................................30UI Element States Pseudo-Classes........................................................36

Exercise 3: Using CSS Attribute-State Pseudo-Classes.................................40Negation Pseudo-Class..........................................................................45Structural Pseudo-Classes.....................................................................47

Exercise 4: Using the Structural Attribute Pseudo-Classes............................55Exercise 5: Using nth-of-type Pseudo-Class...................................................72

Pseudo-Elements....................................................................................78

3. Fonts and Text Effects........................................................................83

Fonts and Text Effects.....................................................................................83Fonts on the Web....................................................................................83Font Services..........................................................................................83

Exercise 6: Using Font Services.....................................................................90The @font-face Rule...............................................................................96

Exercise 7: Using @font-face........................................................................100Text Shadow..........................................................................................104Word Wrapping.....................................................................................104

Exercise 8: Text Shadow and Word Wrap.....................................................107

iVersion: 1.0.0. Printed: 2018-03-20.

Table of Contents

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 5: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

4. Colors, Gradients, Background Images, and Masks......................111

Colors, Gradients, Background Images, and Masks.....................................111Color.....................................................................................................111The opacity Property.............................................................................116

Exercise 9: Using HSL & Opacity..................................................................121Backgrounds.........................................................................................127

Exercise 10: Multiple Background Images with background-clip,background-origin, and background-size......................................................133

5. Borders and Box Effects...................................................................139

Borders and Box Effects...............................................................................139Image Borders......................................................................................139

Exercise 11: Image Borders..........................................................................145Rounded Corners..................................................................................148Box Shadow..........................................................................................151

Exercise 12: Rounded Corners & Drop Shadow...........................................156

6. Transitions, Transforms, and Animations........................................163

Transitions & Transforms...............................................................................163Transitions.............................................................................................163

Exercise 13: Transitions................................................................................170

7. Layout: Columns and Flexible Box..................................................199

Columns........................................................................................................199Exercise 16: Columns...................................................................................205Flexible Box Layout Module..........................................................................208

Examples..............................................................................................208Exercise 17: Flexible Box Layout..................................................................216

8. Vendor Prefixes.................................................................................225

What are Vendor Prefixes?...........................................................................225Maybe They Ain't So Bad..............................................................................225Strategies......................................................................................................226

Autoprefixer...........................................................................................226Exercise 18: Autoprefixer with Gulp..............................................................231

9. Embedding Media..............................................................................239

Embedding Media.........................................................................................239Video Formats..............................................................................................242Styling Video.................................................................................................243Exercise 19: Styling Video.............................................................................246

10. Accessibility Features....................................................................251

Accessibility Features...................................................................................251Web Accessibility..................................................................................251The CSS Speech Module.....................................................................251

© Copyright 2018 Webucator. All rights reserved.ii

Table of Contents

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 6: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

11. Media Queries..................................................................................259

Media Queries..............................................................................................259Targeting Widths and Devices with CSS Media Queries.......................259Responsive Images & the viewport Metatag.........................................266

Exercise 20: Responsive Design..................................................................270

12. Sass..................................................................................................281

Preprocessors...............................................................................................281Exercise 21: Sass.........................................................................................283

13. Frameworks.....................................................................................287

Frameworks..................................................................................................287Bootstrap......................................................................................................288

Setting up Bootstrap.............................................................................288Display Utility Classes...........................................................................297

Foundation....................................................................................................297Setting Up Foundation..........................................................................298

UIkit...............................................................................................................306Setting Up UIkit.....................................................................................306

Exercise 22: Bootstrap..................................................................................315

14. Grid Layout......................................................................................325

CSS Grid Layout...........................................................................................325Styling the Parent Element...........................................................................325Exercise 23: Grid Layout...............................................................................333Styling Grid Children Elements.....................................................................337Controlling Grid Line Size: Gaps...................................................................345Exercise 24: Creating Modern Art.................................................................348Grid Layout for Page Layout.........................................................................353Grid Layout and Media Queries....................................................................358Exercise 25: Page Layout with Grid Areas....................................................360

15. CSS Level 4 Selectors.....................................................................369

CSS Level 4 Selectors..................................................................................369Logical Combinations...................................................................................369

:matches().............................................................................................369Case Insensitivity..........................................................................................372

16. Going Forward/Additional Resources...........................................375

Going Forward/Additional Resources...........................................................375What's Next?.........................................................................................375Online Resources.................................................................................375Get Involved..........................................................................................377

Exercise 26: Testing CSS..............................................................................379

iiiVersion: 1.0.0. Printed: 2018-03-20.

Table of Contents

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 7: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 8: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

The Power of CSS1.

In this lesson, you will learn...

1. How we can use CSS to render visual and experience aspects of web pages forwhich we previously turned to images, JavaScript, or other techniques.

2. Some of the challenges we face using CSS given the current state of browsersupport.

3. An overview of CSS Level 3 and CSS Level 4.

CSS Level 3 and Level 4 offers us the ability to craft visual styles and userexperiences previously unavailable to us with earlier version of cascading stylesheets, and lets us avoid the use of static images, JavaScript, and other techniquesfor rendering fonts, colors, animations, and other aspects of the web experience.

The Power of CSS1.1

Doing More with Less

CSS Level 3 - the third iteration of the Cascading Style Sheet standard - offers webdesigners and developers a broad range of powerful techniques. We can use CSSLevel 3 to:

• Render text with nonstandard fonts.• Animate elements on the page.• Display background gradients.• Selectively alter styles depending on properties (e.g., screen width) of the user's

device.• And lots more.

In the past, we would rely on images (to display text, say, in a nonstandard font, orto show a gradient background for an element), Flash or JavaScript (to animate anelement on the screen or respond to user events), or other techniques to enhance thelook and behavior of the content we present to our users. Some of those techniquesstill have their place, but CSS Level 3 offers us a broader, more mature set of toolsto bring to bear on the challenge of building the very best sites for our intendedaudiences.

Let's look at an example of a simple web page that manifests some of the power ofCSS Level 3.

Page 1 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 9: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

A First Example

Consider a page designed to present links to a few web resources on CSS - openClassFiles/the-power-of-css3/index.html in a text editor to view the code and abrowser to view the page. The page offers users button-type headers for each of thecategories; clicking on the button expands the content below it (a snippet of text anda link) in accordion fashion. Here's a screenshot of the page, with the second ("W3C")element open:

The font for the title, buttons, and content is nonstandard; that is, it's not Arial,Georgia, or any of the other CSS Web Safe Fonts we can be sure most users willhave on their systems. The buttons should fill the available width of the screen, withsome padding on either side. Clicking any of the three buttons should expand thecontent beneath and close up the non-clicked buttons' content. We'd like the pageto render nicely - to stay true to both the look and the interaction specs - on anybrowser, of course, as well as on mobile devices like an Android phone or iPhoneand on tablets like an iPad.

A few years ago, we might have gone about developing some elements on the pageas follows:

© Copyright 2018 Webucator. All rights reserved.Page 2 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 10: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

• Use an image for the "CSS Links" title at top (to display the text in ournonstandard font).

• Use an image for the buttons, to display with rounded corners, gradientbackground, and drop shadow on the button text.

• Use JavaScript - the jQuery library, perhaps - to handle user events ("onclick")to selectively show and hide the content underneath each button.

Of course, these techniques come with some drawbacks:

• Using an image to display the "CSS Links" text is cumbersome - less easy tochange as we update our page in the future - and won't be as readily accessibleto search engine spiders, content syndication feeds, or users who employassistive technologies (like screen readers).

• Apart from rendering all of the text as an image, we have no easy way to usea nonstandard font for the body text.

• Using an image for the button offers the same drawbacks as rendering text asan image - and makes it less easy for us to make the buttons fill the width ofthe allotted space in a responsive manner.

• JavaScript certainly works to fashion the accordion functionality - but it'd benice if we didn't need to introduce another technology here, if possible.

• Sniffing the http request can tell us something about the user's device - and wecan present a different style sheet in response - but this, too, is cumbersome:the "user-agent" string in the request can be difficult to decode, and how tohandle future devices, that might not yet exist?

Unsurprisingly (this is a CSS course, after all!), we can accomplish all of our goalsusing CSS alone. While we'll spend lots of time later in the course on each of theseareas (and many more) in detail, let's take a quick look now at some code to see howwe can leverage some key CSS Level 3 capabilities.

First, let's look at the markup for our page. Open up ClassFiles/the-power-of-css3/Demos/index.html in a code editor:

Page 3 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 11: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

the-power-of-css3/Demos/index.html

<!DOCTYPE html> 1.-------Lines 2 through 10 Omitted-------

<body> 11. <div id="main"> 12. <h1>CSS Links</h1> 13. <dl> 14. <dt><a href="#wikipedia">Wikipedia</a></dt> 15. <dd id="wikipedia"> 16. <p>Cascading Style Sheets (CSS) is a style sheet language used for

describing the presentation semantics&hellip;</p> 17.

<p><a href="http://en.wikipedia.org/wiki/Cascad »» ing_Style_Sheets"><span>Read More:</span> http://en.wikipedia.org/wiki/Cascading_Style_Sheets</a></p>

18.

</dd> 19. <dt><a href="#w3c">W3C</a></dt> 20. <dd id="w3c"> 21. <p>This page summarizes the relationships among specifications,

whether they are finished standards or drafts. Below, each title links to the most recent version of a document.</p>

22.

<p><a href="https://www.w3.org/stan »» dards/techs/css#w3c_all"><span>Read More:</span> https://www.w3.org/standards/techs/css#w3c_all</a></p>

23.

</dd> 24.-------Lines 25 through 29 Omitted-------

</dl> 30. </div> 31.</body> 32.</html>33.

Code Explanation

We're using a simple HTML5 shell - note that the first link is <!DOCTYPE html>.An <h1> tag is our title ("CSS Links"). An html definition list (<dl>) wraps the

© Copyright 2018 Webucator. All rights reserved.Page 4 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 12: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

three links - each button-header is a term (<dt>) and each associated content (i.e.,the content that shows/hides) is a description (<dd>).

Here's a view of the page before we apply any styles:

We'll now apply some CSS. First we link, via the <link> tag, some CSS to resetall styles to remove browser inconsistencies; we'll use Eric Meyer's popular code(http://meyerweb.com/eric/tools/css/reset/) here. Open up the file ClassFiles/the-power-of-css3/Demos/reset.css to view the CSS code.

Next, we'll apply styles to make the page look and behave as detailed above; openup ClassFiles/the-power-of-css3/style.css to examine the CSS. First, we can useGoogle Web Fonts (http://www.google.com/webfonts) to bring in a specific font

Page 5 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 13: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

(Open Sans (http://www.google.com/webfonts/specimen/Open+Sans)) with the lineof code

<linkhref="http://fonts.googleapis.com/css?family=Open+Sans"rel="stylesheet" type="text/css">

in the <head> of ClassFiles/the-power-of-css3/Demos/index.html. We apply

font-family: 'Open Sans', sans-serif;

to the <body> (in ClassFiles/the-power-of-css3/Demos/style.css) to render all textin this font.

We'll now style the definition list, the core of our page. The <dl> tag gets a styleof width:100% which, given that this element sits inside of the <div> with id#main and div#main is styled to have a max-width of 720 pixels, ensures thatthe definition list fills the center of the screen up to the maximum width allocatedto it.

Each of the three <dt> elements - the button-headers - is styled as follows:

© Copyright 2018 Webucator. All rights reserved.Page 6 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 14: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

dl dt { text-align: center; padding: .5em 2em .55em; text-shadow: 0 1px 1px rgba(0,0,0,.3);

/* rounded corners for the buttons */ border-radius: .5em;

/* slight dropshadow */ box-shadow: 0 1px 2px rgba(0,0,0,.2);

border: solid 1px #da7c0c;

background: #f78d1d; /* CSS gradient background for browsers that support it */ background: linear-gradient(#faa51a, #f47a20);

margin-bottom: 1em;}

We use the CSS Level 3 text-shadow and box-shadow properties to add dropshadowing to the text label and the buttons, respectively, and the CSS Level 3border-radius property to round the corners of the buttons.

We apply a gradient background - with lighter orange on top and darker orange onbottom - with linear-gradient. Older browsers will see just a flat orangebackground with no gradient.

Next, a style for the definition - the initially hidden content for each item:

dl dd { color: #999; overflow: hidden;

/* transition when height changes */ transition: height 0.25s ease;}

Here we apply a CSS Level 3 transition: the height (the change for which we'llhandle a little farther down in the style sheet) should change over the course of 1/4of a second (0.25s), rather than happening instantly. We specify the timing function("ease") so that the transition starts slowly, speeds up, then slows near the end.

The following CSS allows browsers to break long strings of text with no spaces intomultiple lines, rather than extending (as would be the case without these rules) pastthe right edge of the displayed area:

Page 7 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 15: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

dl dd p a { color: #f78d1d; text-decoration: none;

/* ensure that long strings (like URLs) without spaces will break over multiple lines, if needed */ word-break: break-all; word-break: break-word; hyphens: auto;}

This will be especially important when our page is viewed on a mobile device, witha narrower screen.

The next two CSS rules effect the open- or closed-ness of the content:

dl dd:not(:target) { height: 0;}

dl dd:target { height: 7em;}

CSS allows us to style an element referenced in a fragment on the end of the page'sURL. Note that, when a user clicks on one of the links in a button on the page, theuser visits a URL like ClassFiles/the-power-of-css3/index.html#wikipedia; we exploitthe CSS Level 3 :target pseudo-selector to style the element corrresponding tothe fragment (like "wikipedia") at the end. Those elements which don't correspondto the target (:not(:target)) get a height of 0; the element that does match the:target, if any, gets a height of auto.

The next CSS rule adjusts the page slightly when viewed on a device with a smallscreen:

@media only screen and (max-device-width: 480px) { dl dd:target { height: 10em; }}

The font size for the "open" item was a little small when viewed on my phone; thismedia query says "make the font size 1.2em when viewed on a device whose screenwidth is less than 480px".

Nothing up our sleeves here - no images or JavaScript were harmed (or used) in thecreation of this page.

© Copyright 2018 Webucator. All rights reserved.Page 8 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 16: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Challenges

Sadly, our solution won't work on all browsers - older versions of Internet Explorerprior to 9 won't display correctly, for instance. A key theme throughout this coursewill be when to (and how to) use CSS Level 3 (and Level 4) techniques appropriately:

• Is the desired effect something that has to work for all users, regardless ofbrowser in use?

• If so, can we code the effect in such a manner that those with older/less-capablebrowsers will see an appropriate fall-back style or interaction? That is, can weensure that our code degrades gracefully?

• Can we make assumptions about our audience that tells us whether, and when,to employ a given CSS Level 3 technique?

We'll review these concepts in detail as we move through the course. Of course,using these newer CSS features depends upon the target browser support for yourwebsite or application.

CSS Level 3 and CSS Level 41.2

CSS Level 3

CSS Level 3 (often referred to as "CSS3"), like earlier versions of CSS, allows forseparation of content from presentation: well-formed, semantic markup (whether itbe XHTML, HTML5, or even XML) connotes the meaning of the content: an <h1>implies a page title, while an HTML5 <nav> tag signifies a navigation element.With CSS, we define the content's visual presentation: the colors and fonts in whichtext is rendered, for example, or the manner in which various elements are positioned.We can present different styles for different media (like screen or print) and, withCSS Level 2, craft styles in response to the screen width or other properties of theuser's device.

Unlike previous versions of CSS, CSS Level 3 has been released as a series ofmodules. Whereas, for example, the CSS2 specification(http://www.w3.org/TR/CSS21/) completely defines that version of CSS2, CSS3 isorganized into separate modules. Progress on each module, representing either anextension to features from CSS2 or new capabilities, proceeds independently. TheW3C's CSS Current Status (https://www.w3.org/standards/techs/css) lists the statusof the various modules. Ultimately, support among popular browsers for each moduledictates the degree to which you can safely use a given module and expect thatvisitors to your pages will see the style you intend.

CSS Level 3 includes the following modules:

Page 9 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 17: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Selected CSS Level 3 ModulesDescriptionModule

W3C Link

Selectors are patterns that match againstelements in a tree, and as such form one ofseveral technologies that can be used to selectnodes in an XML document.

Selectors Level 3

Selectors Level 3 (https://www.w3.org/TR/css3-selectors/)

Borders consisting of images, boxes withmultiple backgrounds, boxes with roundedcorners and boxes with shadows

CSS Backgrounds and Borders Module Level3

CSS Backgrounds and Borders Module Level 3 (https://www.w3.org/TR/css-backgrounds-3/)

Color-related properties and values to color thetext, backgrounds, borders, and other parts ofelements in a document; color values andproperties for foreground color and groupopacity.

CSS Color Module Level 3

CSS Color Module Level 3 (https://www.w3.org/TR/css-color-3/)

Font properties and how font resources areloaded dynamically.

CSS Fonts Module Level 3

CSS Fonts Module Level 3 (https://www.w3.org/TR/css-fonts-3/)

A media query consists of a media type andzero or more expressions that check for theconditions of particular media features. Amongthe media features that can be used in mediaqueries are width, height, and color. Withmedia queries, presentations can be tailored toa specific range of output devices withoutchanging the content itself.

Media Queries

Media Queries (https://www.w3.org/TR/css3-mediaqueries/)

Multi-column layouts: content can be flowedinto multiple columns with a gap and a rulebetween them.

CSS Multi-column Layout Module Level 1

CSS Multi-column Layout Module Level 1 (https://www.w3.org/TR/css-multicol-1/)

We will cover each of these modules in more detail later in this class.

© Copyright 2018 Webucator. All rights reserved.Page 10 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 18: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

CSS Level 41.3

CSS Level 4 has no single specification; like CSS Level 3, CSS Level 4 is a collectionof "level 4" modules, each of which is developed (and, potentially, adopted as astandard) on its own timeline. These modules are very much, as of this writing, inthe development stage. Some of the more intriguing modules include:

Image Values

This module enables the use of the image() function in CSS, allowing us toconstruct a style like the following:

div.darkbackground { color: #fff; background: image("black.png", #000);}

In which the color #000 (black) is used as background if the image does not load.

CSS already has a mechanism allowing for multiple backgrounds:

div.darkbackground { color: #fff; background: url("black.png") #000;}

However, if the image specific by the url() function does load and had sometransparency in it, then the background color (#000) would still show, behind thetransparency. The CSS image() function would allow us to include a fallbackbackground color if and only if the specified background image did not load.

Learn more: W3C CSS Image Values and Replaced Content Module Level 4 Specification (https://www.w3.org/TR/css-images-4/)

Background and Borders

The "CSS Backgrounds and Borders Module Level 4" is a draft; as the W3C's CSSWorking Group page on the module (https://drafts.csswg.org/css-backgrounds-4/)states, "This spec is not yet ready for implementation. It exists in this repository torecord the ideas and promote discussion." The draft includes proposed extensionsof how we can render borders and backgrounds in CSS. For instance, a newcorner-shape property would allow us to specify a variety of shapes for cornersof elements defined via the (existing) border-radius property. A style such as

Page 11 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 19: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

div { border-radius: 5px; corner-shape: notch;}

with a corner-shape of notch would style an element where the border radiidefine a concave rectangular notch at the corner. In addition to notch, other valueswould be round, bevel, and scoop.

As mentioned above, this module - and other CSS Level 4 modules - are very muchin the draft stage; browser support will be limited.

Learn more: CSS Backgrounds and Borders Module Level 4 (https://drafts.csswg.org/css-backgrounds-4/)

Browser Support

Various browsers offer differing levels of support for different CSS Level 3 andCSS Level 4 modules. Older version of Internet Explorer tend to provide spottysupport for many of the newer modules; more recent versions of browsers (includingboth IE and many mobile browsers) offer better support.

Of course, careful attention to the intended audience for your sites, to the currentstate of browser support for CSS features you might use, and to fallback strategiesfor older browsers ensures that the most users get the most meaningful experiencefrom the pages you build. Online resources such as CanIUse.com (http://caniuse.com/) offer a helpful list of feature support, for CSS as well as othertechnologies such as HTML5. For instance, http://caniuse.com/#feat=css-sel3 listshow well (or not) browsers such as Internet Explorer, Firefox, Chrome, Safari,

© Copyright 2018 Webucator. All rights reserved.Page 12 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 20: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Opera, and others support the use of CSS selectors such as :nth-child,:first-of-type, etc.:

Conclusion1.4In this lesson, you have learned:

• How CSS offers designers and developers the ability to present complex stylesand user experiences.

• How CSS enables us to skip the use of images, JavaScript, and other techniques.• An overview of CSS Level 3 and CSS Level 4.

Page 13 of 380Version: 1.0.0. Printed: 2018-03-20.

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 21: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

© Copyright 2018 Webucator. All rights reserved.Page 14 of 380

The Power of CSS

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 22: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Selectors and Pseudo Classes2.

In this lesson, you will learn...

1. How to use CSS wildcard selectors.2. How to use CSS ::before and ::after selectors.3. How to use CSS pseudo-classes.4. How to use CSS pseudo-elements.

CSS Level 3 introduced new selectors, new pseudo-classes, and newpseudo-elements, giving web designers and developers more powerful ways in whichto target elements for styling.

Selectors, Pseudo-Classes, and Pseudo-Elements2.1

Attribute Selectors

CSS Level 3 introduces four new attribute selectors, allowing us to more preciselytarget elements whose attributes begin, end, or contain a specified string:

New Selectors in CSS3NotesExample(s)Selector

Every <img> whose alt attribute valuestarts with "abc"

img[alt^="abc"][attr^=val]

Every <img> whose alt attribute valueends with "xyz"

img[alt$="xyz"][attr$=val]

Every <img> whose src attribute valuecontains string "def"

img[alt*="def"][attr*=val]

These selectors can be useful if the markup to which we are applying styles do nothave convenient ids or classes, or if some aspect of the code lends itself to queryingagainst a substring of an attribute value. Let's look at an example in which we targetthe href attribute of some simple links. Open ClassFiles/selectors-pseudoclasses/Demos/attributeselectors.html in a browser and in a file editor to check the code.

Page 15 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 23: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/attributeselectors.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Attribute Selectors</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.a[href^="https"] { 10.

font-style: italic; 11. } 12. a[href$="/"] { 13. color:#000; 14. } 15. a[href*="wiki"] { 16. text-decoration: underline; 17. }18. </style> 19.</head> 20.<body> 21. <div id="main"> 22. <h1>CSS3 Attribute Selectors</h1> 23. <p>Here are some popular websites:</p> 24. <ul> 25. <li><a href="https://www.google.com">Google</a></li> 26. <li><a href="http://en.wikipedia.org/wi »»

ki/Main_Page">Wikipedia</a></li> 27.

<li><a href="http://twitter.com/">Twitter</a></li> 28. </ul> 29. </div> 30.</body> 31.</html>32.

© Copyright 2018 Webucator. All rights reserved.Page 16 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 24: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

The code above renders the following:

We include a reset style sheet (reset.css) and a general style sheet (style.css) to rendersome general styles for the page. We include the specific styles for this page in the<head> of the page - we'll do this throughout the course, to make easier scanningthe relevant styles, unless the demo requires many lines of CSS code.

The first CSS rule (a[href^="https"]) targets any link whose href attributestarts with "https"; the Google link is thus italicized.

The second CSS rule (a[href$="/"]) targets any link whose href attributeends with a forward slash. The effect of this rule is color the Twitter link in black.

Page 17 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 25: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

The third rule (a[href*="wiki"]) targets any link with an href attributecontaining (anywhere in the string) the text "wiki". This rule catches the Wikipedialink, which is thus underlined.

We can also use attribute selectors to target class or id names, regardless of theelement to which they are applied:

[class*="ew"] { font-weight:bold; }

This would make bold the text within elements such as <div class="new">,<p class="news">, etc.

© Copyright 2018 Webucator. All rights reserved.Page 18 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 26: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Styling a Document Using Attribute SelectorsExercise 110 to 15 minutes

In this exercise, you will use CSS3 attribute selectors to style text.

1. Open ClassFiles/selectors-pseudoclasses/Exercises/attributeselectors.html ina text editor.

2. Add a CSS rule where indicated (inside the <style></style> tags) tocolor the text red inside of any element with a class name containing the string"special".

3. Note that there are four elements: the paragraph of class "special" and div ofclass "especial" should be red; the other paragraph and div should not be red.

4. Check your work in a browser.

Page 19 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 27: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Exercise Solution

selectors-pseudoclasses/Solutions/attributeselectors.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Attribute Selectors</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.[class*="special"] { 10.

color:red; 11. }12. </style> 13.</head> 14.<body> 15. <div id="main"> 16. <h1>CSS3 Attribute Selectors Exercise</h1> 17. <p class="special">This text should be red</p> 18. <div class="especial">This text should also be red</div> 19. <p class="normal">This text should not be red</p> 20. <div>This text should also not be red</div> 21. </div> 22.</body> 23.</html>24.

© Copyright 2018 Webucator. All rights reserved.Page 20 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 28: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

The solution should look as follows:

We target class names containing "special" with the selector[class*="special"].

Page 21 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 29: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

The ::before and ::after Selectors

These two selectors have been around for a while - they predate CSS Level 3 - butare useful and worth reviewing here. Each allows us to insert content via CSS toselected elements.

Selectors ::before and ::afterExampleSelector

p.highlight {content: 'Note: '} would insert the text"Note: " before the existing HTML contents of paragraphs with classhighlight

::before

p.note {content: '*'} would insert the character "*" afterthe existing HTML contents of paragraphs with class note

::after

Let's look at an example:

© Copyright 2018 Webucator. All rights reserved.Page 22 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 30: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/beforeafter.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>::before and ::after</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.a.external::after { 10.

content: ' \00bb'; 11. }12.

13. blockquote { 14. background-color:#efefef; 15. padding:35px 25px 25px 50px; 16. margin:20px 15% 20px 50px; 17. position: relative; 18. } 19.

20.blockquote::before { 21.

content: '"'; 22. font-size:70px; 23. position: absolute; 24. left:15px; 25. top:10px; 26. }27. </style> 28.</head> 29.<body> 30. <div id="main"> 31. <h1><code>::before</code> and <code>::after</code></h1> 32.

Page 23 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 31: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

<p>Here is some sample text with an <a href="/about/">internal link</a> and an <a href="http://www.google.com/" class="external">ex »» ternal link</a>. Here is some sample text with an <a href="/about/">internal link</a> and an <a href="http://www.google.com/" class="external">external link</a>. Here is some sample text with an <a href="/about/">internal link</a> and an <a href="http://www.google.com/" class="external">external link</a>.</p>

33.

<blockquote>This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a blockquote. This is a block »» quote. This is a blockquote. </blockquote>

34.

<p>This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. This is an ordinary paragraph. </p>

35.

</div> 36.</body> 37.</html>38.

© Copyright 2018 Webucator. All rights reserved.Page 24 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 32: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

The code above renders the following:

We style links with class external to show the HTML double-right caret (») afterthe link text by using the ::after selector. Note that we have to use escapedhexidecimal representation (\00bb) to display the character.

We style blockquotes to have a background color and some margin and padding.We display a large double-quote character using the ::before selector.

The target Pseudo-Class

The :target Pseudo-ClassNotesExample(s)Selector

Current active #news element (clicked on a URLcontaining that anchor name)

#news:target:target

We can specify style rules for an element referred to in a web page's address - a URI(uniform resource locator (http://en.wikipedia.org/wiki/Uniform_resource_identifier))that ends with a hash tag followed by an anchor identifier (sometimes known as a

Page 25 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 33: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

fragment identifier). For instance, the URIhttp://www.w3.org/TR/selectors/#target-pseudo points to a specific part (in thiscase, an h4 with id target-pseudo) of the web page that lives athttp://www.w3.org/TR/selectors/. The CSS3 pseudo-class target allows us to stylean element matched by the fragment identifier; if the URI by which the user reachesthe page has no fragment identifier, then the document has no target element.

Let's check out an example. Open ClassFiles/selectors-pseudoclasses/Demos/targetselector.html in a browser and in a file editor to check the code.

© Copyright 2018 Webucator. All rights reserved.Page 26 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 34: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/targetselector.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Target Selector</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.p.tar:target { 10.

background: SlateGrey; 11. color:Snow; 12. }13. </style> 14.</head> 15.<body> 16. <div id="main"> 17. <h1>CSS3 Target Selector</h1> 18. <p class="tar" id="target-1">one</p> 19. <p class="tar" id="target-2">two</p> 20. <p class="tar" id="target-3">three</p> 21. <p class="tar" id="target-4">four</p> 22. <p class="tar" id="target-5">five</p> 23. <p class="tar" id="target-6">six</p> 24. <p class="tar" id="target-7">seven</p> 25. <p class="tar" id="target-8">eight</p> 26. <p class="tar" id="target-9">nine</p> 27.-------Lines 28 through 40 Omitted-------

</div> 41.</body> 42.</html>43.

Page 27 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 35: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

A div (with id of target-example-one) contains multiple ps, each with classtar and with ids of target-1, target-2, etc. Without a target on the end ofthe URI, the page looks as follows:

The CSS p.tar:target matches any paragraph of class tar that is the targetof the page's URI. For instance, a URI like SelectorsPseudoClasses/Demos/targetselector.html#target-2 would invoke the CSS rule on the second paragraph (the

© Copyright 2018 Webucator. All rights reserved.Page 28 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 36: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

paragraph with an id of target-2, styling it with a darker background color andlighter text color. (Note that we're using some new CSS3 colors here.)

Page 29 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 37: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Using CSS TargetExercise 215 to 20 minutes

In this exercise, you will use the CSS target pseudo-class to style elements on apage in response to the target fragment on the page's URI.

1. Open ClassFiles/selectors-pseudoclasses/Exercises/targetselectors.html in atext editor.

2. The page contents and style display a simple navigation at top to allow usersto jump lower on the page to the desired item; note that the navigation is markedup as an unordered list of links inside an HTML5 <nav> element and eachitem below is an <article>.

3. Add CSS rules where indicated (inside the <style></style> tags) tohighlight the selected item - that is, the item corresponding to the target on theURL, after the user clicks on a link.

4. Change the border color, background color, and link color for the highlighteditem.

5. Check your work in a browser.

© Copyright 2018 Webucator. All rights reserved.Page 30 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 38: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Page 31 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 39: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Exercise Solution

selectors-pseudoclasses/Solutions/targetselector.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Target Selector</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9. article { 10. padding: 0.5em 1em; 11. margin: 0.5em 0; 12. border: 2px solid AntiqueWhite; 13. } 14. article h2 { 15. font-size:1.5em; 16. } 17. article p { 18. margin:0; 19. } 20.article:target { 21.

color: #fff; 22. background:DarkGreen; 23. border: 2px solid #000; 24. } 25. article:target a { 26. text-decoration: underline; 27. }28. </style> 29.</head> 30.<body> 31. <div id="main"> 32. <h1>CSS3 Target Selector</h1> 33. <p>Some CSS resources on the web:</p> 34. <nav> 35. <ul> 36. <li><a href="#wiki">Wikipedia</a></li> 37. <li><a href="#w3c">W3C</a></li> 38. <li><a href="#webucator">Webucator</a></li> 39.

© Copyright 2018 Webucator. All rights reserved.Page 32 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 40: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

</ul> 40. </nav> 41. <article id="wiki"> 42. <h2>Wikipedia</h2> 43. <p>A detailed overview of CSS history, syntax, browser support, and

more.</p> 44.

<p><a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">Learn More</a></p>

45.

</article> 46. <article id="w3c"> 47. <h2>W3C</h2> 48. <p>The official CSS specifications.</p> 49. <p><a href="http://www.w3.org/Style/CSS/Overview.en.html">Learn

More</a></p> 50.

</article> 51. <article id="webucator"> 52. <h2>Webucator</h2> 53. <p>Online training courses in web design and development.</p> 54. <p><a href="http://www.webucator.com/webdesign/css.cfm">Learn

More</a></p> 55.

</article> 56. </div> 57.</body> 58.</html>59.

Page 33 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 41: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

Before adding styles to address the highlighting - or before the user clicks on a link- looks as such:

If the user were to click the second ("W3C") link, the page should look like this:

© Copyright 2018 Webucator. All rights reserved.Page 34 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 42: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

We use the :target pseudo-class to style the <article> corresponding to thefragment, if one exists, on the end of the URI for the page. A fragment of, forexample, "#w3c", would match the id of the second <article> - and thus theborder color, background color, and text color of that item would change.

Page 35 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 43: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

UI Element States Pseudo-Classes

Used mostly on form elements, the element-state pseudo-classes :enabled,:disabled, and :checked allow us to style page elements based on their state:

UI Element States Pseudo-ClassesNotesExample(s)Selector

Every <input> element that is enabledinput:enabled:enabled

Every <input> element that is disabledinput:disabled:disabled

Every <input> element that is checkedinput:checked:checked

:enabled is usually applied to inputs and other form widgets - it targets allelements that are active for user input. Its opposite, :disabled, targets elements(with attribute disabled) not available for user input. :checked matcheselements, usually check boxes and radio buttons, that are currently checked, eitherfrom a user's action or from an initial state.

We'll look now at a simple example in which we style elements based on theirenabled, disabled, and checked states. Open ClassFiles/selectors-pseudoclasses/Demos/attribute-state-pseudo-classes.html in a browser and in a file editor to checkthe code.

© Copyright 2018 Webucator. All rights reserved.Page 36 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 44: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/attribute-state-pseudo-classes.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Attribute State Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.input:enabled { 10.

border:1px solid Brown; 11. } 12. input:disabled { 13. border:1px solid DarkKhaki; 14. background:Bisque; 15. } 16. span.thanks { 17. font-size:.8em; 18. padding:0.25em; 19. display:none; 20. color:DeepSkyBlue; 21. font-style:italic; 22. } 23. input:checked + span.thanks { 24. display:inline; 25. }26. </style> 27.</head> 28.<body> 29. <div id="main"> 30. <h1>CSS3 Attribute State Pseudo-Classes</h1> 31. <p>Please use the fictional form below to register for our site:</p>32.

<form action="#" method="get"> 33. <label for="fname">First Name</label> <input type="text" name="fname"

id="fname"> 34.

<label for="lname">Last Name</label> <input type="text" name="lname" id="lname">

35.

<label for="fee">Registration Fee</label> <input type="text" name="fee" id="fee" disabled="disabled" value="$50.00">

36.

Page 37 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 45: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

<label for="mailinglist">Join mailing list?</label> <input type="checkbox" name="mailinglist" id="mailinglist" value="1"> <span class="thanks">Thanks - expect to receive your first email soon</span>

37.

<br> 38. <input type="submit" value="Submit"> 39. </form> 40. </div> 41.</body> 42.</html>43.

Code Explanation

A simple registration form presents users with fields for first and last names and acheck box to opt in for joining a mailing list. A "Registration Fee" field shows the

© Copyright 2018 Webucator. All rights reserved.Page 38 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 46: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

user the cost of registration but is not (because of a disabled attribute) open foruser input.

We style enabled form fields with a red border and disabled form fields with ayellowish background color. We target the <span> of class "thanks" via the:checked pseudo-class and the CSS + selector (selecting the element immediatelyfollowing) to unhide the message "Thanks - expect to receive your first email soon".

Page 39 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 47: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Using CSS Attribute-State Pseudo-ClassesExercise 315 to 20 minutes

In this exercise, you will style a form to highlight the difference between enabledand disabled form elements and to show/hide informational text based on the checkedstate of an element.

1. Open ClassFiles/selectors-pseudoclasses/Exercises/attribute-state-pseudo-classes.html in a text editor.

2. The form on the page represents a short conference registration form, in whichthe user enters his or her full name, selects the type of registration ("full" or"sessions only"), and chooses the manner ("check" or "credit card") in whichthey will make payment.

3. Note that a short bit of JavaScript (by way of the jQuery library) populates theread-only "Total Fee" field in response to the user's selection; this is done foryou.

4. Style the page so that the enabled elements are visually distinct from the disabledelements.

5. Add two <div> elements, one after each of the radio buttons for paymenttype. Style the page to hide or display payment information ("make check outto...", "Paypal details appear on next screen") based on the user's choice ofpayment type. Float the <div>s to the right of the payment type radio buttons.

© Copyright 2018 Webucator. All rights reserved.Page 40 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 48: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

6. Your completed page should look something like this:

7. Check your work in a browser.

Page 41 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 49: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Exercise Solution

selectors-pseudoclasses/Solutions/attribute-state-pseudo-classes.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Attribute State Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.input:enabled { 10.

border:1px solid Olive; 11. } 12. input:disabled { 13. border:1px solid OliveDrab; 14. background:Olive; 15. color:White; 16. } 17. div.paymentinfo { 18. border:1px solid OliveDrab; 19. background:Olive; 20. color:White; 21. font-size:.8em; 22. padding:1em; 23. display:none; 24. float:right; 25. width:60%; 26. margin-right:5%; 27. } 28. input:checked + div { 29. display:block; 30. }31. </style> 32. <script src="../Shared/jquery.min.js"></script> 33. <script> 34. $(document).ready(function(){ 35. $('#regtype').change(function() { 36. regtype = $(this).val(); 37. if (regtype == 'all') { 38. $('#fee').val('$100'); 39.

© Copyright 2018 Webucator. All rights reserved.Page 42 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 50: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

} else if (regtype == 'sessions') { 40. $('#fee').val('$50'); 41. } else { 42. $('#fee').val('$0'); 43. } 44. }) 45. }); 46. </script> 47.</head> 48.<body> 49. <div id="main"> 50. <h1>CSS3 Attribute State Pseudo-Classes</h1> 51. <p>Register for one of our free seminars:</p> 52. <form action="#" method="get"> 53. <label for="fullname">Full Name</label> <input type="text"

name="fullname" id="fullname"> 54.

<label for="regtype">Registration Type</label> 55. <select name="regtype" id="regtype"> 56. <option value="">-select-</option> 57. <option value="all">Sessions &amp; Dinner ($100)</option> 58. <option value="sessions">Sessions Only ($50)</option> 59. </select> 60. <label for="fee">Total Fee</label> <input type="text" name="fee"

id="fee" disabled="disabled" value="$0"> 61.

<h2>Payment</h2> 62. <label for="check">Check</label> <input type="radio" name="payment"

id="payment-check" value="check"> 63.

<div id="paymentinfo-check" class="paymentinfo">Please make check payable to "CSS Seminars"</div>

64.

<label for="creditcard">Credit Card</label> <input type="radio" name="payment" id="payment-creditcard" value="creditcard">

65.

<div id="paymentinfo-creditcard" class="paymentinfo">Secure payment details will appear on the next screen</div>

66.

<br> 67. <input type="submit" value="Submit"> 68. </form> 69. </div> 70.</body> 71.</html>72.

Code Explanation

A bit of jQuery populates the (disabled) #fee field in response to the user changingthe registration type. We add two <div>s, each of class "paymentinfo", to displayinformation about each type of payment.

Page 43 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 51: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

We style the form elements depending on their state - :enabled items get a whitebackground, while :disabled items get a dark background and white text.

We style the two <div>s as initially hidden. We set the <div> immediatelyfollowing a checked <input> (input:checked + div) to display as block,unhiding the element.

© Copyright 2018 Webucator. All rights reserved.Page 44 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 52: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Negation Pseudo-Class

The negation pseudo-class :not allows us to target elements that are not a givenelement, do not have a given attribute, or do match specified class or id.

Negation Pseudo-ClassNotesExample(s)Selector

Every element that is not a <div>:not(div):not(selector)

Consider the following example:

Page 45 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 53: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/negation.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Negation Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.p:not(.a) { 10.

color:red; 11. } 12. :not(div) { 13. border-left:2px solid red; 14. padding-left:2px; 15. } 16. a:not([href^="../"]) { 17. text-transform: uppercase; 18. }19. </style> 20.</head> 21.<body> 22. <div id="main"> 23. <h1>CSS3 Negation Pseudo-Classes</h1> 24. <p>paragraph</p> 25. <p class="a">paragraph - class "a"</p> 26. <ul> 27. <li><a href="../index.php">list item</a></li> 28. <li><a href="about.php">list item - class "a"</a></li> 29. </ul> 30. </div> 31.</body> 32.</html>33.

© Copyright 2018 Webucator. All rights reserved.Page 46 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 54: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

Here's a screenshot of the page:

The page contains two paragraphs, one of which is classed as "a", and an unorderedlist with two list items, each of which contain a link.

The first CSS rule, p:not(.a), matches all paragraphs not classed as "a" - thiscolors the second paragraph red.

The second CSS rule, :not(div), adds a red border and some padding to the leftof any element not a <div>.

The last CSS rule, a:not([href^="../"]), displays the text for any link notstarting with "../" as all uppercase letters.

Page 47 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 55: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Structural Pseudo-Classes

© Copyright 2018 Webucator. All rights reserved.Page 48 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 56: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Structural Pseudo-ClassesNotesExample(s)Selector

The root element:root:root

Every <li> thatis the first <li>

li:first-of-type:first-of-type

child of itsparent

Every <li> thatis the last <li>

li:last-of-type:last-of-type

child of itsparent

Every <li> thatis the only <li>

li:only-of-type:only-of-type

child of itsparent

Every <li> thatis the only childof its parent

li:only-child:only-child

Every <li> thatis the second

li:nth-child(2):nth-child(n)

child of itsparent

Every <li> thatis the third child

li:nth-last-child(3):nth-last-child(n)

of its parent,counting backfrom the lastchild

Every <li> thatis the third <li>

li:nth-of-type(3):nth-of-type(n)

child of itsparent

Every <li> thatis the third <li>

li:nth-last-of-type(3):nth-last-of-type(n)

child of itsparent, countingback from thelast child

Page 49 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 57: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

NotesExample(s)Selector

Every <li> thatis the last childof its parent

li:last-child:last-child

Every <li> thathas no children

li:empty:empty

Let's look at an example where we explore the :root, :empty, and the "child"and "of-type" pseudo-classes that don't involve "nth".

© Copyright 2018 Webucator. All rights reserved.Page 50 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 58: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/structural-pseudo-classes.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Structural Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.:root { 10.

border:5px solid MidnightBlue; 11. } 12. p:first-of-type { 13. color:Cyan; 14. } 15. p:last-of-type { 16. border-bottom:2px solid DeepPink; 17. } 18. li:first-child { 19. font-style: italic; 20. } 21. li:last-child { 22. font-weight: bold; 23. } 24. div:only-of-type { 25. border-top:2px solid Orchid; 26. padding-top:5px; 27. } 28. div:only-child { 29. border-left:2px solid Maroon; 30. } 31. :empty { 32. border:2px solid GreenYellow; 33. width:100px; 34. height:10px; 35. }36. </style> 37.</head> 38.<body> 39.

Page 51 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 59: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

<div id="main"> 40. <h1>CSS3 Structural Pseudo-Classes</h1> 41. <div id="div1"> 42. <div>This is a div</div> 43. <p>This is a paragraph in div1.</p> 44. </div> 45. <div id="div2"> 46. <p>This is a paragraph in div2.</p> 47. </div> 48. <ul> 49. <li>First unordered list - first list item</li> 50. <li>First unordered list - second list item</li> 51. <li>First unordered list - third list item</li> 52. </ul> 53. <ul> 54. <li>Second unordered list - first list item</li> 55. <li>Second unordered list - second list item</li> 56. <li>Second unordered list - third list item</li> 57. <li>Second unordered list - fourth list item</li> 58. </ul> 59. <p></p> 60.

61. </div> 62.</body> 63.</html>64.

© Copyright 2018 Webucator. All rights reserved.Page 52 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 60: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

The page contains a collection of div, p, ul, and li elements, which we styleaccording to their status as first of their type within their parent container, last childof their parent, empty, etc. Here's a screenshot of the page:

:root selects the root element - the initial containing block - of the page; for HTMLpages, this is always the <html> element. Here, we style the root with a 5px-thickdark blue border.

p:first-of-type and p:last-of-type target the first and last paragraph,respectively, within their parent container elements. Note the "of-type" aspect ofthese pseudo-classes - it is the first and last paragraph, not first and last child element,that receives the styling. We color the first paragraph as Cyan and give the lastparagraph a pink bottom border.

li:first-child and li:last-child target all list items that are the firstor last child of their parents. Unlike first-of-type and last-of-type,

Page 53 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 61: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

first-child and last-child target those elements that are specifically thelast child element of their parent, regardless of the types of other sibling children.The result of our CSS is to italicize the first list item of each unordered list and tomake bold the last list item of each unordered list.

div:only-of-type matches any <div> which is the only <div> of itsimmediate parent. Both the <div> with id "main" and the <div> that is the firstelement of the <div> with id "div1" have, as a result of our rules, a 2px top borderof color "Orchid".

div:only-child targets any <div> which is the only child of its parent; the<div> with id "main" gets a Maroon left border as a result of this rule.

:empty matches any element that has no children. The last paragraph on the pagegets a greenish border from our rule.

© Copyright 2018 Webucator. All rights reserved.Page 54 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 62: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Using the Structural Attribute Pseudo-ClassesExercise 410 to 15 minutes

In this exercise, you will explore the difference betweenfirst-child/last-child and first-of-type/last-of-type.

1. Open ClassFiles/selectors-pseudoclasses/Exercises/structural-pseudo-classes.html in a text editor.

2. The markup for the page, which is created for you, contains two <div>elements, each of which contains two <div> and two <p> elements. Note theorder of the contained <div>/<p> elements differs on the page.

3. Style the page so that the four "I'm a paragraph" elements are colored red, blue,green, and yellow (in that order).

4. Use only first-child, last-child, first-of-type, andlast-of-type rules to effect the coloring.

Page 55 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 63: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

5. Your completed page should look something like this:

6. Check your work in a browser.

© Copyright 2018 Webucator. All rights reserved.Page 56 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 64: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Page 57 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 65: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Exercise Solution

selectors-pseudoclasses/Solutions/structural-pseudo-classes.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Structural Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9..container { 10.

border:1px solid black; 11. font-size:.8em; 12. padding:.5em 1em; 13. } 14. p:first-of-type { 15. color:red; 16. } 17. p:last-of-type { 18. color:yellow; 19. } 20. p:first-child { 21. color:green; 22. } 23. p:last-child { 24. color:blue; 25. }26. </style> 27.</head> 28.<body> 29. <div id="main"> 30. <h1>CSS3 Structural Pseudo-Classes</h1> 31. <div id="container1" class="container"> 32. <div>I'm a div</div> 33. <p>I'm a paragraph</p> 34. <div>I'm a div</div> 35. <p>I'm a paragraph</p> 36. </div> 37. <div id="container2" class="container"> 38. <p>I'm a paragraph</p> 39.

© Copyright 2018 Webucator. All rights reserved.Page 58 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 66: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

<div>I'm a div</div> 40. <p>I'm a paragraph</p> 41. <div>I'm a div</div> 42. </div> 43. </div> 44.</body> 45.</html>46.

Code Explanation

p:first-of-type selects (and colors in red) the second child element in thefirst (#container1) <div>, since it is the first child element of type <p>.Similarly, p:last-of-type colors in yellow the third child (a paragraph) of thesecond (#container2) <div>, since it is the last child of type <p>.

p:first-child selects (and colors in green) any element that is both a <p> andis the first child of its parent; this targets the first child of the second(#container2) <div>. Last, p:last-child colors in blue the last child ofthe first <div>.

Page 59 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 67: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Let's look now at examples illustrating the use of the "nth" structural pseudo-classes.Open up selectors-pseudoclasses/Demos/structural-pseudo-classes-nth.html in a texteditor to view the code, and in a browser to observe the results.

nth-child

nth-child matches every element that is the nth child of its parent, regardless oftype, where n is an integer, a keyword (odd or even) or a formula. Indexing is one-(not zero-) based; that is, the first element of the collection has index 1.

At its simplest, we can supply an integer parameter to select the nth element. In"Example 1: li:nth-child(3)", we set a background for the list item with text"three" using nth-child(3).

/* CSS */ ul#example1 li:nth-child(3) { background: DarkSalmon; }

<!-- markup --> <ul id="example1"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

Next, consider "Example 2: div#example2 p:nth-child(3)". Note thatnth-child (and nth-last-child, discussed below) disregards the type of

© Copyright 2018 Webucator. All rights reserved.Page 60 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 68: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

the children elements - specifying div#example2 p:nth-child(3) in theexample below means "select the third child of its parent if the child element is ap" - the parent being, in this case, a div. Since the first child of the div is, in thiscase, an h4 element, it is the p with text "two" that has its background color changed:

/* CSS */ div#example2 p:nth-child(3) { background: Maroon; }

<!-- markup --> <div id="example2"> <h3>Numbers</h3> <p>one</p> <p>two</p> <p>three</p> <p>four</p> <p>five</p> <p>six</p> <p>seven</p> <p>eight</p> <p>nine</p> <p>ten</p> </div>

"Example 3: ul#example3 li:nth-child(even)" demonstrates how wecan use keywords odd or even to select all odd or even elements. In this example,we apply a background color to every other (i.e., all even) list items:

Page 61 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 69: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example3 li:nth-child(even) { background: LightSeaGreen; }

<!-- markup --> <ul id="example3"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

The an+b method of specifying the nth-child, demonstrated in "Example 4:ul#example3 li:nth-child(2n+3)", offers a way to match a set of elementsvia a cycle size ("a" - that is, every "a-th" element, with indexing starting at 1) andoffset ("b"). For example, nth-child(2n+3) would match every second elementstarting from the third:

© Copyright 2018 Webucator. All rights reserved.Page 62 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 70: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example4 li:nth-child(2n+3) { background: CornflowerBlue; }

<!-- markup --> <ul id="example4"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

We can also use the an+b method for nth-child with a negative ("b") offset, ineffect selecting a nonexistent first element (one that comes "before" the actual firstelement in the DOM) and selecting successive elements as given in the cycle ("a")parameter. For instance, nth-child(5n-1) would match every fifth elementstarting at the zeroth element (with one-based indexing). Check out "Example 5:ul#example5 li:nth-child(5n-1)" to see this in action:

Page 63 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 71: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example5 li:nth-child(5n-1) { background:GoldenRod; }

<!-- markup --> <ul id="example5"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

nth-last-child

nth-last-child is similar to nth-child, but counts backward from the endof the matched collection of siblings.

In "Example 6: ul#example6 li:nth-last-child(3)", we set a backgroundfor the list item with text "eight" using nth-last-child(3), since the list itemwith text "eight" is the third-from-the-last element in the matched collection:

© Copyright 2018 Webucator. All rights reserved.Page 64 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 72: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example6 li:nth-last-child(3) { background: DarkSalmon; }

<!-- markup --> <ul id="example6"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

In "Example 7: ul#example7 li:nth-last-child(even)", we apply abackground color to every other list item. Note that this example differs from theearlier nth-child example using even, since we are counting back from theend:

Page 65 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 73: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example7 li:nth-last-child(even) { background: LightSeaGreen; }

<!-- markup --> <ul id="example7"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

As with nth-child, the an+b parameter format for nth-last-child offersa way to match a set of elements via a cycle size ("a" - that is, every "a-th" element)and offset ("b") - but here the offset and cycle count back from the end of thecollection. Consider "Example 8: ul#example8li:nth-last-child(2n+3)", where nth-last-child(2n+3) matchesevery second element starting from the third from the last element:

© Copyright 2018 Webucator. All rights reserved.Page 66 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 74: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example8 li:nth-last-child(2n+3) { background: CornflowerBlue; }

<!-- markup --> <ul id="example8"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

Using the an+b format for nth-last-child with a negative ("b") offset countsbackward (every "a-th" element) from an off-the-end-of-the-list offset. In "Example9: ul#example9 li:nth-last-child(5n-1)", we start at the 12th elementand work backwards by fives:

Page 67 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 75: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ ul#example9 li:nth-last-child(5n-1) { background:GoldenRod; }

<!-- markup --> <ul id="example9"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul>

nth-of-type and nth-last-of-type

Unlike nth-child and nth-last-child, the nth-of-type andnth-last-of-type selectors count only matching elements (i.e., the elementspecified to the left of the colon) when indexing. Consider the following twoexamples:

© Copyright 2018 Webucator. All rights reserved.Page 68 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 76: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ div#example10 p:nth-child(3n + 2) { background: SaddleBrown; }

<!-- markup --> <div id="example10"> <h3>Numbers</h3> <p>one</p> <p>two</p> <p>three</p> <h3>More Numbers</h3> <p>four</p> <p>five</p> <p>six</p> <h3>Yet More Numbers</h3> <p>seven</p> <p>eight</p> <p>nine</p> <p>ten</p> </div>

Page 69 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 77: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

/* CSS */ div#example11 p:nth-of-type(3n + 2) { background: Orchid; }

<!-- markup --> <div id="example11"> <h3>Numbers</h3> <p>one</p> <p>two</p> <p>three</p> <h3>More Numbers</h3> <p>four</p> <p>five</p> <p>six</p> <h3>Yet More Numbers</h3> <p>seven</p> <p>eight</p> <p>nine</p> <p>ten</p> </div>

Each CSS rule is applied to the same markup: a div containing three h4s and ten

© Copyright 2018 Webucator. All rights reserved.Page 70 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 78: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

ps. In the first example above, nth-child(3n+2) matches every third elementstarting at the second element; the first child element (an h4) of the div is consideredwhen counting the offset, thus the p with text "one" is the first element whosebackground color is set. Each third child of the parent is matched; if the child is alsoa p, then the background rule is applied.

In the second example, p:nth-of-type(3n+2) matches only those children ofthe div which are also ps; in this case, the first child (an h4) is not counted - theoffset specifies the second p (not the second child) and only every third p (not everythird child).

Page 71 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 79: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Using nth-of-type Pseudo-ClassExercise 520 to 30 minutes

In this exercise, you will use the nth-of-type pseudo-class to style an 8-by-8 tile ofsquares (<div>s) with alternating colors.

1. Open ClassFiles/selectors-pseudoclasses/Exercises/structural-pseudo-classes-nth.html in a text editor.

2. Note that the section of the page titled "Alternating Pattern" displays 64<div>s; style these, using nth-of-type, to display in an 8-by-8 grid witheach alternating columns of green.

3. Your solution should look like:

4. Check your work in a browser.

*Challenge1. Open ClassFiles/selectors-pseudoclasses/Exercises/structural-pseudo-classes-

nth-challenge.html) in a text editor.

© Copyright 2018 Webucator. All rights reserved.Page 72 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 80: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

2. Note that the section titled "Chessboard" displays 64 <div>s; style these as achessboard (also using nth-of-type, as such:

3. Check your work in a browser.

Page 73 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 81: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Exercise Solution

selectors-pseudoclasses/Solutions/structural-pseudo-classes-nth.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 "nth" Structural Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.#alternating div { 10.

width:40px;height:40px;border:1px solid black; 11. float:left; 12. margin:0; 13. } 14.

15. #alternating div:nth-of-type(2n+1) { 16. background:LimeGreen; 17. } 18.

19. #alternating div:nth-of-type(8n+1) { 20. clear:left; 21. }22. </style> 23.</head> 24.<body> 25. <div id="main"> 26. <h1>CSS3 "nth" Structural Pseudo-Classes</h1> 27. <h2>Alternating Pattern</h2> 28. <div id="alternating"> 29. <div></div><div></div><div></div><div></div> 30. <div></div><div></div><div></div><div></div> 31.-------Lines 32 through 37 Omitted-------

Code Explanation

To effect the eight-to-a-row pattern, we size each <div> as a square (with widthand height both 40px), float each <div> left, and use chessboarddiv:nth-of-type(8n+1) to clear the last <div> in each row.

© Copyright 2018 Webucator. All rights reserved.Page 74 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 82: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

We use div:nth-of-type(2n+1) to target every other element, giving it agreen background. We could also have used div:nth-of-type(odd) to achievethe same effect.

Page 75 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 83: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Challenge Solution

selectors-pseudoclasses/Solutions/structural-pseudo-classes-nth-challenge.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 "nth" Structural Pseudo-Classes</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9.#chessboard div { 10.

width:40px;height:40px;border:1px solid black; 11. float:left; 12. margin:0; 13. } 14.

15. #chessboard div:nth-of-type(16n+1), 16. #chessboard div:nth-of-type(16n+3), 17. #chessboard div:nth-of-type(16n+5), 18. #chessboard div:nth-of-type(16n+7), 19. #chessboard div:nth-of-type(16n+10), 20. #chessboard div:nth-of-type(16n+12), 21. #chessboard div:nth-of-type(16n+14), 22. #chessboard div:nth-of-type(16n+16) { 23. background-color:Brown; 24. } 25.

26. #chessboard div:nth-of-type(8n+1) { 27. clear:left; 28. }29. </style> 30.</head> 31.<body> 32. <div id="main"> 33. <h1>CSS3 "nth" Structural Pseudo-Classes</h1> 34. <h2>Chessboard</h2> 35. <div id="chessboard"> 36. <div></div><div></div><div></div><div></div> 37. <div></div><div></div><div></div><div></div> 38.-------Lines 39 through 44 Omitted-------

© Copyright 2018 Webucator. All rights reserved.Page 76 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 84: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

We use the same strategy as above to create the 8-by-8 grid - sizing, floating, andclearing the last <div> in each row.

Using a single CSS rule like div:nth-of-type(2n+1) won't work here, sincethe colored pattern in each chessboard row is staggered. Instead, we use eight CSSrules to color every sixteenth element, offset appropriately: #chessboarddiv:nth-of-type(16n+1), #chessboard div:nth-of-type(16n+3),etc.

Page 77 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 85: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Pseudo-Elements

We can use CSS pseudo-elements to style specified parts of an element. We could,for instance, style the first letter or line of a paragraph, or insert content before orafter a div element.

Pseudo-ElementsNotesExample(s)Pseudo-Element

Style the first line of text; can onlybe applied to block-level elements.

p::first-letter::first-letter

Style the first letter of text; can onlybe applied to block-level elements.

p::first-word::first-word

Note that, beginning with CSS Level 3, we use a double colon for pseudo-elements,to distinguish from pseudo classes:

p::first-letter { font-size: 3rem;}

Let's look at some examples.

© Copyright 2018 Webucator. All rights reserved.Page 78 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 86: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Sample

selectors-pseudoclasses/Demos/firstletterfirstline.html

<!DOCTYPE html> 1.<html> 2.<head> 3. <meta charset="utf-8"> 4. <title>CSS3 Attribute Selectors</title> 5. <meta name="viewport" content="width=device-width"> 6. <link rel="stylesheet" href="../Shared/reset.css"> 7. <link rel="stylesheet" href="../Shared/style.css"> 8. <style> 9. p { 10. line-height: 2.2rem; 11. } 12.

13.p#para1::first-letter { 14.

font-size:4rem; 15. } 16.

17. p#para2::first-letter { 18. color:#c00; 19. float: left; 20. font-family: Georgia; 21. font-size: 7rem; 22. line-height: 6rem; 23. padding-top: 0.1rem; 24. padding-right: 1rem; 25. padding-left: 0.5rem; 26. } 27.

28. p#para3::first-line { 29. font-weight: bold; 30. }31. </style> 32.</head> 33.<body> 34. <div id="main"> 35. <h1>First Letter &amp; First Line</h1> 36.

Page 79 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 87: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

<p id="para1">This paragraph gets styled with a large first letter. This paragraph gets styled with a large first letter. This paragraph gets styled with a large first letter. This paragraph gets styled with a large first letter.</p>

37.

<p id="para2">This paragraph gets styled with a drop cap. This para »» graph gets styled with a drop cap. This paragraph gets styled with a drop cap. This paragraph gets styled with a drop cap. This paragraph gets styled with a drop cap. This paragraph gets styled with a drop cap. This paragraph gets styled with a drop cap. This paragraph gets styled with a drop cap.</p>

38.

<p id="para3">This paragraph gets styled with a bold first line. This paragraph gets styled with a bold first line. This paragraph gets styled with a bold first line. This paragraph gets styled with a bold first line. This paragraph gets styled with a bold first line.</p>

39.

</div> 40.</body> 41.</html>42.

© Copyright 2018 Webucator. All rights reserved.Page 80 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 88: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

Code Explanation

The code above renders like the screenshot shown below:

For the first paragraph, with id #para1, we use p#para1::first-letter tomake the first letter (a "T") larger.

The second paragraph, with an id of #para2, gets a "drop cap": we usep#para2::first-letter to style the first letter with larger font size and redcolor; floating the first letter (again, a "T") and adding some padding to it lets therest of the paragraph's text flow around it.

In the last paragraph, with id #para3, we use p#para3::first-line to stylethe first line of text as bold. Note that the style applies to all text in the first line

Page 81 of 380Version: 1.0.0. Printed: 2018-03-20.

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 89: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

before the line breaks; resizing the browser would change how much text shows asthe first line, but the bold styling would always apply to the first line, however longit is.

Conclusion2.2In this lesson, you have learned:

• How to use new CSS3 selectors and pseudo-classes to style pages.

© Copyright 2018 Webucator. All rights reserved.Page 82 of 380

Selectors and Pseudo Classes

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied

Page 90: Unauthorized EVALUATION - ITCourseware · 2018-03-23 · technologies for the firm include PHP and Wordpress, JavaScript and jQuery, Ruby on Rails, and HTML5/CSS3. Previously, Brian

7400 E. Orchard Road, Suite 1450 NGreenwood Village, Colorado 80111

Ph: 303-302-5280www.ITCourseware.com

9-38-00163-000-03-20-18

EVALUATION COPY

Unauthorized reproduction or distribution is prohibitied