Creating Modern, Responsive Websites With Web Standards

Website Standards and Clean Code

It isn’t that difficult to create a modern website based on current web standards. If your website was built using the latest technology, your site will be super-fast, modern, clean and responsive.

Everyone wants their website to cost less, work better, and reach more people in today’s browsers, screen readers, and wireless devices. The inescapable technological advancements that are happening as we speak are breaking websites all over the internet. A modern website built using the latest coding practices ensures that your website will function properly across all devices and help individuals with disabilities who are using special devices to access and interact with the internet – and stand the test of time.

You don’t have to spend money on trendy, short-sighted, proprietary solutions that will end in disaster. No one can afford to piecemeal a website that will ultimately break sooner than later.

Coding several different stylesheets might have seemed like a great idea at the time, but it is not a rational solution to problems that are continuing to plague site owners and builders.


WaSP ( advocates standards that reduce the cost and complexity of site creation and ensure simple, affordable access for all. Today, every browser supports web standards as a matter of course. They work with the designers of development tools such as Dreamweaver. You can find a myriad of web standards educational tools and this information can be found in most languages today.

Apple’s latest WebKit based Safari browser, which powers the iPhone’s web browser, Mozilla powered Firefox, Opera, the WebKit based Google Chrome, and Microsoft Internet Explorer 7+ understand and correctly support XHTML, CSS3, JavaScript, and the DOM.
*Internet Explorer 6 does not support many of the latest web standards, and we can only hope that everyone has moved passed this version of IE. Developers know that we can fix IE6 to some degree, but there comes a time when you have to move forward and not look back. We’ve stopped overkill fixes because newer phones are equipped with the latest browsers and it just doesn’t warrant the extra time and expense anymore to work out ALL the fixes needed for IE6 to view properly.



JavaScript creates action.  JavaScript is the bomb. This language has given us the ability to create action!
In a perfect world, browsers perfect their support for every single standard. Considering that most software doesn’t come out bug-free, and standards are sophisticated and complex, cross-browser support is actually pretty solid enough that we do develop using the latest standards. HTML5, more accessibility, CSS3, structured markup and deeper DOM and JavaScript function calls are becoming the progressive-enhancement that is pushing the internet into the future. All the big companies such as Apple, MSN, Wikipedia, and WordPress have embraced web standards. Of course, they don’t always achieve perfect validation or pure semantic markup, but a trained developer can make these markup fixes very quickly, and let’s face it, modern browsers are lenient.




More than 90% of all websites are obsolete. They might look good on desktop browsers, but outside of that, the symptoms of decay are starting to appear. Carefully constructed layouts have begun to fall apart, and expensively engineered behaviors have stopped working. As browsers evolve, site performance continues to deteriorate.

Modern browsers are not merely newer versions of the same old thing. They differ fundamentally from their predecessors, and in many cases, they’ve been rebuilt from the ground up. They have a new job: to comply as well as possible with the web standards. As the newer browsers comply with web standards, they are becoming increasingly intolerant of broken code and markup.



We believe in “write once, publish everywhere”. It isn’t wishful thinking. We are proud of the fact that our mission statement is “Because it matters”. Our mission follows some basic rules:

Control layout, placement, and typography in desktop browsers while allowing users to modify the presentation to suit their needs.
Develop and support sophisticated behaviors that work across multiple browsers and platforms.
Comply with accessibility laws and guidelines without sacrificing beauty, performance, or sophistication.
Redesign quickly – reducing costs and eliminating unnecessary work.
Support emerging devices from wireless gadgets and smart phones to Braille output devices and screen readers used by those with disabilities with one website.
Offer sophisticated printed versions of any web page.
Stay educated and ahead of the curve to always use real semantic markup.



SEO and Analytics go hand-in-hand.  Believe it or not, companies do not have to spend a lot of money for SEO or Analytics. Well thought out SEO makes your website findable. Content is king. Focus on lean, keyword-rich, buzzword-free content that’s relevant to your customers, and use semantic markup. Copy, CSS layout and HTML5’s latest coding practices are the golden keys to findability.



Accessibility makes sure your content can be read and your site can be used by everyone, no matter what device they browse with, and regardless of physical ability. Innovation is the soul of accessibility. Accessibility is legal standard for judging and enforcing the accessibility of sites. This is great news because the world is being pushed into one single standard.

If you use standards-based designing principles, you not only make your content easy for search engines to find, it will also enable visually disabled people who use screen readers to navigate your websites content.

Screen reader users navigate web pages by tabbing from h2 to h2 and from section to section, just like sighted users navigate by visually scanning. When structuring your site semantically, pay particular attention to forms and tables. Provide keyboard access for those who are unable to use a mouse. Keyboards and assistive devices are the gateway to online user experience.


Google web crawlers look for relevancy of content when a user types in an inquiry.
Think of web crawlers as blind users – Google is the biggest blind user on the web. Dish out appropriate content, well written and well structured, and you not only serve the blind folks in your audience, you also attract millions of sighted ones.

It wouldn’t be smart to exclude disabled Americans. This demographic would take up a city the size of Los Angeles or New York City. Millions!

If you think blind people don’t buy products online is missing the point and the boat. Don’t be blind yourself to the true nature of the audience you reject – you are still reaching the non-disabled populace this way by conforming to access guidelines and many others who would have ordered your products over the phone if only your site let them.

Section 508

Section 508 requires all websites under its jurisdiction to provide “equal or equivalent access to everyone” to accommodate the visually impaired, the hearing impaired, the physically disabled, and people who have photosensitive epilepsy and it spells out what accessibility really means. This law covers computers, fax machines, copiers, telephones, transaction machines, and kiosks, as well as other equipment used for transmitting, receiving, or storing information. It also covers many websites. Section 508 became U.S. law in 2001 and applies to the following:

  • Federal departments and agencies (including the U.S. Postal Service)
  • Deliverables from contractors who serve them
  • Activities sponsored or funded by the Federal government
  • Activities sponsored by states that have adopted the regulations
  • This is just skimming the surface and you can find plenty of resources to explain what the exact standards are and how to apply them along with specific things to do to make your site 508 compliant.

The bottom line is that if you design with web standards and follow the guidelines, your site should be accessible to screen readers, Lynx, mobile devices, and old browsers as it is to modern, compliant browsers. Standards and accessibility converge in agreeing that one web document should serve all readers and users. Even Flash and PDF’s can now be made accessible.


Most tasks to bring a website to its best take minutes to accomplish. Simple tasks like adding a label to your web form or writing a table summary. Type a brief alt text for each image – which is a no-brainer. High level conformance is going to obviously fall under another category and will cost more. If you want to author closed captions for web videos or to caption live streaming media news feeds in real time see Joe Clark’s “Best Practices in Online Captioning” . (

I highly recommend the following cited book for anyone who builds things for the internet. Web Standards is such an exciting concept that ties us all together. Where we go from here who knows, but right now we are accomplishing a great thing using Web Standards, and this book is a must have.

You can find the latest Standards and beta versions of some brilliant new concepts existing on the W3C website. Their HTML5 Validator is a great place to find semantic errors within your page. Go to for the latest information.

Jeffrey Zeldman with Ethan Marcotte (2010). Designing with Web Standards, Third Edition. Berkeley, CA. New Riders.


CSS3 – Design with Color Control and Opacity

CSS3 has the ability to control color opacity.

There are many degrees of translucence between total transparency and total opacity.  Web Designers often use opacity for visual appeal in conjunction with mouseover events for pop-up photo galleries as well as drop-down and flyout menus.

hex_colorsColor is a big part of a website, and you can color anything and everything using CSS.

There are 16 valid color names:

black, silver, gray, white, maroon, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, and aqua.

Hex Codes

Virtually all modern screens can show at least 16.7 million colors, and CSS provides several ways to define all those colors.  The most common method of defining colors is to use a hex code.  This allows you to define a color using three pairs of hexadecimal numbers representing red, green and blue.  A zero indicates none of that color.  An ff indicates that color at full strength.  Example: #000000 is black – none of any color; #ffffff is full white – full strength of every color; #ff0000 is red – full strength, no other color; #00ff00 is green – no red, full strength green, no blue.

You can also use a three-digit shorthand syntax to express colors where each pair of digits has matching characters.  The browser actually doubles each of the digits to translate to six digits.  Example:  #000 is short for #000000; #0f0 is short for #00ff00.  The letters aren’t case-sensitive, so you can use uppercase or lowercase.

RGB Codes

rgbRGB is another way to express any of the 16.7 million colors.  Like hex, you define a color using a combination of red, green, and blue, but you use the 255 decimal range of 0 to 255, and you don’t need the # character.  The syntax used is rgb(red,green,blue).  You replace the red, green, and blue each with a whole number in the range of 0-255 to indicate the amount of that color.  Or, optionally, each number can be a percent in the range of 0% to 100%.  You can’t mix percent and numbers though.  Example:  rgb(0,0,0) is black, and it is the same as saying rgb(0%,0%,0%) or hex code #000!  There is no technical advantage or disadvantage to any particular method, it’s your call.

HSL Color

hslAnother way to express any of the 16.7 million colors available to you is Hue, Saturation, and Lightness (HSL) which is based on the concept of a hypothetical color cylinder.  The syntax for expressing color using HSL is hsl(hue, saturation, brightness).

Hue is the basic colors of the rainbow, and all the colors circle the hypothetical cylinder.  The cylinder is round, so 360 degrees around.  Red is at 0 degrees, green is at 120 degrees, blue is at 240 degrees.  At exactly 360 degrees, it goes back full circle to red.

Saturation increases as you move out from the center of the cylinder.  It is how much of the color there is.  Picture a bottle of perfectly red ink.  That would be 100% saturation, near the outside of the cylinder.  Take a drop of that ink and drop it into a glass of clear water.  It’s red, but it is at a low saturation, maybe 1%, near the inside of the cylinder.

Lightness is how much light is hitting the color.  No light is 0 (zero) and would render it black near the bottom of the cylinder.  Too much light (100) would render white at the top of that imaginary cylinder.

So looking at hsl(hue, saturation, brightness), you replace hue with hue expressed as a number indicating degrees around the cylinder with red at 0 (zero), green at 120, and blue at 240.  You can use any number in the range of 0 to 360.  You can express saturation as a number the range of 0% (no saturation) to 100% (full saturation).  Lightness, too, ranges from 0% (totally dark) to 100% (totally light) with 50% being the standard lighting.

It is important to keep in mind that hex, RGB, and HSL are just different ways of expressing the same 16.7 million colors.  There is no right way or better way.  It is up to you, the developer.

Translucent color expression is made using rgb() or hsl() coloring methods and using a fourth value for opacity.

Opacity, or transparency, and translucency all describe how much you can see through something.   The syntax for transparency is rgba(red, green, blue, opacity) or hsla(hue, saturation, lightness, opacity).  The “a” stands for alpha transparency.  The opacity value is new to CSS3 so some older browsers won’t handle them correctly.  You will want to set a background color as the default for the older browsers followed by the hsla() or rgba() values, including the opacity value.  The newer browsers will read the second value in this statement:

#wrapper {
background: white;
background: rgba(255,255,255,.8);

The opacity value is a number between .01 to .99 – the larger the number, the more opaque the color.  Zero is no opacity (transparent) and 1 is opaque.

Opacity property

The opacity property also has the syntax opacity: value;.  The value can be any number in the range of 0 to 1 where 0 is totally transparent and 1 is opaque.  This property is great because is applies to images and entire containing elements!

<td style=”opacity: .1″>
<image src=”images/felix.jpg” alt=”felix the cat” />

You can give each cell its own opacity value using an inline style.  You can have elements on a page that are completely invisible by using the syntax visibility: value; with either hidden or visible for the value.  It still takes up the space although it is not visible.

Use the syntax display: none; if you want to remove an element from the flow entirely. Use display: block; to make it visible.

By default, block elements are however tall they need to be to contain their content.

So, this has been a great lesson for me and I hope it helps someone else down the road.

Christina Descalzo
Kennesaw State University – HTML5 & CSS3 Certified

HTML5 and CSS3 – Background Image Positions

It’s All Relative

ansley-1-25The viewport you view pages on comes in many sizes.  The viewport is not the page.  You have to scroll inside the viewport to see the entire page.   Setting up the clear difference is going to help understand how background images work.

Top left, top right, bottom left, bottom right and center center can apply to a div, or to the viewport.  You position things relative to either.  These positions apply to the viewport, or to the page.

Here are the values for background-image positions:

background-image: url(…), url(…);                 /* two images if you’d like */
background-attachment: value;                     /* scroll OR fixed which centers it in the viewport*/
background-position:  horizontal vertical;     /* replace horizontal with left, center or right – the vertical is optional – default is center, or specify top, center or bottom */
background-repeat: repeat or no-repeat or repeat-y or repeat-x;   /* default is top left for no-repeat */
background-size: width height; (unit of measure); OR auto; (maintain aspect ratio); OR cover; (no distortion sizes the image to fill the height and width, some clipping of the image will occur to avoid distorting the image); OR contain; (will have gaps around it to preserve proportion)  /* this is the file’s properties set in a unit of measure.  */

CSS3 multiple background images 

body {        /* Four corner images and one background image repeated */
url (thefile/imagecorner1.png),
url (thefile/imagecorner2.png),
url (thefile/imagecorner3.png),
url (thefile/imagecorner4.png),
url (thefile/background.png);
/* Their positions followed by a comma */
top left,
top right,
bottom left,
bottom right,
top left;
/* How each repeats */
background-attachment: fixed;
background-color: #ff0072;
It all happens in the CSS….

The shorthand property – easy on the code, but doesn’t work in older browsers:

The syntax for the shorthand property to specify the different stylistic values on a single line using spaces to separate the values:

background: url (path) position / size repeat-style attachment color;   /* the syntax */

background: url (path) center / contain no-repeat fixed black;      /* an example */


1.  the default size of an image is the actual size of the image as defined by the dimension in the image file.
2.  Default tiling is set to repeat in all directions.
3.  If you don’t specify the background-attachment file or have no content yet (which means the page has no height), center will put it at the top of the viewport in the center.
4.  You position images relative to the page OR to the viewport.  Background-attachment: fixed; along with background-position: center and no-repeat will contain the image in the center of the viewport – even if the page is empty.
5.  Get the perfect image background when you say background-position: left top; when used with background-size: cover, and the image size you’d like (ie., 1024 x 729) set in pixels at 72  pixels per inch (dpi).  You can set your styling and positioning anyway you’d like.  You can also set the opacity for images and I have covered that in my article Design with Color Control and Opacity.

Play with the different positions – that is how you will get good at it.

Christina Descalzo
Web Design and Development

CSS3 Selectors

css3 selectors and javascriptCSS3 has added the ability to target almost any element on the page with a wide range of selectors.

We’ve been keeping up with the Cascading Style Sheet evolution.  We’ve been matching elements by type, class, and/or id.  Then we got familiar with the pseudo-elements, pseudo-classes and combinators.

CSS3 is an extension of CSS2.1 that adds powerful new functionality and has been divided up into several modules.  Each module has a standalone specification for a subsection of CSS, like selectors, text, or backgrounds.  The list of changes is quite exhaustive and can be researched at

  1. The original CSS specification had about 6 selectors.
  2. CSS2 introduced attribute selectors & CSS2.1 expanded the range with 12 more selectors.
  3. CSS3 introduces over a dozen new selectors.
  4. CSS3 did not add any new pseudo-elements, but refined these special selectors to now use a double colon as the proper syntax (::) to differentiate between the two types of selectors.
  5. CSS3 provides three new attribute selectors (ie., href or title) and one new combinator – that is, a selector that joins other selectors together, such as the child combinator (>) from CSS2.  The Selectors Level 3 Module has widespread and stable implementation across most browsers.  When I say most browsers, it usually means IE8+, and most all other browsers, who have been keeping up with the evolution.

We can get into the Document Object Model (DOM) to manipulate our elements.

A Quick Overview of useful, supported changes from CSS3:

CSS3 contains a lot of new properties that allow you to create visual fx, such as rounded corners, drop shadows, semitransparent backgrounds, gradients, and images for borders. Most of these changes are in the Background and Borders module; others in the Colors and Images modules.

You can manipulate a box’s position and shape in two- or three-dimensional space, such as rotating, scaling, or skewing it.  These effects are called transforms, and are covered in the 2D and 3D Transforms modules.

The Fonts module introduced the @font-face rule that allows you to link to a font file on your server and use it to display the text on your page, instead of being limited to the fonts on your user’s machine.

CSS3 introduces over a dozen new selectors. They are included in the Selector module.  The pseudo-class and attribute selectors allow you to target specific pieces of your HTML without needing to add IDs or classes, streamlining your code.

The Transitions and Animation module allows you to ease changes from one style on an element to another, such as gradually and smoothly changing the color of a button when you hover over it.  You can make complicated style changes and movements.

Multi-column Layout is a module that makes multi-column layouts easier to create.  It deals with flowing the text of a single block into multiple columns, similar to a newspaper layout.  The Flexible Box Layout module deals with making blocks align horizontally or vertically with each other and making them more flexible to the available space than floats or positioning can be.

Before moving on, let’s recap how a selector might be utilized.  Here is a short contact list example:

<li><a href=”” lang=”en-GB” rel=”friend met”>Peter</a></li>
<li><a href=”” lang=”es-ES” rel=”friend”>Pedro</a></li>
<li><a href=”” lang=”es-MX” rel=”contact”>Pancho</a></li>

All of these elements have a rel attribute which we can use to target all of the elements. The advantages of having more methods for traversing the document mean fewer styling hooks are required.  Here is another example:

<li class=”1first 2pretty”>3<span>L</span>orem ipsum</li>
<li>Lorem ipsum</li>
<li class=”pretty”>Lorem ipsum</li>
<li class=”4last”>Lorem ipsum</li>

This markup contains class names to describe each element’s position in the document tree:   first (1) and last (4) show that the li elements are the first and last children on the ul element, and pretty (2) is used to the odd-numbered li elements.  An extra span (3) is included around the first letter of the li element.  Use this example to add styles to alternating elements, set different values on the first and last elements, or add special formatting to the first letter of a text node.

Here is the list of selectors from CSS2:

a[rel] {color:red;}Simple Attribute Selector – all elements will have this rule applied to it. a[rel=’friend’] {color: red;}Exact Attribute Value Selector – will only target elements with the value of friend, so it would be the second element.
a[rel~=’friend’] {color:red;}Partial Attribute Value Selector – selects both of the elements that contain the value of friend.  It looks for the value of friend as part of a space-separated list, and applies to the first and second elements.
a[lang|=’es’] {color: red;}Language Attribute Selector applies rules to elements based on their lang attribute.  This would target both the second and third elements in our example because we targeted just es, and did not specify ES or MX.

CSS3 Introduces New Selectors 

The new Selectors already have widespread support, including IE8+.  CSS3’s new methods allow you to achieve the same visual results without muddying the markup with unnecessary classes and non-semantic elements.

a[attr^=val] – matches any element a whose attribute attr starts with the value val.  The val matches the beginning of the attribute value.  a[title^=’image’] {} –  rule will be applied to the a element in the first paragraph since the title attribute string begins with the word image.

a[attr$=val] – matches any element a whose attribute attr ends in val.  The val matches the end of the attribute.

a[attr*=val] – matches any element a whose attribute attr matches val anywhere within the attribute.  The string val is matched anywhere in the attribute value.  It is similar to a[attr~=val] above, except the val can be part of a word.  For example, .fakelink[title~=info] {} would match any element with the class fakelink that has a title attribute containing the string info, such as “Click here for more information.”

Selectors can be broadly separated into two categories, but they both sit outside the DOM

What’s the difference between a pseudo-class(:) and a pseudo-element(::)?

Remember this:  pseudo-classes select HTML elements that could have classes added to them, while pseudo-elements select things that aren’t HTML elements at all.

The four pseudo-elements in CSS are ::first-line, ::first-letter, ::before, and ::after.  Fragments of other HTML elements, not individual elements themselves, and not part of the DOM.  A double colon (::) is the correct syntax, but the single colon is better supported.  IE6, IE7 and IE8 only understand the single-colon notation.  All other browsers support both.

Pseudo-classes act directly on elements defined in the document tree (ie., p elements and href attributes); this category contains class, type, and attribute selectors, or DOM selectors.  E:first-child {} allows you to make a selection based on information that exists but isn’t provided as an attribute of the element – the exact purpose of a pseudo-class.

The pseudo-classes that we are familiar with for some of our user interaction are classes, namely :link, :visited, :hover, :active, and :focus, aka dynamic or interactive pseudo-classes.  The pseudo-class uses a single (:) colon.

Generated Content – The ::before and ::after pseudo-elements don’t refer to content that exists in the markup, but rather to a location where you can insert additional content, generated right there in your CSS.  While this generated content doesn’t become part of the DOM, it can be styled.  Notice the attr() allows you to access any attributes of the selected element.  Here is an example:

a[href^=http]:after {
content: “(” attr(href) “)”;
The a[href^=http] means “any a element whose href attribute begins with http, or in other words, external links.  You can use this to display the link’s target.  I tried it and it worked.  Another example might be like this:

a[href$=pdf] {
background: transparent url(pdficon.gif) 0 50% no-repeat;
padding-left:  20px;
a[href$=pdf]:after {
content:  “(PDF)”;
This style will add a PDF icon and the text”(PDF)” after links to PDF’s.  Remember that the [attr$=val] selector matches the end of an attribute .pdf., and of course, you need the image that will be displayed for you at 50% transparency.

Things to remember now….. 

1.  The :visited pseudo-class may pose a security risk, and may not be fully supported in the future.  Malicious sites can apply a style to a visited link, then use JavaScript to check the styles of links to popular sites.  This allows the attacker to glimpse the user’s browsing history without their permission.  As a result, several browsers have begun limiting the styles that can be applied with :visited and some others (notably Safari 5) have disabled it entirely. The spec explicitly condones these changes, saying:

“UAs [User Agents] may therefore treat all links as unvisited links,or implement other measures to preserve the user’s privacy while rendering visited and unvisited links differently.”

2.  For better accessibility, add :focus wherever you include :hover, as not all visitors will use a mouse to navigate your site.

3.  :hover can apply to any element on the page – not just links and form controls.

4.  :focus and :active are relevant to links, form controls, and any element with a tabindex attribute.

These are the most common pseudo-classes, but there are many others.  The following pseudo-classes match elements based on attributes, user interaction, and form control state.  They have been part of the spec-planned evolution and are currently being supported in most cases:

:enabled – a user interface element that’s enabled.
:disabled – a user interface element that’s disabled.
:checked – radio button or checkboxes that are selected or ticked.
:indeterminate – form elements neither checked or unchecked.  Not supported yet.
:target – this selector singles out the element that is the target of the currently active intrapage anchor.  You know you can have links to anchors within a page by using the # character with the id of the target.  This changes the URL in the address bar to thispage.html#content – and the :target selector now matches the #content element, as if you had included the selector #content.
:default – applies to one or more UI elements that are the default among a set of similar elements.
:valid – applies to elements that are valid, based on the type or pattern attributes.
:invalid – applies to empty required elements, and elements failing to match the requirement defined by the type or pattern attributes.
:in-range – applies to elements with range limitations, where the value is within those limitations.  Applies, for example, to number and range input types with min and max attributes.
: out-of-range – the opposite of :in-range: elements whose value is outside the limitations of their range.
:required – applies to form controls that have the required attribute set.
: optional – applies to all form controls that do not have the required attribute.
:read-only – applies to elements whose contents are unable to be altered by the user.  This is usually most elements other than form fields.
:read-write – applies to elements whose contents are user-alterable, such as text input fields.

Browsers that support form control attributes like required and pattern also support the associated :valid and :invalid pseudo-classes.

IE6 fails to understand :hover on elements other than links, and neither IE6 nor IE7 understand :focus.  IE8 and earlier lack support for :checked, :enabled, :disabled and :target.  However, IE9 does support these selectors.
JavaScript libraries such as jQuery can help in targeting these pseudo-classes in nonsupporting browsers.
   See my article about the JavaScript shim.

Relational Selectors

Relational selectors target elements based on their relationship to another element within the markup.  All are supported in IE7+, Firefox, Opera and WebKit:

Descendant (E F)

The descendant selector targets any element F that is a descendant (child, grandchild, great grandchild, and so on) of an element E.  For example, ol li targets li elements that are inside ordered lists.  This would include li elements in a ul that’s nested in an ol – which might not be what you want.

Child (E > F)

This selector matches any element F that is a direct child of element E – any further nested elements will be ignored.  The ol > li would only target li elements directly inside the ol, and would omit those nested inside a ul.

Adjacent Sibling (E + F)

This will match any element F that shares the same parent as E, and comes directly after E in the markup.  For example, li + li will target all li elements except the first li in a given container.

General Sibling (E + F)

This one is tricky. It will match any element F that shares the same parent as any E and comes after it in the markup. So, h1-h2 will match any h2 that follows an h1, as long as they both share the same direct parent – that is, as long as the h2 is not nested in any other element.

Here is an example:

<h1>Main Title</h1>
<h2>This subtitle is matched</h2>
<p>blah, blah, blah…</p>
<h2>This is not matched by h1-h2, but is by header h2</h2>
<p>blah, blah, blah…</p>

The selector string h1-h2 will match the first h2, because they’re both children, or direct descendants, of the header. The second h2 doesn’t match, since its parent is article, not header. It would, however, match header h2. Similarly, h2-p only matches the last paragraph, since the first paragraph precedes the h2 with which it shares the parent article.

There aren’t any parent or ancestor selectors.  If the browser had to go backwards up the DOM tree, or recurse into sets of nested elements before deciding whether or not to apply a style, rendering would be exponentially slower and more demanding in terms of processing.

Another example would be if you wanted a three column layout for the site, and you want the three columns divs to be floated left (normal).  To avoid this style being applied to any other divs nested inside the main div, we use the child selector.  This is a basic form structure that you will be using:

#main > div {
float: left;
overflow: hidden;

Structural Pseudo-classes

The nth-* Pseudo-Class – Four of the new pseudo-classes are based on a count value used to find an element’s position in the document tree, and you use the syntax nth-*.  The asterisk is in place of a number of different values, each of which we will cover.  It is quite straightforward.  By default, n represents a number that begins at 0 and increments by 1 (1, 2, 3, etc.).  Another integer can be passed into it as a multiplier.  For example, 2n is every multiple of 2 (2, 4, 5, etc.), 3n is every multiple of 3 (3, 6, 9, etc.), and so on:

E:nth-*(n) {}   **Default value n, so all elements are selected**
E:nth-*(2n) {}
E:nth-*(3n) {}
The first example uses the default value n, so all elements of type E would be selected – the same thing as using a simple element selector.  The next example selects every other E element.

You may also use the mathematical operators for plus (+) and minus (-).  So 2n+1 would be every multiple of two plus one (1, 3, 5, etc.), 3n-1 would be every multiple of three minus one (2, 5, 8, etc.):

E:nth-*(n+1) {}   **selects every element except for the first instance, so 2, 3, 4, 5, etc.**
E:nth-*(2n+1) {}
E:nth-*(3n-1) {}

So now that we know how to target elements based on their attributes and states, we can also use CSS3 to target elements based simply on their location in the markup.  These selectors are grouped under the heading structural pseudo-classes.  

These might seem complicated, but they will make sense when you go to use them.  These selectors are supported in IE9, as well as current and older versions of all the other browsers – but not in IE8 and below.

You write the position number of the element you want to select inside the parenthesis (the argument), such as li:nth-child(5).  This selector would match the fifth li element in a list.  It gets powerful when you use a formula as its argument, allowing you to create more complex alternating patterns or even select specific blocks of sequential children at at time.  n is a counter starting at zero, and b is an offset value that you pick.  Example:

Since n starts at zero and then increases by one each cycle, this selector would match:
(3 x 0) + 1 = 1 = 1st list item
(3 x 1) + 1 = 4 = 4th list item
(3 x 2) + 1 = 7 = 7th list item, etc….

You could add classes to the first, fourth and seventh item, but this is easier to write, and easier to maintain.  If you ever wanted to add another list item, you would have to re-class all the list items from that point forward because their position number has changed.  Using the :nth-child() pseudo-class, that keeps track of the position number for you is more efficient and mistake-proof.

Don’t let the math scare you off from using the :nth-child().  Play around with it and see how it affects your styles.  You can check out to try this tool to play around with the :nth-child(), :nth-last-child(), :nth-of-type(), and :nth-last-of-type().

Here is another example, which will produce an alternating color variation within a list:
li:nth-child(even) {
background-color: hsla(210, 70%,82%,.5);
This will create a blue background to every other list item.  Cool!
I quickly found out that to write about all things new in CSS3 would require writing a book.  I’ve just touched upon a few things that you will need to get started with CSS3.

Here are some more things to chew on for a while:

:root – the root element, which is always the html element.
E F:nth child(n) – the element F that is the nth child of its parent E.
E F:nth-last-child(n)  – the element F that is the nth child of its parent E, counting backwards from the last one.  li:nth-last-child(1) would match the last item in any list – this is the same as li:last-child (see below).
E:nth-of-type(n) – the element that is the nth element of its type in a given parent element.
E:nth-last-of-type(n) – like nth-of-type(n), except counting backwards from the last element in a parent.
E:first-child – the element E that is the first child E of its parent.  It is the same as :nth-child.
E:last-child – the element E that is the last child E of its parent, same as :nth-last-child(1).
E:first-of-type – same as :nth-of-type(1).
E:last-of-type – same as :nth-last-of-type(1).
E: only-child – an element that’s the only child of its parent.
E:only-of-type – an element that’s the only one of its type inside its parent element.
E:empty – an element that has no children; this includes text nodes, so <p>hello</p> will not be matched.
E:lang(en) – an element in the language denoted by the two-letter abbreviation (en).
E:not(exception) – this is a particularly useful one:  it will select elements that don’t match the selector in the parentheses.

Selectors with the :not pseudo-class match everything to the left of the colon, and then exclude from that matched group the elements that also match what’s to the right of the colon.  The left-hand side matching goes first.  For example, p:not(.copyright) will match all the paragraphs in a document first, and then exclude all the paragraphs from the set that also have the class of copyright.  You can string several :not pseudo-classes together. h2:not(header > h2):not(.logo) will match all h2s on a page except those that are in a header and those that have a class of logo.

I referenced three books and the W3C website.  I hope if you are reading this, that you learn something.  I know I did, but there is more…..

Gastston, Peter. *The Books of CSS3*. San Francisco: no starch press 2011.
Goldstein, Alex; Lazaris, Louis; Weyl, Estelle. *HTML5 & CSS3 for the Real World*. Australia: Sitepoint.
Gillenwater, Zoe Mickley. *Stunning CSS3*. Berkeley: New Riders.

JavaScript polyfill for HTML5 and CSS3 (aka shim or shiv)

Modern Responsive and Responsible Design using HTML5, CSS3 and JavaScript

Web developers are commissioned to build websites for modern browsers today for every type of computer, including phones and tablets.  This is an exciting time to jump on board with a variety of developer tools and learn how to design for the future.  The problems arise when a designer looks at  the website with older Internet Explorer browsers including IE8, IE7 and especially, IE6 because  of the way they respond (or actually do not respond) to HTML5 and CSS3.  It is very important for web designers and developers to understand the problems and to figure out how to work around these issues.  We all want to build for the future, but lets not forget about the viewers who haven’t received the message about the rich internet experiences they can get from Chrome, Safari, Firefox, IE9, etc.

It is easy to forget when you have upgraded equipment and use Windows 7 and several Apple products used for development.

Of course IE9 is the default browser for Windows7 (which you have to purchase), but it also gives developers the ability to view websites in IE8, IE7 and IE6 by using the development tools found in the F12 console.  If you use Dreamweaver CS5.5 or CS6, you can also view your designs in the IE browsers as well as a variety of phones, tablets, Chrome, Safari, etc. by using the Adobe Browserlab developer tools console.

The PhoneGap framework allows developers to build apps and convert the web files into code that runs as a native app on the mobile operating system of your choice.  Dreamweaver comes with the PhoneGap kit and makes packaging apps and testing them simple.  You can compile and test Android, iPhone and iPad apps!

Mobile device development has challenges and opportunities.  Progressive enhancement using CSS3 and HTML5 allow leading designers to build a rich website for tomorrow’s browsers and devices while making sure the older browsers are rendering presentable and enjoyable pages.    It is not enough that a website designer can use Dreamweaver (or any CMS for that matter) to design websites but never look at the code.  The magic is in the code.  The days of copying and pasting are over if you expect to build unique, customized websites.  You have to know what issues surround the different browsers and fix problems as they arise.

 There are two JavaScript codes that have been crafted to help developers work around the Internet Explorer problems.  

1.  A fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more).  Here is the link:  It works like a charm.

  • Copyright 2011: Scott Jehl,
  • Dual licensed under the MIT or GPL Version 2 licenses.

The goal of this script is to provide a fast and lightweight (3kb minified / 1kb gzipped) script to enable responsive web designs in browsers that don’t support CSS3 Media Queries – in particular, Internet Explorer 8 and under. It’s written in such a way that it will probably patch support for other non-supporting browsers as well (more information on that soon).

If you’re unfamiliar with the concepts surrounding Responsive Web Design, you can read up here and also here.

Demo page (the colors change to show media queries working)

2.  A frequently used common method is to use the shiv:
<!–[if lt IE 9]> <script src=”html5shiv.js”></script> <![endif]–>
To use this script, download the html5shiv and roll it in to your own code (ideally minified).

Full original, uncompressed source available here:

This source code adds new HTML5 elements (which is simple code), but also supports printing HTML5 elements and includes the default styles for HTML5 elements, like block on article and section.

Getting it to work in the browser was easy, @jon_neal and afarkas made IE actually print HTML5 elements – these guys are to take all the credit. Please take a moment to thank them!

Whichever one you use must be included  in the <head> of your file but doesn’t matter if it appears before or after the CSS – but for the sake of performance, it would make better sense to include the CSS first then this script.  Of course, you have to upload the file with your website, or refer the code to an outside source.

shiv or shim?

Common question: what’s the difference between the html5shim and the html5shivAnswer: nothing, one has an m and one has a v – that’s it.  It’s all just polyfill.