Professional Documents
Culture Documents
The first thing you should do when creating a new Web site is to
create a separate folder to store it in. I like to store my Web
pages off a folder called HTML in my "My Documents" folder, but
you can store them where you like.
Important
Always name your Web folders and files using all lowercase and
without any spaces or punctuation. While Windows allows you to
use spaces, many Web hosting providers do not, and you'll save
yourself some time and trouble if you name your files and folders
well from the beginning.
Open a New Web Page
Since a Web page is just a text file, you can use a text editor such
as Notepad to write your HTML. Make sure you're in a blank page
by choosing File > New...
Save Your Page as HTML
As with the directory name, always use all lowercase letters and
no spaces or special characters in your filename.
Start Your Web Page
DOCTYPE
The first thing you should type in your HTML document is the
DOCTYPE. This tells the browsers what type of HTML to expect.
For this Web site, we're going to write it in transitional XHTML, so
use the following DOCTYPE:
HTML
Once you have the DOCTYPE, you can start your HTML with the
<html> </html> element. Type both the beginning tag and the
end tag and leave some space for your Web page contents, as in
the picture.
<html>
</html>
Create a Head for Your Web Page
<head>
</head>
The title of your Web page is the text that displays in the
browser's window. It is also what is written in bookmarks and
favorites when someone saves your site. Store your title text
between <title> </title> tags. For this page, I titled it "McKinley,
Shasta, and Other Pets":
The body of your Web page is stored within the <body> </body>
element. It should come after the </head> but before the
</html> As usual, leave extra space between the starting and
ending body tags:
<body>
</body>
Dividing Your Web Page into Sections
First add the two div elements. Give them both a unique id using
the id attribute. I like to identify my divisions based on the
location or function. So a column on the right might have the id
"right". Or a navigation header division might have the id
"header". Add two div elements to your document and label them
"nav" for the navigation column and "main" for the main column.
<div id="nav">
</div>
<div id="main">
</div>
Once you have your Web page nearly ready to add content, you'll
need to get your directories set up so that you have a folder to
put your images in. If you think you'll have a lot of stylesheets or
javascripts, you might want to create separate folders for them
as well.
Because we're going to use the navigation over and over, it's
easier if it's stored in a separate file, so that you can just copy
and paste it into your documents when you're ready to add it.
Unfortunately, if you change the HTML for your navigation, you'll
have to go in and change it on all the pages. So it's a good idea
to make certain of your navigation early so you don't have to
change all your files numerous times.
Open a new page in Notepad and save it as nav-template.htm.
Then copy the entire division into the file:
Please remember that any time you change this file you'll need to
update every other page in your site. This template is just to
make it easier to copy and paste your navigation into new pages.
For this site, label your page "My Pets", and put it in the <div
id="main"> section:
<div id="main">
<h1>McKinley, Shasta, and Other Pets</h1>
<p class="topline">
<img src="images/pets1_dogs.jpg" width="250" height="188"
alt="Shasta and McKinley" class="noborder">
Shasta and McKinley do seem to like each other.
</p>
<br clear="all" />
Don't worry if your page doesn't look correct, in the next section
you'll learn how to add a CSS stylesheet to your page so that it all
looks really nice.
The same way we created a separate text file for the HTML, you
will create a text file for the CSS. If you need visuals for this
process please see the first tutorial. Here are the steps to create
your CSS style sheet in Notepad:
When you're writing XHTML for different browsers, one thing you
will learn is that they all seem to have different margins and rules
for how they display things. The best way to be sure that your
site looks the same in most browsers is to not allow things like
margins to default to the browser choice.
html,body {
margin: 0px;
padding: 0px;
border: 0px;
left: 0px;
top: 0px;
}
Changing the Font on the Page
The font is often the first thing that you'll want to change on a
Web page. The default font on a Web page can be ugly, and is
actually up the Web browser itself, so if you don't define the font,
you really won't know what your page will look like.
p, li {
font: 1em Arial, Helvetica, sans-serif;
}
h1 {
font: 2em Arial, Helvetica, sans-serif;
}
h2 {
font: 1.5em Arial, Helvetica, sans-serif;
}
h3 {
font: 1.25em Arial, Helvetica, sans-serif;
}
I started with 1em as my base size for paragraphs and list items,
and then used that to set the size for my headlines. I don't expect
to use a headline deeper than h4, but if you plan to you'll want to
style it as well.
The default colors for links are blue and purple for unvisited and
visited links respectively. While this is standard, it might not fit
the color scheme of your pages, so let's change it. In your
styles.css file, add the following:
a:link {
font-family: Arial, Helvetica, sans-serif;
color: #FF9900;
text-decoration: underline;
}
a:visited {
color: #FFCC66;
}
a:hover {
background: #FFFFCC;
font-weight: bold;
}
I set up three link styles, the a:link as the default, a:visited for
when it's been visited, I change the color, and a:hover. With
a:hover I have the link get a background color and go bold to
emphasize it's a link to be clicked.
#nav {
width: 225px;
margin-right: 15px;
border: medium solid #000000;
}
#nav li {
list-style: none;
}
.footer {
font-size: .75em;
clear: both;
width: 100%;
text-align: center;
}
#main {
width: 800px;
top: 0px;
position: absolute;
left: 250px;
}
Since I've already set the paragraph font above, I wanted to give
each paragraph a little extra "kick" to make it stand out better. I
did this by putting a border on the top that highlighted the
paragraph more than just the image alone.
.topline {
border-top: thick solid #FFCC00;
}
#main img {
float: left;
margin-right: 5px;
margin-bottom: 15px;
}
.noborder {
border: 0px none;
}
As you can see, there are also margin properties set on the
images, to make sure that they aren't smashed up against the
floated text that is beside them in the paragraphs.
Once you've saved your CSS you can reload the pets.htm page in
your Web browser. Your page should look similar to the one
shown in this picture, with images aligned and the navigation
placed correctly on the left side of the page.
Follow these same steps for all of your internal pages for this site.
You want to have one page for every page in your navigation.
The first thing you should be aware is that this site is not built
using these techniques. The Web Design site on About (and all
About sites) is built using tables, and until browsers that support
CSS Positioning are more widely used, will be for the foreseeable
future.
Browser Support
For example, the page for this article can be considered to have
five content parts:
1. the header
This is where my photo is, the top banner ad, and basic
navigation.
2. the left navigation
This is the left side of the page, with the subjects and
essentials.
3. the right navigation
This is where the tower ads and other information is.
4. the content
The text of this article.
5. the footer
The bottom navigation, copyright information, lower banner
ad, and so on.
For the sake of this article, I'm going to pretend there are just
three columns on the page, and ignore the header and footer.
Once you've defined the different content areas of your site, you
need to write them in your HTML. While you can, generally, place
your sections in any order, it's a good idea to place first items
you'd like less advanced browsers to see first.
1. <div id="leftnavigation"></div>
2. <div id="rightnavigation"></div>
3. <div id="content"></div>
Positioning
This is the fun part. Using CSS you can define the position for
your id'ed divs. Store your position information in a style call like
this:
#content {
For this layout, I set the two navigation columns to fixed widths
and then set their position absolute, so that they wouldn't be
impacted by where they are found in the HTML.
#leftnavigation {
position : absolute;
left : 0;
width : 150px;
margin-left : 10px;
margin-top : 20px;
color : #000000;
padding : 3px;
}
#rightnavigation {
position : absolute;
left : 80%;
top : 20px;
width : 140px;
padding-left : 10px;
z-index : 3;
color : #000000;
padding : 3px;
}
• visible
This is the default, and it indicates that the content should be
displayed on the page as the browser normally would.
• hidden
This style indicates that any extra content that doesn't fit in
the box should remain hidden.
• scroll
With the overflow set to scroll will add scrollbars (both vertical
and horizontal) to the box property.
• inherit
The inherit style sets the overflow to be inherently the same
as the parent element.
• auto
This is the style we want. It specifies that if the content will
overflow the box, scrollbars should display, otherwise, they are
left off.
As with the other page, this page might not look as nice in
browsers that don't support CSS positioning. See the HTML. See
the CSS. See it in Action.