HTML & CSS (CCW Part 2)

After you’ve figured out navigation, layout, and sent out requests for content, it’s time to start building your site. This lesson deals with basic HTML and CSS along with best practices using for both.

There are many web editors out there, but for this lesson I’ll be using Dreamweaver’s basic starter page for my example.

Starting on the build

So, let’s have a look at what a blank page looks like in code. A basic Dreamweaver HTML page is shown below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document Title</title>
</head>
<body>
</body>
</html>  

There are six parts here that make up a solid base for your page. Your Doctype, html  tags, head tags, meta data, the title tags, and last the body tags. All are part of the HTML code.

HTML (HyperText Markup Language)

Your HTML is the skeleton for your CSS. It supports the body of your webpage while CSS provides the muscles and skin. Therefore, if your HTML is incorrect, it doesn’t matter if the CSS is perfect, your website will fail.

First off, let’s talk about HTML and XHTML (Extensible HyperText Markup Language). HTML is mainly comprised of tags like the example above. XHTML is not very different from HTML- except that it’s stricter which allows browsers to process the code faster and eliminate errors caused by incorrect markup.

For example, <img src=”example.jpg”> would not display in XHTML because the ‘img’ tag is not closed. To display correctly, it would need to look like this:<img src=”example.jpg” />

Yes, the ‘/’ needs to be at the end of every tag to close it in XHTML.
HTML is not so picky and will take either <img src=”example.jpg”> or <img src=”example.jpg” />.

Generally, it is good to use HTML for your doctype, but practice XHTML within the HTML. Why? Because it’s better for the browser.

XHTML within HTML

By following all the XHTML rules you help the browser load pages faster and it’s less confusing to search through. That’s where XHTML is a plus- however, you may not know all the rules of XHTML, or you might miss a rule by accident, rendering your whole page useless until you find the problem. HTML doesn’t care about little mistakes, so by using XHTML style in and HTML page, you cover accidental code flubs so that your page will still work when you open it.

Some major differences in XHTML and HTML

HTML

<br>      <hr>       <img src="example.gif">
<P>Something</P>

XHTML

<br />      <hr />      <img src="example.gif" />
<p>Something</p>

For more on XHTML rules:           http://www.w3schools.com/xhtml/xhtml_html.asp

HTML Basics

NOTE: I’ll be writing in XHTML, but I use it within an HTML framework. Keep this in mind.

What is a “doctype” and why is it on my page?

First off, the doctype declaration should appear before any other markup on your page. Why? Because it is an instruction to the web browser about what version of the markup language (eg: HTML, XHTML and their variants) the page is written in.

For more on this see:            http://www.w3schools.com/tags/tag_DOCTYPE.asp

Placement

The placement of code in the HTML specifies what elements are within elements and their hierarchy to other elements. For example, let’s say I wanted a box within a header. I would have:

<div id=”header”><div class=”box”>Box Content</div></div>

The ‘div’ tag calls the CSS to place the header on the page and insert the box into the header. It is very important to close your divs as it tells the CSS styling to stop past the ‘</div>’ point. It is also important to nest your tags to avoid conflicting style properties or code errors. To style the elements for each div tag, you must go into the CSS and not the HTML. Remember that most HTML is strictly for organizing.

<head>…</head>

Your ‘head’ tags should contain all information a browser needs to render the content in the ‘body’ tags as well as information pertinent to search engines and browser needs for your page.

Tags used in the ‘head’ are:

<title> ... </title>      displays title of page for the browser to put on the tab or on the window’s title bar
<meta />  gives data for search engines to organize your page by/tells what your page is about
<base />   specifies a default address or a default target for all links on a page
<link />  gets a resource reference such as a CSS style sheet

An example for calling a style sheet is below.

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

So, what’s going on here?

Well, ‘rel’ says that the relationship between the current document and the linked document is that it’s a style sheet, ‘href’ calls the actual style sheet from its location,  ‘type’ tells us that the style sheet  is formatted in text/css, and ‘media’ tells us that it’s for a computer screen.

If you wanted to make this style sheet for a phone, you would change ‘media=”screen”’ to ‘media=”mobile”’. ‘media’ allows you to have multiple style sheets on a page that target different devices. (ex: style sheets for mobile, print, and screen)

<body>…</body>

Your ‘body’ tags contain the page elements that will show up in the browser window. Organization of these elements is key. Keep your tags correctly nested. I can not stress this enough. Keeping tags well organized in your code will help in a lot of ways.

Some commonly used tags in the ‘body’ are:

<h1> ... </h1>  creates a heading with h1-h6, h1 being the largest and h6 being the smallest
<p> ... </p>    organizes content into paragraphs
<a></a>  designates a link
<img /> places an image within the page
<br /> puts a break in-between text
<hr /> creates a horizontal rule- ie, a line- between elements
<strong> ... </strong>   strong emphasized text (bolds text)
<em> ... </em>  emphasized text (italicizes text)
<ol><li> ... </li></ol>  ‘ol’ is an ordered list, ‘ul’ is an unordered list, ‘li’ in both ‘ul’ and ‘ol’ is a list item
<div> ... </div>  tag defines a division or a section in an HTML document- mostly used to call style elements from the CSS
<form> ... </form>  used to place a form element within the page

Some natural hookups:

There are some tags that naturally have certain things following them.
For example, <a href=”...”> ... </a>.

‘a’ says that it’s a link and ‘href’ tells the link where to go. <img src=”...” /> ‘img’ says that the element is an image and ‘src’ tells the location of the image you want displayed.

Putting together CSS and HTML using ‘div’

The ‘div’ tag when used with CSS will either have ‘id’ or ‘class’ attached to it.

ex: <div id=”...”> ... </div> or <div class=”...”> ... </div>

A ‘div’ can have multiple classes attached, but only one id. Also, a certain id can only be used once on a page where as a certain class can be used multiple times.

ex: <div id=”container” class=”numberone” class=”numbertwo”> ... </div>

BEST PRACTICES

  • Put CSS in the header just above the </head> tag. (In order to have all styles ready for the body when it loads.)
  • Put links to scripts as well as scripts themselves (ex: jQuery, mootools, javascript) at the bottom of the page- just above the </body> tag. (This encourages faster page loading.)
  • Keep things well organized and, when necessary, document where your div tags end like so: </div> <!-- example div ends here -->
  • Nest your tags.

CSS (Cascading Style Sheets)

Getting the look

The main styles of the site, look and layout, are controlled mainly through CSS. If you need to edit the presentation of an element, div, or id use CSS. CSS and HTML together make a website fast loading and easily customizable. Using a CSS style sheet, you can change an element of your site across all the pages that have that element simply by editing your CSS. This cuts down on mistakes and makes your time spent on code more efficient.

CSS Example

Some examples of CSS.

h1 {
font-size: 2.6em;
padding:5px 0 20px 0;
}
#content {
padding-top:15px;
font-family:Verdana, sans-serif;
}
.sec-nav {
padding:0;
margin:0 0 30px 0;
}
li:visited {
color: #00CC00;
text-decoration: none;
font-weight: bold;
}  

Writing style

Before we get into the guts of this operation, I’m going to tell you about how people write the optional parts of code.

There are 3 types of naming conventions:

  • camel case
  • dash
  • underscore

Let’s say I have something in my CSS I want to call “Slider Thumbnails”.   Well, spaces are defined as starting something new, so I can’t use the above. Solution- one of the 3 naming conventions.

Camel Case:      sliderThumbnails

Dash:                  slider-thumbnails

Underscore:      slider_thumbnails

Which do I use? I use underscore because it seems easier to read for me, but this is all subjective. You pick the style that works best for you. What is important is that there are no spaces within the name.

About CSS

CSS can be used in three different ways: inline, internal, and external.

Inline is when you use ‘style’ attached to an element to build CSS for a single element within the HTML.

ex:   <p style=”color:red;”>…</p>

Internal is when you place your CSS styles in the ‘head’ tags.

ex: <head>
<style type="text/css"> p  {color:red;} </style>
</head>

External is when you have a separate style sheet and link to it from the ‘head’.

ex: <link rel="stylesheet" href="style.css" type="text/css" media="screen" />

The external style sheet will have formatting like this inside it: p  {color:red;}

What is a CSS format?

CSS creates a selector for HTML to use when you group elements you want styled on your page. The selector then has notes on what properties you want added and what you want the properties to be.

ex:   selector { property:value; }

There are 2 ways of organizing CSS: single line and multiple line – both are correct so it’s a matter of preference which one you use.

selector { property:value;  property:value; }

selector {
property:value;
property:value;
}

Your selector can be named anything you want. (With the exception of element selectors.)

Different types of selectors

There are different types of selectors: element, id, class, and pseudo.

Element selectors retain their proper html titles such as ‘body’, ‘p’, ‘h1’, ‘ul’, ‘ol’, ‘a’, ‘img’, etc… and do not use any identifying features. ex:  img

Id selectors use ‘#’ before a name and are unique.  ex:   #container

Class selectors use ‘.’ before a name and are not unique.   ex:   .thumbnail

A pseudo selector uses ‘:’ and must be attached to an element selector.    ex:    a:hover

As stated before in the html section, an ‘id’ is unique and the same id can’t be used numerous times on a page. Use ‘id’s for main containers and other large boxes on a page. A ‘class’ is not unique and can be used multiple times on a page or multiple times on an element.

For more on this see:            http://css-tricks.com/the-difference-between-id-and-class/

Property and value

A property in CSS tells what you want to style within the selector and the value tells how you want it styled. For instance, I would like a red boarder around my header.

ex:   #header  {border-color:red;}

“#header” would be my selector while “border-color” would be my property. “red” is the value I want displayed as the “border-color” on the “#header”.

There are many different types of properties. Some deal with position while others handle styles and spacing. For a full list of properties, see http://www.w3schools.com/css/css_reference.asp and scroll down to CSS Properties.

Decoding CSS

Let’s take apart this CSS.

#wordmark{
background:url(images/wordmark.png) top left no-repeat;
width:709px;
height:112px;
position:absolute;
top:0px;
left:10px;
text-indent:-9999px;
margin:0;
}

It’s an ‘id’ named wordmark.
It has a background image placed in the top left and the image is not repeated.
It’s 709×112 pixels, and its position is absolute on the page with the coordinates being top 0 and left 10. It has a text indent of -9999px, which means the text is hidden off the page, and the margin is 0 so other elements will come right up against it.

Most CSS properties are easy to figure out. Especially in things they control. Just use common sense and in most cases- what you think it does it what it does. Some tricky properties are ‘color’, which actually controls the color of your text, and ‘margin’ vs ‘padding’.

Margin determines the amount of space around your element.
Padding determines the amount of space within your element.

Bundle up

Sometimes you want to specify a lot of things that actually all relate to one property. Well, there is a way to do that.

background:#990000 url(images/footer-bg.png) top left repeat-x;
font:bold 1.7em/175% "Lucida Sans",Lucida Sans Unicode,Verdana,Helvetica,sans-serif;
border:1px #ccc dotted;
padding:4px 0 4px 4px;
margin:3px 0px 10px 15px;

This helps lighten your code and makes things run faster. It also makes things easier to find.

BEST PRACTICES

  • Separate your sections with descriptive headers. (ex: /* styles for slider */)
  • Use CSS to style all links and header elements so that they appear the same throughout the site.
  • Watch out for conflicting CSS. In order to remove conflicts, sub list the element when necessary. (ex: #containingDiv h1)

UA WordPress Theme: How to Control the Width of your Menu Items

In last week’s announcement of our new UA WordPress Theme, I mentioned there would be several tutorials to introduce you to the new features of our theme.  This week’s tutorial will cover how to control the width of your menu items in the Primary Navigation area.

Before we get into the technical how-to, lets backup and look at what’s going on and why we would even need to change the width.

Default Fixed Width

With CSS, we are allowed to define the exact width of an element.  The new UA WordPress theme will automatically assign the appropriate menu class based on the number of menu items you have in your Primary Navigation menu.  This allows us to assign a default width to each list item in order to distribute evenly across the navigation bar.

Variable Length Names

The trouble with using a default fixed width for each menu item is that, often, it leaves no room for contracting or expanding.  So let’s say you have chosen six menu items for your web site, and the words chosen for those menu items are variable length, so that some are much longer than others.

  • About the College
  • Academic Programs
  • Giving
  • News
  • Resources and Links
  • Contact

Because the list items are of equal length by default, but the words inside the list items are of different length, the menu may appear unevenly distributed, as shown here:


Notice the extra space around the shorter items “Giving” and “News”, and then how little space there is between the items “About the College” and “Academic Programs”. This method certainly works, but may not be ideal for the visual appeal of your site, since the variable length of the words make the menu appear to be unevenly distributed.

Recognizing the Problem

With the Dreamweaver templates, we were able to control the CSS IDs using “item1″, “item2″, etc.

HTML Code generated from UA Dreamweaver templates

<div id="main-nav">
<ul class="menu_6">
<li id="item1"><a href="#">About the College</a></li>
<li id="item2"><a href="#">Academic Programs</a></li>
<li id="item3"><a href="#">Giving</a></li>
<li id="item4"><a href="#">News</a></li>
<li id="item5"><a href="#">Resources & Links</a></li>
<li id="item6"><a href="#">Contact</a></li>
</ul>
</div>

However, because the UA Theme is now using the WordPress Menus functionality, we lose the custom CSS IDs and are instead replaced by automatically generated IDs created by WordPress.

HTML Code generated from UA WordPress Theme

<div id="main-nav" class="menu-custom-menu-container">
<ul id="menu-custom-menu-1" class="menu_6">
<li id="menu-item-4" class="menu-item menu-item-type-custom"><a href="#">About the College</a></li>
<li id="menu-item-5" class="menu-item menu-item-type-post_type"><a href="#">Academic Programs</a></li>
<li id="menu-item-9" class="menu-item menu-item-type-custom"><a href="#">Giving</a></li>
<li id="menu-item-10" class="menu-item menu-item-type-custom"><a href="#">News</a></li>
<li id="menu-item-42" class="menu-item menu-item-type-custom"><a href="#">Resources & Links</a></li>
<li id="menu-item-43" class="menu-item menu-item-type-custom"><a href="#">Contact</a></li>
</ul>
</div>

As you can see, WordPress changes quite a bit from the original code.

Fixing the Problem

Now that we know what is going, how do we go about fixing it?  Luckily, it’s as simple as checking out the generated HTML code from your site and adding a few lines to the CSS file!

  1. Go to the home page of your site and, using your browser, View the Source.  In Firefox, this is done by going to View->Page Source.
  2. Scroll down until you come to the “main-nav” section (examine the code from above if you aren’t exactly sure).
  3. Each <li> will have an associated ID.  Using the code from above, the IDs are
    • menu-item-4
    • menu-item-5
    • menu-item-9
    • menu-item-10
    • menu-item-42
    • menu-item-43
  4. Now, open style.css in the ua_theme folder and add the IDs.
  5. Add custom widths for each menu item until you find the right mixture.
  6. IMPORTANT: the width of all of the items must total no more than 972px.
#menu-item-4{width:197px;}
#menu-item-5{width:201px;}
#menu-item-9{width:130px;}
#menu-item-10{width:130px;}
#menu-item-42{width:172px;}
#menu-item-43{width:142px;}


As you can see, the menu now appears much better visually because the list items appear to be evenly distributed across the menu. And the total width of the menu is equal to 972px, so the code is correct. Certainly, this is a subjective process to find “what looks right”, but that is a process with which all web designers should be quite familiar.

If you have any questions about this tutorial, please leave a comment.

Commenting on Code in Code

commentimage

Ever wonder how web designers keep everything in order when they’re typing out their code? Well, commenting helps a lot in organizing. By using comments, you can also signal out things you want to fix, make note of, or even just keep track of. So how do you keep the comments from messing up the 18 hours of coding you just did? Well, there are different options for different languages.

HTML

Below is the style for your basic html web page which really shouldn’t have too many comments- just nice clean code.

<!-- Comment Here -->

CSS

For organizing your styles and your main boxes- or whatever else you need- this commenting style works for single line or block quotes.

/* Comment Here */

JavaScript or jQuery

For JavaScript or jQuery, this method comments out the entire line starting from behind the back slashes. It is used as an end of line comment. CSS style is used as a short single line comment.

// Comment Here

/* Comment Here */

For block comments the code looks like CSS, but remember to keep an asterisk on each line.

/*
* Comment Here
*/

PHP

PHP can use the JavaScript method, or the pound symbol to comment out a line.

// Comment Here

# Comment Here

For multiple lines, the comment code is like the CSS code but unlike the JavaScript, no further asterisks are needed.

/* Comment
Here */

Ajax

To comment in Ajax, use the same method as in JavaScript.

// Comment Here

ActionScript

When working with flash, you might want to use these to comment on your action script. The first works for multiple lines and single lines while the second is just used for single lined short comments.

/* Comment Here */

// Comment Here

CSS for the Phone

With the world of web expanding to mobile devices, designers must remember that ‘fantastic’ on a computer may be ‘horrifying’ on someone’s phone. However, CSS can help. By using an alternate style sheet, the computer and all the web wandering phones out there are covered.

First, we create a separate style sheet for phones by using media=”handheld” and place it in the head.

<link rel=”stylesheet” href=”name.css” type=”text/css” media=”handheld” />

Now comes the business of design in your CSS. Designing for the phone means designing for a small vertical screen and all the challenges it possesses.

First we take out all extraneous information by placing a  “display: none” in the CSS you want to hide. Once all the important areas have been singled out we’re ready for re-design.

Layout

Divide your layout into sets of horizontal bars. Horizontal layouts will keep things easy to read and provide a better hierarchy for your viewers. Try not to have two much side by side as it makes the text smaller. Make sure that your logo is at the top at all times and your main content comes directly after.

Examples:layouts

To better design your layout, a helpful guide to screen sizes can be found here at Sender 11.

Navigation

With touch screens popping up all over the place, it pays to consider the width of a human finger. Make sure links are large and well spaced so that mistakes do not happen. A good way to do this is to insert plain content or space around links. Another is to go with the button route. By turning a link into a button it is easier for the viewer to put their finger on the right spot.

Look

Remember that people mainly want to browse a page for information, so keep the layout simple. People will appreciate not having to navigate through a ton of images to get to what they want. Try understated patterns in small strips or as a background to add a different feel, or use a horizontal image at the very front to grab people’s attention.

Examples:

background

To conclude, the most important thing when designing for the mobile phone is readability.  Keep this in mind and everything will be perfect.

For more help and ideas, here are some good sites:

For info on designing for the iPhone try iPhone Microsites.
For examples in web design for the iPhone, try CSSiPhone.
For some good before and after pics try readyforiPhone.

To check if your CSS looks good on all cell phones, refer to “How to Test Websites for Mobile Devices” by Matthew Muro.

3 ways to apply CSS to HTML

If you’re setting out to learn how to use CSS (Cascading Style Sheets), the first step may not be learning the language but learning where to put the language. There are basically 3 ways to apply CSS to your HTML.

Note: With tools like jQuery and old-fashioned JavaScript, some might say there are more than 3 ways to apply CSS, but this article is about the 3 basic ways that will suit most purposes.

It doesn’t matter which order you learn these in but for this article we’ll go from the specific to the general. We’ll start with inline, then move to internal, then finish with external.

Inline

We start with the inline method of CSS placement. Inline style declarations allow us to define styles at the exact point we need them. For example, if we want to make a headline show up as large, bold, crimson text, we will find that headline in our HTML and add the CSS where the headline appears in the markup. Here is an example of what this inline CSS declaration would look like:

<h1 style="font-size:2.5em;font-weight:bold;color:#990000;">Sample
Headline</h1>

<p>This is a paragraph that has no inline styles applied to it.</p>

What you see in the code example above is mostly HTML, but it has some CSS essentially dropped right in the middle of it. We have specified that our h1 heading should have a font-size of 2.5 em (fairly large), a font-weight of bold (the CSS way of saying it should be boldfaced) and a color of #990000 (the hexadecimal, web-safe code for crimson).

We’ve also included a paragraph below the headline in our example, but we haven’t added any inline styles to it. With inline style declarations, we only affect the elements that we choose to style.

Now, if this was the only way to apply CSS, you might wonder just how useful this technology is. After all, it would be pretty tedious to have to add these kinds of statements to every piece of content you want to style throughout a website.

That’s where the other 2 methods of CSS placement come in so let’s move on.

Internal

Let’s say we want all our h1 headings and paragraphs on one particular web page to have a certain size, color and maybe a certain line-height (space between lines). One way to do this would be to include internal styles on the page rather than inline.

With internal placement of CSS, we will make our style rules in the HEAD section of the HTML. By using this method, the style declarations we make will affect only content on this page.

The basic syntax for writing internal CSS is to enclose these style declarations in style tags, so we add the following lines inside the HEAD section of our page:

<style>
h1 {font-size:1.5em; color:#990000;}
p {font-size:.9em; line-height:140%;color:#000000;}
</style>

This code sets the style on all p elements and all h1 elements within this particular web page. Keep in mind that there are ways to override those styles on certain paragraphs. One way to do that would be to put an inline style on a certain paragraph that sets its color to gray instead of black. Another would be to add more rules that would affect certain paragraphs using classes and IDs.

In case you’re wondering, technically you could put your internal CSS declarations in the BODY of the HTML rather than the HEAD, but placing the CSS in the HEAD is better for organization and performance and is definitely the way to go.

External

The 3rd method for applying CSS to your HTML is to put your CSS in an external file (call it something like style.css) and then link to that CSS in your HTML file. The great thing about this method is that you can have 1000 pages (or more) in a website and have every one of them link to that stylesheet. This means you can make changes to that one CSS file and have the changes apply across all 1000 pages of your site.

There are basically 2 steps to this method, building the CSS file and then linking to the CSS file in your HTML. We won’t cover making the CSS file in this post, so let’s just assume we have a CSS file called style.css that lives in the same directory on our server as the HTML file we want to apply it to.

All we have to do is type the following in the HEAD of our HTML document:

	<link rel="stylesheet" href="style.css" media="screen" />

As long as you have a stylesheet called style.css then any HTML file that includes that link in its HEAD will have the rules from style.css applied to it. This is generally how you would go about setting styles that control the appearance of a whole website in one place, the external CSS file.

Note: The href part of the link above has to correctly link to style.css, so if you are linking from a different directory you will have to use relative or absolute linking to navigate the path to style.css.

When to use which

You might wonder why there are 3 ways to apply CSS to your HTML, but once you start doing this stuff on your own website, you’ll quickly realize that all 3 methods are useful depending on the situation.

For example, most well-done CSS websites with more than about 2 pages employ an external CSS file to define most styles for the site. You can think of these as the default styles for all pages.

Now suppose there is one page where you want all styles to be the same as the rest of the site but with bigger paragraph text, or different colored headlines. You can use internal placement to define those different styles in the HEAD section of that page only and override the styles in your external CSS file. But, there’s a catch. If you want to override the external CSS with internal declarations, you’ll need to place the internal style tags and declarations after the link to the external style sheet.

Internal styles do not necessarily override external styles. If your internal styles come before the external CSS link, the external will overwrite the internal.

On the other hand, when we’re talking about overriding external or internal CSS with inline styles, things are a little more clearcut. Inline styles do override internal or external CSS. This means you can use inline styles if you have something that you just want to do for one specific element on one page without writing a rule that affects anything else.

It’s probably best to use inline styles sparingly. One of the main advantages of CSS is to separate the presentation, or look, of your website from the content of the site. External stylesheets and, to some extent, internal rules in the HEAD of a page, facilitate this separation. Inline styles mix presentation and content, and doing this too often can leave you with a site that’s difficult to maintain when you start making changes to the look with CSS.

If you are just getting started with CSS, here are a couple of good introductions (one video / one article) that cover a lot more than the one topic I’ve discussed above:

Common style sheets across multiple sites

While designing UA News, Dialog, and Research Magazine, it quickly became apparent that the similarities between the three sites lent itself well to using a common style sheet.  Because these sites share content and are related in some way, it was important that the design elements should be similar across the board to create that feeling that they were all connected—a suite of sites. Creating this sense of connection is something that the Admissions sites have done very well.

In order to make this common style sheet work, I needed two files:

  • common.css
  • style.css

The common.css file held 95% of all basic styles, margins, paddings, colors, and whatever else is needed.  Ideally, I wanted each site to pull as much from this CSS as possible and, where needed, overwrite the common styles with specific directives from style.css.

A very simple, but great, example of how this is useful can be seen with each site’s text headings.

common.css

h1, h2, h3, h4, h5, h6{
	font-family:Georgia, Verdana, sans-serif;
	font-weight:normal;
	color:#2e363a;
	margin-bottom:10px;
	padding-bottom:5px;
}

Research Magazine style.css

h1, h2, h3, h4, h5, h6{
	font-family:Arial, Verdana, sans-serif;
}
h1{
	color:#333333;
	border-bottom:#333333 solid 4px;
}

As you can see, the common font is set at Georgia plus a few other such as color and padding. To create a unique look on Research, all I do is declare a new font and other styles on my site specific style sheet.

The main advantages of using multiple style sheets is that it makes it easier to make changes to generic styles across all sites quickly.  The disadvantage is that it can sometimes be hard to manage.  Some may cite performance issues, but the style.css files are so small I can’t see that being a problem.

With all of that being said, I think the advantages of being able to control 95% of the styles for three sites in one file far outweighs the disadvantages.

One way to do rounded rectangles with CSS background images

I recently completed a redesign of the K-12 Summer Programs website, which provides information on UA summer camps for young people, from toddlers to high school students. The page layout comes from a standard template I use for Undergraduate Admissions microsites, with a crimson nameplate bar at the top of the page and a gray footer at the bottom. This particular microsite is customized with a background taken from the print brochure for K-12 Summer Programs.

I decided to use rounded rectangles as containers for the information about each summer camp. There are a number of ways to make rounded rectangles, but I thought I’d quickly explain the technique I used in case anyone else finds it useful.

I should mention that I considered using the CSS3 border-radius property, but it is not supported by Internet Explorer, and I decided the rounded rectangles were too important to the site’s design to have 75% of users not see them.

Basically the method I used was to separate each rounded rectangle into 3 divs. One div (campboxtop) forms the top of the rounded rectangle, another (campboxbottom) forms the bottom of the rectangle, while the div in the middle (campbox) holds the content for each camp.

The way to do this is pretty simple. In Photoshop or your image editor of choice, just create a rounded rectangle of the size you need. Then, crop out everything except the top part (something like this). Make sure that your crop leaves the curve of the corners so that it can be joined smoothly with a rectangle below it to form the rounded rectangle on our page.

Export your top rectangle to the appropriate web format (.gif or .jpg), and then undo the crop so you are left with your original rounded rectangle. From there, do a crop of the bottom of the rectangle the same way you did the top and export it to web format.

Now you have the background images for the top and bottom of your rounded rectangle. At this point, you can write the CSS that puts those images to use, which in my case ended up looking like this:

.campboxtop {background-image:url(images/campboxtop.gif);
background-position:top center;
margin-top:20px;
display:block;
width:540px;
height:19px;
}

.campboxbottom {background-image:url(images/campboxbottom.gif);
background-position:bottom center;
display:block;
width:540px;
height:19px;
}

.campbox {background-color:#eae5d1;
padding:1px 20px 1px 15px;
}

Note the use of 1px padding on the top and bottom of the campbox div. I found that using no padding there resulted in a gap between the bottom part of the rounded rectangle and the campbox div.

Within the campbox div, I use an h2 and paragraph tags to mark up the content. Combining that with empty divs for the top and bottom of the rectangle, the HTML for one camp entry looks like this:

<div class=”campboxtop”></div>

<div class=”campbox”>

<h2>Capstone Summer Honors Program</h2>

<p class=”campdate”>June 1 – July 5</p>

<p>Would you like to earn college credit while getting a taste of college life—before you graduate from high school? Check out the Capstone Summer Honors Program. Through this program, you can enroll in 2 three-hour, college-level courses and in a one-hour honors course during the first term of the UA summer session. You’ll stay in a UA residence hall, dine in one of the many Bama Dining facilities, and enjoy membership privileges at the Student Recreation Center. For qualified high-school juniors.  Priority deadline: March 30. The cost is $1500.00. </p>
</div>
<div class=”campboxbottom”></div>

I tested the K12-Summer Programs website in Firefox, Safari 4, Internet Explorer 6/7/8, and Opera, and it worked fine in all. Better cross-browser support of the CSS3 border-radius property will certainly make it easier to work with rounded rectangles, but the technique outlined above is working in the meantime.

View K-12 Summer Programs website