Friday, October 29, 2010

XHTML and CSS notes

Stylin with CSS


XHTML Structure


DOCTYPE declarations:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"

XML namespace declaration:

<html xmlns= lang="en" xml:lang="en">

Content type declaration:

<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />

Symbols such as <, &:

A simple template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns= lang="en" xml:lang="en">
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
    <title>Title for your Web page</title>

Four ways of CSS declaration:

  1. embed <style></style> section in the head element
  2. link to external CSS file: <link href="mystylesheetprint.css" media="screen" rel="stylesheet" type="text/css">, for print, just change media="print"
  3. in-line style, just specify at each tag, e.g. <p style="font-size: 25pt; color: red;">
  4. use @import in <style></style> section in the head element. The only downside is that IE6 might have so called FOUC (Flash of Un-styled Content) problem, meaning the content will be momentarily displayed without CSS formatting. See more at

CSS syntax-related stuff:

Contextual selector:

this limits style to parent element, e.g. p em{color:green;} makes only those <em> within <p> elements green color.

Class selector:

e.g.{color:green;} <p class="green">green text</p>, note that if multiple classes exist, the last one declared in CSS definition file wins.

Id selector:

p#green{color:green;} <p id="green">green text</p>
Difference between id and class selector is that one id value is unique to one element and id is usually used in javascript as well. So, for those styles unique to an element, use id, for styles that can be shared among different elements, use class selector.

Attribute selector:

select element based on attribute existence or values, e.g. this example add a pdf icon after links to pdf files, use [href|="foo"] to specify link names that start with "foo"
a[href$=".pdf"] {

background:transparent url(images/iconpdf.gif) no-repeat scroll right center;

Unit measurement:

try to use relative units: em (from the width of a character), ex (from the height of character x), or percentage.


many different ways to specify a color: #RRGGBB, (R%, G%, B%), or use color name. There are only 16 color names in the spec: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, yellow.


serif, sans-serif, monospace, fantasy, cursive, e.g. p{font-family:sans-serif;}

Round corners:

No comments:

Post a Comment