HTML5 and CSS3 offer some great features that everyone is clamoring to use. However, not everyone can simply rip apart their site and redo all of their markup and styling across the board. There are some quick wins, especially with CSS3, to be had that you can integrate into your site without rewriting your whole entire site.
1. Easing Into
HTML5 and CSS3
Brian Moon
dealnews.com
Who attended the
HTML5 and Javascript
@brianlmoon
tutorial yesterday? http://brian.moonspot.net/
2. What is in HTML5?
• New Semantic Tags
• <article>, <header>, <footer>, etc.
• New Multimedia Tags
• <canvas>, <video>, <audio>, etc.
• New Javascript APIs
• data- attributes
• HTML5 Forms
3. What is in CSS3?
• New Properties
• New Selectors
• Device dependent Media Queries
4. What is not
HTML5 nor CSS3?
• SVG - been around, browsers just got
better
• Geo-Location - Separate W3C spec from
HTML5
5. Who uses your site?
• Are the tech savvy?
• Are they sensitive to change?
• Are they in China? (Lots of IE6 still)
• All Mobile?
7. Our design goals
• Identical UI and UX on modern browsers
• Fully functional and usable on IE8, IE7 and
Opera
• Page should render and users should be
able to click things in IE6
9. http://blogs.msdn.com/b/jennifer/archive/2011/08/01/html5-part-1-semantic-markup-and-page-layout.aspx
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
Semantic Tags
</head>
<body>
<header>
<hgroup>
<h1>Header in h1</h1>
<h2>Subheader in h2</h2>
</hgroup>
</header>
<nav>
<ul>
<li><a href="#">Menu Option 1</a></li>
<li><a href="#">Menu Option 2</a></li>
<li><a href="#">Menu Option 3</a></li>
</ul>
</nav>
<section>
<article>
<header>
<h1>Article #1</h1>
</header>
<section>
This is the first article. This is <mark>highlighted</mark>.
</section>
</article>
<article>
<header>
<h1>Article #2</h1>
</header>
<section>
This is the second article. These articles could be blog posts, etc.
</section>
</article>
</section>
10. Semantic Tags
• Older browsers don’t treat these as block
elements
• CSS can fix it in some browsers
• Javascript (HTML Shiv) required in older IE
versions
• Good semantic HTML4 markup and
Microformats already recognized by scrapers
• Would use in new projects.YMMV on ROI for
converting well done HTML
11. data attributes problem
• Unknown attributes are ignored by
browsers, but the pages don’t validate.
• Hacks exist where classes are used
(e.g. class=”artid-574244”)
12. data- attributes
<div class="art body" data-artid="574244">
• Allows you to store data as an attribute
that is ignored by the browser
• Any attribute prefixed with data- is ignored
by the browser (as all unknown attributes
are) and are treated as valid HTML5.
• Use element.getAttribute(“data-artid”); to
get the data
• Use it now. Works in all browsers.
13. Video & Audio
• Well documented licensing war
• Great idea, caught up in licensing issues
• May have to store your media in more than
one format
• Javascript libraries exist to help with
fallback
• Have used it via JS libs. Eases the pain. Falls
back to Flash.
14. Canvas
• Graphics via markup/JS
• Not generally lighter weight than images, so
not a replacement for static images
• Great for graphs and such
• Many, many javascript libraries to help build
graphs via Canvas.
• Used for internal reporting where we
dictate browser versions. Publicly,YMMV.
Wanna waste time? http://canvasrider.com/
15. New JS APIs
• Web Performance - neat
• Local Storage - requires user prompt
• Web Workers (IE10)
• Web Sockets - very new, has issues
• You really need a good use case for these
17. HTML5 Forms
• Reduce custom validation Javascript
• You can query if a field is valid with
checkValidity().
• Custom validation possible via event
handlers
• Requires IE10 =(
• Some javascript libs can close the gap.
20. Use with fallback
• border-radius
• box-shadow
• gradient backgrounds
• multiple backgrounds
• Make sure the design holds up to your
standard on browsers that don’t support
these
25. Transitions
• Replaces javascript for some types of
animations
• CSS language to define how an element
changes from one state to another
• Should be treated as optional and have a fall
back or the page should work without
them
• Can be taxing on the browser
27. Transforms
• CSS language for scaling and rotating
elements
• Mixed with transistions, animation can be
achieved.
• May require browser specific tweaking or
even non-standard CSS for IE.
• Can confuse the box model and page flow
28. Example
The labels are
rotated 90
degrees, but as
you can see,
Firebug things
the element is in
a different place
than where it
appears when
drawn.
30. Eye Candy Issues
• All of these techniques can be taxing on the
browser and or device.
• Excessive use of gradients and transforms
can cause major browser lag
• Many require browser prefixes (-moz or
-webkit) or IE specific syntax (filter)
31. Selectors
tr:nth-child(2n+1) /* every odd row of an table */
tr:nth-child(odd) /* same */
tr:nth-child(2n+0) /* every even row of an table */
tr:nth-child(even) /* same */
tr:nth-last-child(-n+2) /* the two last rows of an table */
a:first-child /* a is first child of any element */
Also:
:first-of-type
:only-child
:only-of-type
:empty
Browser performance may suffer using these
on large, complex documents. Only use
these when you can’t control the markup.
32. How Selectors Work
This is not CSS3, but just general knowledge you need
• CSS is parsed and ALL rules are evaluated.
More rules, more work for the browser
• Rules are evaluated right to left
• “.foo a” matches ALL a tags in the document
and walks up the DOM to decide if they
have a .foo parent.
33. Media Queries
@media all and (max-width: 699px) and (min-width: 520px),
(min-width: 1151px) {
body {
background: #ccc;
}
}
• Allow you to specify different CSS for
different device specifications
• You can use these now to help with mobile
design and usability. Those devices support
it, older browsers ignore it.
35. Conclusion
• Understand your audience
• HTML5 Doctype works for HTML4, try it
• Use HTML5 semantic tags to fix bad HTML
or on new projects
• Video is not the Flash killer we all hoped
for. But, it does have its uses.
• HTML5 Forms have great potential, but still
a nice to have for now.
36. Conclusion
• CSS3 eye candy is a great extra bit for
users that can see it. Be sure you are happy
with the fallback for others.
• New CSS3 selectors are powerful, but
good markup with classes is still better
• CSS media queries are very helpful for
formatting your pages on smaller screens
and are supported on those platforms