Archive for November, 2009
Basics of CSS – Part #7
Nov 16th
Today we’re going to continue our adventure about the box model. We covered the box model and the margin property but we still need to cover padding and border properties!
If we recall that margin > border > padding > content… Margins are always invisible, Borders can be any color we’d like them to be, and padding will be the same color as the background-color of the element.
Border Property
The border property defines the border around an element. Using this border property we can have a border around anything we’d like. We can have the following properties:
- border-top
- border-top-color
- border-top-style
- border-top-width
- border-right
- border-right-color
- border-right-style
- border-right-width
- border-bottom
- border-bottom-color
- border-bottom-style
- border-bottom-width
- border-left
- border-left-color
- border-left-style
- border-left-width
- border – all-inclusive
Consider the following code:
1 2 3 4 5 6 7 8 9
p.top-border {
border-top-color:#ff9300;
border-top-style:solid;
border-top-width:1px;
}
So this would only apply to p elements with the class attribute of “top-border”, we know that much! This particular element would have a top border of #ff9300 (Atomicpages orange!), a border-style of solid (there are no breaks or spaces), and a border width of 1px since we want it to be thin.
This is how it would look like if we tried this. The more we type the longer the border becomes. It almost appears as if the text above is really being underlined but this is the border-top property.
For every border property there exists a short-hand way of adding styles to our borders. We can very well type border-top-width, border-top-style, border-top-color every instance we want to use this. We know exactly what the border is doing without having to guess or anything. This can take time, however. We can shorten the example above by doing the following:
1 2 3
p.border-ex {border-top:width style color;} /*Syntax*/
p.top-border {border-top:1px solid #ff9300;}
This is far more efficient and a much faster way of adding border styles to our elements! It is more confusing and might take some time to get used to. If you’re comfortable using the long-hand method then stick to what you’re comfortable with. If you prefer short-hand methods then use those, bear in mind that the short-hand method does exist and it readily available.
border-width
The first value/property we should define in our border should be the width of our border. There are built in values that we can use or we can define our own. Here are the values we can have:
- thin — approx. 1px
- medium — default value
- thick
- px, em, pt, etc
This is a thin border, This is a medium border, This is a thick border,
This is a border with 15px as the value..
Why we would want a border with 15px is beyond me, but for the sake of this example it is fine.
border-style
There are a lot of styles for borders, here are the styles you can have:
| Values | Description |
|---|---|
| none | Specifies no border |
| hidden | Specifies a hidden border |
| solid | A solid border |
| inset | 3D inset border, effects depends on border-color value |
| outset | 3D outset border, effects depends on border-color value |
| dotted | a dotted border |
| dashed | a dashed border |
| groove | 3D groove border, effects depends on border-color value |
| double | a double border |
That is a lot of styles indeed! We won’t go over every single style in this tutorial. I will, however, add a downloadable that will contain these styles! Note: the 3D style borders, it depends all on the color you pick. Some colors will look nice and some color will not look nice at all!
border-color
The border color property works the same as the background-color property. You can choose any color you would like your border to be. You may use built in colors (e.g. reg, green, blue), HTML Color Codes, or RGB Values to use your colors.
1 2 3 4 5
border-color:red; /*Color value*/
border-color:#ff9300; /*Hex Value*/
border-color:rgb(51, 255, 0); /*Decimal Value*/
All-Inclusive
The all-inclusive border property works the same as most other all-inclusive properties. It saves time but makes the code a little more confusing. The syntax you should use is like the following:
1 2 3
border:width style color;
border:1px solid #ff9300;
If you want to see these examples in action then click on the green download button below!

border.zip
Size: 3.25 KB
PHP #3: If, Else If, Else Statements
Nov 14th
Welcome to part 3 of these basics of PHP tutorials. In this part, we are going to learn how to make if statements.
The syntax for an if statement look like this:
1 2 3 | if (condition) { //Run this code if condition is true } |
Where it says “condition” we insert a Boolean expression, an expression that either has a value of true or false. If the condition is true, the code inside the brackets will be executed. Here’s an example:
1 2 3 | if (3 > 2) { //This code would run because 3 is greater than 2 } |
The Boolean expression 3>2 would return true, because 3 is greater than 2. Since it is true, the code inside the brackets would be executed. After the code in the brackets is executed, it would continue executing any code after the closing bracket.
Now consider this:
1 2 3 | if (2 > 3) { //This code would not run because 2 is not greater than 3 } |
The Boolean expression 2>3 would return false, because 2 is not greater than 3. Since it is false, the code inside the brackets would be skipped and any code after the ending bracket would continue on being executed.
Of course there are many other comparison operators besides > that you can use as well.
- > returns true if the value to the left is greater than the value to the right.
- >= returns true if the value to the left is greater than or equal to the value to the right
- < returns true if the value to the left is less than the value to the right.
- <= returns true if the value to the left if less than or equal to the value to the right.
- == returns true if the value to the left is equal to the value to the right.
- != returns true if the value to the left is not equal to the value to the right.
We can use variables for comparison as well.
1 2 3 | if ($value == $value2) { print "$value equals $value2"; } |
You can add another block of code called “else” that executes if the condition is not true.
1 2 3 4 5 | if ($value == $value2) { print "$value equals $value2"; } else { print "$value does not equal $value2"; } |
You can even add more blocks of code that execute if the initial condition statement is false, but another condition is true:
1 2 3 4 5 6 7 | if ($value == $value2) { print "$value equals $value2"; } elseif ($value < $value2) { print "$value is less than $value2"; } else { print "$value is greater than $value2"; } |
You can also combine multiple conditional statements into one.
1 2 3 4 5 | if ($value == $value2 && $value2 == $value3) { print "$value, $value2, and $value3 are all equal" } elseif ($value == $value2 || $value2 == $value3) { print "$value is equal to $value2 and/or $value2 is equal to $value3" } |
A statement consisting of two statements joined by && will only return true if both statements are true.
A statement consisting of two statements joined by || will return true if either of one of the two statement is true, or if both are true.
Basics of CSS – Part #6
Nov 14th
Today we’re going to talk about the margin property in CSS! You should familiarize yourself with the box model if you aren’t already.
Margin Property
As we see in the box model, the margins are always transparent and always surround the padding which surrounds the border which surrounds the content — margin > border > padding > content.
Properties
There are five possible properties you can use with margin:
- margin-left
- margin-right
- margin-top
- margin-bottom
- margin
The first four options allow you to have different values for any side with the code being clear as day. Consider the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
p.indent {
color:#ff9300;
border:1px solid #fff;
margin-left:25px;
margin-top:10px;
margin-bottom:30px;
margin-right:15px;
}
We have a class called “indent” which is turning the text the color #ff9300 (AtomicPages Orange), this element will also have a border that is 1px in width, solid, and pure white. This will also have a left margin of 25px, a top margin of 10px, a bottom margin of 30px, and a right margin of 15px. That means the p element will be confided to those specifications. These values can be almost anything you would like them to be.
Values
As with most if not all CSS properties. The margin property can contain multiple values.
- auto — the browser determines the margin. Different browsers means different results!
- em, px, pt
- %
In the above code example we used pixels as the unit. You can use em, px, pt, or any other unit you really want to use. The most common units are px and em.
Margin — All Inclusive
Using the single margin property will allow you to define all values of a margin that you want instead of typing out margin-top, margin-left, etc. This all-inclusive property is pretty nifty if you’re working and you’re on a roll and whatnot. It can contain one to four values.
1
margin:15px 30px 45px 60px;
- top margin – 15px
- right margin – 30px
- bottom margin – 45px
- left margin – 60px
This example has four values for the margin property. The values start with margin-top and then go clockwise to margin-left. So if you think of clock and a new day, which always starts at 12 or the top of the clock, and then rotate clockwise the next 90° angle is at the right, then the 180° is at the bottom, and then the 270° is at the left. So it’s like looking at the clock at every 90° angle you get top, right, bottom, left.
1
margin:15px 30px 45px;
- top margin 15px
- right and left margin 30px
- bottom margin 45px
This might come as a surprise to us because you would think they would group the Top and [bottom and left] segments separately, however; we can see in this example that the margin-top is 15px and the margin-bottom is 45px. The left and right margins are grouped together because they just belong together. If someone asks, “when I say a word you think of something that is opposite to that” and they ask, “up” you’ll probably say “down” off the bat.
1
margin:15px 30px;
- top and bottom margins 15px
- right and left margins 30px
This might be more clear since there are only two values here. Naturally, we’d think Top and [right and left] so the top and bottom margins will have a value of 15px, whereas the right and left margins will have a value of 30px.
1
margin:15px;
- top, right, bottom, and left margins 15px
One single value for the margin property will set all margins to that value, in our case 15px. If you wish to see this property and the values in action click on the download button below!

margins.zip
Size: 3.12 KB
Basics of XHTML Part – #3
Nov 11th
As with the CSS tutorials, the XHTML tutorials are cumulative and dependent on each other. That being said, if you didn’t read the Basics of XHTML Part 2 you may read it now or read on. Something interesting happens here, however. This is where we begin learning specific attributes, other neat HTML elements, and including styles into our HTML.
Styles
We won’t get into great detail about the style attribute but we will cover the basics! Recall that attributes is additional information about an HTML element. This style attribute is one that we can place on ANY HTML element that you know!
1 2 3 4 5 6 7
content
<a style="text-decoration:underline;" href="url">Click here</a>
<img style="height: 15px; width: 15px;" src="image.jpg" alt="img" />
<p style="margin-left:25px;">content</p>
So we have a wide variety of elements and each of them has the style attribute which is defining additional information for that particular instance in which it is used. If you know a little about External and/or Internal Style Sheets, this style attribute (commonly referred to as Inline CSS) has priority over External and Internal Style Sheets. So if you have a style that defines the width and height of an image and you want to override that you would use this style attribute. Consider the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<html>
<head>
<style type="text/css">
.img {
border:none;
width:100px;
height:25px;
}
</style>
</head>
<body>
<div class="img">
<!--This will NOT work-->
<img src="image url" alt="img" width="50" height="25" />
<!--This will work-->
<img src="image url" style="width: 50px;" alt="img" /></div>
</body>
The first question you might as is why didn’t we not define the height inside of the style attribute? The answer is simple, it is redundant! Since we want to keep the height 25px (at least for this example) is it perfectly legal to leave it out since the height is inherited from the class=”img”.
If you wish to read more about Inline CSS then Click here. If you wish to read more about CSS then read about it here
Hyperlinks and Anchors
I believe we talked about hyperlinks in the Basics of XHTML and we covered atributes in the Basics of XHTML Part 2 so we know that..
1 2 3 4 5
<!--Syntax for hyperlink-->
<a href="url">click here</a>
<a href="http://www.atomicpages.net">Atomicpages.net</a>
href=”url” and href=”http://www.atomicpages.net/” is an attribute that is telling the browser where this link is. However, there are some conditions we need to be aware of…
- If you want to link to a website other than your own you MUST include a protocol such as http:// and then the address of the website.
- If you want to link inside of your website you may use relative links or absolute links.
As minimal as these two things that we need to be aware of are.. the http:// is absolutely necessary in the attribute for hyperlinks to work properly. here for no http:// is a link neglecting the http://. If you click on that link it will take you to the 404 Page Not Found Page.
Target Attribute
The only target attribute we really need to associate ourselves with is target=”_blank”.
1 2 3
<a href="url" target="_blank">link</a>
<a href="http://www.atomicpages.net/" target="_blank">AtomicPages Hosting</a>
target=”_blank” will open that link in a new window or tab depending on your browser settings. Usually there are some rules that I follow.. If I am referring to a link within the same website in which I am writing on, I’ll do a standard link. If I am referring to a link outside of a website I am writing on I usually use the target=”_blank” attribute so it opens and the user can still easily access the content with the hyperlink. It’s all personal preference, however; not all people are thrilled by the idea of a new window or tab popping up and some people are irked when it doesn’t.
Name Attribute
Have you ever visited a website like wikipedia and click in an article and it moves you to a certain part of the page? If not then visit this wiki article on the thrilling history of HTML and in the contents click on a link. You’ll notice the url changed! Example:
1 2 3 4 5
<a href="http://en.wikipedia.org/wiki/HTML/">Wiki</a>
<!--to-->
<a href="http://en.wikipedia.org/wiki/HTML#HTML_version_timeline/">Wiki</a>
How in the world did they do that?! It is very simple actually! By using the name attribute of course! Consider the following:
1 2 3 4 5 6 7
<!--This labels the anchor-->
<a name="label">content</a>
<!--This calls the anchor-->
<a href="#label">content</a>
So what’s exactly happening here? Isn’t there a style that says everything within a tags will be orange and underlined? Why isn’t there anything that is underlined and orange at the top except that one link to the Basics of XHTML Part 2? Is it there?
No! Since I wanted to avoid any changed text and I wanted to avoid using inline css (because it’s more work) I did the following:
1 2 3 4 5 6 7
<!--No content-->
<a name="top"></a>
<!--And to link the name attribute-->
<a href="#top">Back to Top</a>
Relative Links
Relative Links are links to files on your server. For example:
1 2 3
<a href="hosting.php">Web Hosting</a>
<a href="../index.php">Home</a>
This is perfectly legal to do and often is much better than using an absolute link. As long as the file that is referencing the file or address is within the same directory on your server it will still link properly. If you wish to go to one directory above to “link” a file then you use ../filename.
Absolute Links
Absolute Links are usually links to files beyond your server such as links to other websites. There are times when using an absolute link is necessary like to define an https:// protocol or maybe a address to a subdomain of your website or simply to another page that you know won’t move.
Basics of XHTML – Part #2
Nov 9th
As we covered in the Basics of XHTML, we have basic rules that we need to follow in order to correctly write XHTML and get the results we want. We know that for most elements, we need an opening tag and closing tag. There are, however, some elements that are self-closing such as the img element and br element.
1 2 3 4 5 6 7 8
<start tag>content</end tag>
<a href="http://www.example.com">Example</a>
<img src="images/img.png" />
<br />
This tutorial will cover additional major concepts of HTML such as attributes and a basic introduction to various HTML elements.
HTML Attributes
- HTML elements can have attributes
- Attributes provide more info about the element
- Attributes are always defined in the start tag
The general syntax for attributes is as follows:
1 2 3 4 5
<start attribute="value">...</end>
<a href="http://www.atomicpages.net">AtomicPages</a>
<img src="images/img.png" height="200" width="200" title="Image" />
As mentioned previously, attributes provide additional information about the element that is being used. For instance, consider our img element that is used above. We have three different attributes that are contributing to the information of this element.
- height – setting the height in px
- width – setting with width in px
- title – setting the title of the image
Not all attributes can be used on all HTML elements. There are restrictions on which can be used and which cannot be used. To see all of the attributes, see this W3C reference.
Common Attributes
Here is a list of some very common attributes that we will encounter very often in the future.
1 2 3 4 5 6 7 8 9 10 11 12
<start class="[class name]">...</end tag>
<start style="[inline css]">...</end tag>
<start id="[id name]">...</end tag>
<p class="start">...</p>
<span style="font-size:15px;">...</span>
<div id="header">...</div>
These three attributes are perhaps the most common attributes aside from “href” and “src”. These attributes aid in styling web pages usingCSS which we cover in a separate tutorial series. They are, however, still very important to be aware of and how the function as attributes.
HTML Formatting
We can think of an HTML document as one without any formatting whatsoever. HTML does not have a mind of its own and will not automatically format itself like a term paper would in Microsoft Word or any other word-editing program. All of the formatting is organic and has to be done manually by us. Though this may seem tedious, we eventually grow fond of it because we can see our work come to life.
The most common formatting tags will produce various results. We can create bold text, italic text, big text, an underlined text all without any additional assistance from anything other than pure HTML. We don’t even need anything other than pure HTML so create a web site!
Text Formatting
| Tags | Description |
|---|---|
| <b> | Bold Text |
| <strong> | Strong Text |
| <i> | Italic Text |
| <em> | Emphasized Text |
| <u> | Underlined Text depreciated use inline css instead |
| <s> | Deprecated, strikethrough text. Use <del>. |
| <strike> | Deprecated, strikethrough text. Use <del>. |
| <del> | Deleted Text |
| <ins> | Inserted Text |
| <sub> | Subscript Text |
| <sup> | Superscript Text |
| <big> | Big Text |
| <small> | Small Text |
So what do all of these insane tags do? Well, let’s start form the top!
- Bold and Strong.
- Italic and Emphasized. <i> is deprecated.
- Underlined Text without the use of styles. <u> is deprecated.
StrikeandStrikethoughdo the same thing but are depreciated1Deleted Textis the preferred way of creating strike though text.- Inserted Text is an alternative way of creating underlined text.
- Subscript is subscript text.
- Superscript is superscript text.
- Big is a way of creating big text.
- Small is a way of creating small text.
Computer Text
| Tags | Description |
|---|---|
| <code> | Computer Code Text |
| <pre> | Preformatted Text |
| <samp> | Sample Computer Code |
| <tt> | Teletype Text |
| <kbd> | Keyboard Text |
| <var> | Defines a Variable |
- Code, Pre, Teletype, Sample Computer Text, and Keyboard Text do essentially the same, which is formatting text in a way that it appears to be computer code. There are differences between them, however, but we need not be worried about this yet.
- Variables is slightly different for instead of making the text monospace it actually italicizes the text.
Quotes, Citations, etc
| Tags | Description |
|---|---|
| <blockquote> | Long Quotations |
| <q> | Short Quotations |
| <cite> | Cites something |
| <address> | Address Element |
| <abbr> | Abbreviation Element |
| <dfn> | Definition Term |
| <bdo> | Text Direction |
-
Generally you’ll see blockquote on forums or blogs somewhere, you’ll click “quote” and then a new window will pop up and you’ll see blockquote in HTML of BB Code form (usually). As you can see, using this blockquote element, our text is the same, however, the background is different to signify this long quote.
The “q” element is a short quote.
Notice how the “q” element is simply surrounded by double quotes to signify it’s existence as a short quote.- Cited text it different to let users know that whatever you are referring to is a cited source. You may want to utilize the “sub” and/or “sup” elements when using the “cite” element so you can create footnotes at the bottom of the web page.
-
The address element if for placing an address in
. The text is intentionally different for the specific use of an address.
- A definition term is more like a type of list. We will be covering this later on.
- This “bdo” element should not be be used unless you want wish to have the direction of text reversed.This text will read from left to right. This text well read from right to left.(This text will read from right to left – it’s backwards!)
1. Depreciated — These are outdated HTML elements that have been replaced by more conventional, functional, and flexible alternatives. Though some browsers may support these elements, their continued support cannot be assumed; eventually these tags will become obsolete and browsers will not support their functionality.
A List of Depreciated Elements and their Alternatives
| Tags | Description | Replacement |
|---|---|---|
| <applet> | Inserts Applet | <object> |
| <basefont /> | Sets defaul font color and size | font style sheets |
| <center> | Centered Text | text-align:center; |
| <dir> | Directory List | <ul> |
| <font> | Font, color, and size of text | font style sheets |
| <isindex> | Adds search field | <form> |
| <menu> | Menu List | <ul> |
| <s> | Strike through text | <del> or style sheets |
| <strike> | Strike through text | <del> or style sheets |
| <u> | Underlined text | text-decoration:unerline; |
| <xmp> | Preformatted Text | <pre> |
