Welcome to the XHTML and CSS workshop
brought to you by the GSLIS Tech Lab

An Introduction to XHTML and CSS

XHTML

For starters, XHTML stands for eXtensible Hypertext Markup Language and it is an XML compliant version of HTML. There are two types of XHTML: transitional and strict. Though transitional is more forgiving and closer to HTML, the differences between the two are not great, so it's worth trying your hand at the strict version, even if you're a beginner at making web pages. (In fact, you might have an easier time if you've never used HTML since you don't have to break old habits!)

Some of the more important changes from HTML to XHTML are:

CSS

CSS, or Cascading Style Sheets, partners with XHTML and serves to style the content of the webpage content. In HTML, both the document structure (the paragraphs, headers, etc...) and the styling of the content (the bold, highlights, etc...) were mixed. Now with CSS and XHTML you can separate the two which can make things much easier, for the designer and the viewer. We'll make some changes to this style sheet to see what this means!

css has a particular syntax that it always follows: selector {property: value;} but you can link multiples styles in one selector, like this: selector {property: value; property2: value2; property3: value3;}

css also ignores white space like html, so if you want to make your css easier to read, you can format it like this:
selector {
property: value;
property2: value2;
property3: value3;
}

there are a couple other pieces of css that can come in very handy, the class attribute (identified in the css with a period) and the id attribute (identified in the css by a hash mark). for example, you could put a class on a paragraph in your xhtml like this: <p class="highlight"> and then in your css, you could highlight that class of paragraph like this: p.highlight {background-color: papayawhip;}

et voila... there's your highlighted paragraph!

the difference between an id and a class is that you can only use an id once in a page. it is used to identify something unique. most often you will find a <div> with an id tag, maybe something like <div id="navbar"> and <div id="content"> so that the unique sections of the page are easily identifiable. the class tag you can use as many times as you like.

another trick with css is to use a class or an id on an undefined selector, like this: .highlight {background-color: papayawhip;} you can see i've removed the p from before the highlight class. now you can use that class on any tag in your html, maybe like this:

A couple of things to keep in mind

Here are our sample files for you to play with. (Right click on the link to download the file.) Just keep them in the same folder and the html file will find the css file so it can apply the styles.

Don't forget to check out our CSS resources page!

Thanks from Sue and Frances!