Web Page Design - How to Get Started With CSS and Stop Using Tables to Design Your Sites

I've been working with CSS for a while and tablesmany other workarounds, this can be a tough habit
even longer. Having worked so long figuring out theto break. But once you have a good grasp of the
tricks and workarounds for tables, I've mostly usedbox model, you will no longer need these
tables for structure and CSS for style. That is not aworkarounds for formatting and lay out. Also, if you
bad thing. But is only using part of the power of CSS.start using CSS without understanding the box model
Moreover, I had a project recently that required ayou will most likely waste a lot of time bogged down
table free design. If you find yourself in this situationtrying to fix things that you would of never broken in
don't panic. If you can understand the purpose ofthe first place.
CSS, and learn or know the basics of CSS syntax, itI've always hated the expression, "Think outside of
can be a fairly simple process.the box". I can truly say with CSS not only think
The main thing to keep in mind is that you are tryinginside the box. Learn to work inside the box.
to end up with a site that has pages that containWhich brings us to our next fundamental. In CSS, just
mostly just data. You will also have one or moreas HTML, you can use many types of measurement
style sheets that contain all the structure and designunits. Usually working with pixels is fine, but the EM
of the site.unit seems to be the most reliable. If you do not use
Since there are already books, sites and courses thata strict DTD for your pages definitely look at using
cover all the details of CSS, I will not be going intoEM instead of PX. Percentages are fine in most
the syntax or details of CSS. I've never found anycases, but I have seen some small issues with using
aspects of CSS complicated enough to need outsidepercentages. As you do your own research on this
instruction or even a book, but I have wasted timeyou will find more information. The main thing to
going over the details without seeing the big picture.remember is that 16px = 1em, and not all unit types
This article will just cover the main aspects of CSSwill work in all browsers. Since pixels are most familiar
and what areas of CSS should be understood beforeto web developers, and EM is supported by all major
you get into the details.browsers, these are the two main units that should
For practice, I took a site that was mostly done inbe used.
tables, and converted the site to all CSS. The basicInheritance is also very important. Basically, colors,
lay out of the site is a header, sidebar, main contentfonts and much more can be changed by CSS. The
area, advertising section and a footer. This is a fairlychanges are applied via an external style sheet, a
common lay out, but these guidelines will work forstyle sheet on the page or even a style applied
almost any lay out or new design.directly into the HTML. Since the last style applied will
First you must truly separate all the data from anybe used, make sure you understand how inheritance
structure and formatting. This seems obvious if youworks. Also, any default browser settings will be
know anything about the reason for CSS. I only pointoverridden by an external, internal or inline style.
this out, because it is very easy to throw someA good example is the H1 HTML tag. I like to reset
formatting in with the data if you are new to thethe default size and color of the headline tag.
process. That would not be the end of the world,Although the default font is usually times and the
but it would be missing the point of the exercise.default color is black, the font size usually changes
Remember, the goal is to change the way youslightly from browser to browser.
currently build pages and start using CSS whereverFor instance, if I want most of the H1s to be a 20px
possible. The reason: so that major changes to theArial font and red, I would apply that in my main,
look and feel of the site can be made without havingmost likely external, style sheet. But let's say I have
to make changes to all the pages.a page where I want the H1 tag to be a different
Second always try to think if there is any possibilitysize. I can override the external style sheet size with
that you will be reusing the code.some inline style. So for this example, I really want
NOTE: This may not make much sense if you havemy headline to stand out, and I change the size to
no or limited knowledge of CSS, but make a note of30px. But the headline color is still red and the font is
it and keep it in mind as you start using CSS.still Arial.
If it is code that you will be reusing, make sure youWhy? Even though, I reset the size with an inline
make it a class. Also, try to put it in your main stylestyle tag, the color and font family was never reset.
sheet. As you become more advanced with CSS,So, until I override the color, or any other parameter
you will most likely have multiple style sheets. Havingdefined by another style sheet, the H1s will inherit, in
site wide elements in your main style sheet will makethis case, the Arial font and red shading from the
them easier to edit in the future. Also, since all pagesexternal style sheet.
will be calling the main style sheet file, the class willNote: If you import multiple style sheets, it will use
always be available when you make a call for it.the last style applied to the page. When you use
Now, I'll go in to the main issues, problems, etc. that Iexternal style sheets the page is processed just as if
came across as I removed all tables and otherthe code were on the page. So if you run into issues,
formatting from the web pages.make sure you are not importing multiple style sheets
The main problem with CSS is cross browserthat are in conflict with each other. A best practice is
compatibility. Most designers and users know thatto make sure that you use unique names for all
browsers display pages differently. Unless youclasses and IDs even if they are in separate style
specifically code the site to display the same, or assheets.
close as possible, in all browsers, it is almostLastly, the default settings, such as margins, padding,
guaranteed the site will not display the same.colors, etc. can vary slightly from browser to
There's a couple lines of code that should be addedbrowser, and between different versions of the
to each page.same browser. Also, as new browsers are released
- First declare a document type. If you are notand updated, it would be nice to know that your
familiar with a DTD (document type decleration) itpages will not break. So at the very beginning of my
looks something like this . The three main types ofmain style sheet, I like to declare some global
DTDs are loose, tranistional and strict. I highlysettings.
recommend strict. Research to see what works bestGenerally, you will want to override the default
for you, but strict is the safest way to insure crosspadding, margins and borders at a minimum. The
browser compatibility. It is necessary to declare apadding, margin and border are the main things that
DTD or CSS simply will not work the same in thevary from browser to browser. Once again, it
most popular browsers.depends upon your needs. But, because of
- You will also want to add this line: . This helps fixinheritance, this will override the default browser
the IE compatability error and will help with somesettings on all of your tags and elements
sizing issues. It is not a must have. I have had noautomatically. Personally, I like setting everything to
issues with the IE meta tag though. So, I wouldzero with a default color of white. I've never had any
recommend adding it for now.issues with cross browser compatibility using these
Next I recommend studying the box model of CSS.settings.
If you are used to using spacer .gifs, tables and the