Tuesday, March 23, 2010

An Introduction to CSS

Our next step is to learn CSS (Cascading Style Sheets), a key tool for today's web designers.
What is CSS?

CSS is the acronym for: ‘Cascading Style Sheets’. CSS is an extension to basic HTML that allows you to style your web pages. An example of a style change would be to make words bold. In standard HTML you would use the tag like so:

make me bold

This works fine and there is nothing wrong with it per se, except that now if you wanted to, say, change all your text that you initially made bold to underlined, you would have to go to every spot in every page and change the tag.

Another disadvantage can be found in this example: say you wanted to make the above text bold, make the font style Verdana and change its color to red you would need a lot of code wrapped around the text:


This is text


This is verbose (wordy) and contributes to making your HTML messy. With CSS you can create a custom style elsewhere and set all its properties, give it a unique name and then ‘tag’ your HTML to apply these stylistic properties:

My CSS styled text



And in between the < head> tags at the top of your web page you would insert this CSS code that defines the style we just applied:



In the above example we include the style sheet code inline, or in other words, in the page. This is fine for smaller projects or in situations where the styles you're defining will only be used in a single page. There are many times when you will be applying your styles to many pages and it would be a hassle to have to copy and paste you CSS code into each page. Besides, the fact that you will be cluttering up each page with the same CSS code, you also find yourself having to edit each of these pages if you want to make a style change. Like with JavaScript, you can define/create your CSS style in a separate file and then link it to the page you want to apply the code to:

< link href="myFirstStyleSheet.css" rel="stylesheet" type="text/css">

The above line of code links your external style sheet called ‘myFirstStyleSheet.css’ to the HTML document. You place this code in between the tags in your web page.

To create an external style sheet all you need to do is create a simple text document (on Windows you simply right-click and select new -> text document) and then change it from a file type .txt to .css. You can change the file type by just changing the file names extension. The file name’s extension on Windows tells the computer what kind of file it is and allows the computer to determine how to handle the file when, for example, you try to open it.

You probably guessed it; CSS files are just specially (specifically) formatted text files much in the same way that HTML pages are. There is nothing special or different about the file itself, rather it is the contents of the file that makes a CSS document a CSS document.

When working with an external CSS document there are a couple of points to remember:

1. You DON'T add these tags in the CSS document/page itself as you would if you embedded the CSS code in your HTML:



Since the link in your web page connecting the CSS page to your HTML page says that you are linking to a CSS page, you don’t need to declare that the code in the page is CSS. That is what the above tags do. Instead you would just add your CSS code directly to the page:

.myNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FF0000;
}

.my2ndNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FF0000;
}

.my3rdNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12pt;
color: #FF0000;

}

In the above example I have created a series of CSS classes that can be applied to any HTML tag like so:

My CSS styled text



or

My CSS styled text



You will notice that in the above example I applied a CSS style to an

tag. This tag sets the size of the text that it wraps to a size that is preset in the browser (ex: 10 pixels). When you apply a CSS class to it, the CSS code overrides the default size that you would normally get with an

tag in favor of the size specified in the CSS class. So now you can see that CSS can override default HTML tag behavior!

In the above examples, I have CSS code where I define my CSS classes and then ‘apply’ them to various elements in the page. Another way to apply CSS is to globally redefine an HTML tag to look a certain way:

h1 { font-family: Garamond, "Times New Roman", serif; font-size: 200%; }

What this CSS code does is set the font style and size of all

tags in one shot. Now you don't have to apply a CSS class as we did before to any

tag since they are automatically all affected by the CSS style rules.

Here is another example of where I give the whole page bigger margins:

body { margin-left: 15%; margin-right: 15%; }

As you can see, you can redefine any tag and change the way it looks! This can be very powerful:

div {
background: rgb(204,204,255);
padding: 0.5em;
border: 1px solid #000000;
}

Set in the above code, any
tag will now have a background color of ‘rgb(204,204,255)’ and have a padding of 0.5em and a thin 1 pixel border that is solid black.

A few things to explain about the above:

Color in CSS can be expressed in a few ways:

1. In Hex -> for example: #000000 – this is black and this: #FF0000 is red.
2. In rgb -> rgb(204,204,255) is a light purple-blue color.
3. With named colors like: ‘red’ or ‘blue’

I typically use hex color since I am familiar with them or I just use named colors. So the last example can be rewritten like so:

div {
background: green;
padding: 0.5em;
border: 1px solid #FF0000;
}

So instead of ‘rgb(204,204,255)’ , I just specified ‘green’.

By using RGB (RGB is the acronym for: ‘Red Green Blue’) and Hex color, you can really get the exact color you want easily when you know your codes. Luckily many programs (like Dreamweaver) provide easy to use color pickers for you so you don’t need to know the values for the code.

In this last example I will show you the ‘super cool’ CSS code that allows you to create link roll-over effects without images:

:link { color: rgb(0, 0, 153) } /* for unvisited links */
:visited { color: rgb(153, 0, 153) } /* for visited links */
:hover { color: rgb(0, 96, 255) } /* when mouse is over link */
:active { color: rgb(255, 0, 102) } /* when link is clicked */

The above CSS will cause your link to change color when someone hovers their mouse pointer over it, instant rollovers with no images! One important note with the above code is that it is important that the style declarations be in the right order: "link-visited-hover-active", otherwise it may break it in some browsers.

CSS is very powerful and allows you to do things that you can’t do with standard HTML. It is supported nicely now in all the modern browsers and is a must learn tool for web designers.

The above examples are just a small sample of what you can do with CSS, but it should be more than enough for you to start styling your pages nicely. Like with many technologies, CSS has a lot of capability that most people will not need to use often if at all. Don’t get caught in the trap of thinking that if there is some functionality/feature available, that you have to use it.

How to build website

An introduction to domain names, web servers, and website hosting

I assume that you know nothing about the inner workings of the Internet; maybe you're not even sure how people actually get to web sites, where the web sites are actually sitting, what the web is in the first place....

In this article I am going to give you the minimum you need to get your 'feet wet' so that we can quickly get into building web sites. I won't go into painful micro-details that would put all but true nerds to sleep, again there is just enough so that you have a basic understanding of what's going on.
What is the web?

In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the web) are typically connected by phone lines, digital satellite signals, cables, and other types of data-transfer mechanisms. A 'data-transfer mechanism' is a nerd's way of saying: a way to move information from point A to point B to point C and so on.

The computers that make up the web can be connected all the time (24/7), or they can be connected only periodically. The computers that are connected all the time are typically called a 'server'. Servers are computers just like the one you're using now to read this article, with one major difference, they have a special software installed called 'server' software.
What is the function of server software / programs?

Server software is created to 'serve' web pages and web sites. Basically, the server computer has a bunch of web sites loaded on it and it just waits for people (via web browsers) to request or ask for a particular page. When the browser requests a page the server sends it out.
How does the web surfer find a web site?

The short answer is: by typing in the URL, or in other words, the web site address. So for example, if you wanted to find the web site www.helloeducare.com, you would type in the address into your web browser's address bar or maybe use your 'favorites' or 'bookmarks' link to helloeducare.

There are other ways to find web sites (like search engines,) but behind the scenes web sites are all being found by going to the web site's official address. That brings us our last nerd detail: how does a website get an official address so that the rest of the web can find it?
Registering your domain name

If you ever wondered what the heck registering a domain was all about ... you probably figured it out by now! But just in case - registering a domain name gets you an official address for your web site on the World Wide Web. With this 'official' address, the rest of the web can find you.

Like your home address is unique in the real world, there also can't be any duplicate addresses on the Internet, otherwise no one would know where to go! In other words, domain names are unique addresses on the web.
Why does registering a domain name cost money?

If you want to have your own unique address on the web, your own domain name, it will cost a few bucks for each year you want to 'own' the name. The cost of registering a domain name ranges from less than $10 USD to about $30 USD per year. You can register a domain from 1 to 10 years.

The reason for the cost is that the central 'address book' of all the world's domain names needs to be updated - somebody's got to pay for that! You may have noticed that I just snuck in a little extra piece of information: the giant 'web address book' of domains.

That leads us to our last bit of nerd information: when you type in a website's domain name or click on a link that takes you to that domain name, your browser starts asking servers where that particular domain name is sitting (on the web) and the servers are then able to tell the browser where to go by referring to the giant address book I mentioned above.
Getting your web site 'live' on the Web

With the nerd background details under our belts, we can now learn about the two steps to going live on the Web:

1. Register your domain.
2. Rent some server space.


1. Registering your domain

There are many companies out there that allow you to register the domain name for your web site. Prices vary, as does the quality of service, but at the end of the day, they all handle the details of getting your domain name listed in the giant address book I spoke about earlier.

These days, you will find that many of the names you may be interested in registering are already taken. As I mentioned above, domain names have to be unique and many have been slurped up.
What is the difference between .com, .net, .org, etc.?

Practically speaking, there is really no difference these days. Search engines don't discriminate between a .COM address and a .NET address. The only thing you might consider is that people tend to type in .COM automatically since it was the first publicly known domain extension. So when registering a domain name, I would go for the .COM first and if it was taken, I would then try for any of the others. (.net, .org, .tv, etc. ...)

You probably guessed; a .COM address is not the same domain name of the same name with a different extension. So for example:

www.helloeducare.com is not the same place as www.helloeducare.net

As such, each of the addresses can be registered separately.
2. Renting server space to 'host' your web site

You need to rent space on a server so that it can serve your web site to the World Wide Web; this is often called 'hosting'. Companies that provide this service are often called 'host' or hosting companies.

After you've registered your domain, all you need to do is contact a hosting company and tell them your domain name. They will be able to guide you through the process and you should be live on the web in no time - typically within a week or less.
A cheaper option

Some people may not want to buy a domain or pay for hosting because they only have a personal web site for fun or practice. You can still get your website live on the web by using a free hosting service that allows you to create what is called a 'sub-domain'. A sub-domain is just a domain that is part of another domain. So if helloeducare.com offered sub-domain hosting you could have an address like:

www.helloeducare.com/yourWebsite/

Or it could be like:

http://yourWebsite.helloeducare.com

Whichever way the free hosting service decides to do it. The point is that your web site domain is really a part of the parent domain, in this case helloeducare.com. Doing it this way, you don't need to buy a domain name, and you don't need to pay for hosting.

This is fine for fun or project websites, but if you are serious about your web site (say it's your business website) using sub-domains is like taking someone else's business card and writing your name on it! You figure it out ...

One last point, I've heard of free hosting services that will allow you to host proper domains with them for free and without annoying ads that other free hosts will insert into your pages. But I've never used them, and in my opinion you always get what you pay for. In the internet's recent past there was once a crop of free service providers that would give away access to the web via dial-up, they were notorious for bad service and all have since gone bankrupt ... I wonder why?
Moving your website files onto the server

After you have your domain name registered and your hosting service in place, the last step is to upload the website onto the server. You can transfer your web site to your host's server using an FTP program.

An FTP program is a type of software that is used to move files from one computer to another over the Internet. FTP is the acronym for: File Transfer Protocol; this just means that this is a 'way' of moving files.

There are several free FTP programs you can use to move your files and many HTML editors and web design programs like Dreamweaver have FTP capabilities built in.

One option you probably have to 'FTP' your files to the server is Internet Explorer. Internet Explorer 5 and up have an FTP program built right in. You can use it by typing in the FTP address of the server in the address bar preceded by the keyword: FTP. Here is an example:

FTP://207.35.15.69/yourwebsite/