CSS
Basics of CSS Revisited
Nov 29th
After awhile of going back and re-reading the previous CSS tutorials, I realized there was some flaws here and there and some things that should have been covered earlier but were not. So we’re going to start anew with a whole new CSS series that contains CSS2.1, CSS3 and HTML5 (including various hacks for webkit-based browsers, IE, FF, and Opera). Shall we begin?
This tutorial is the absolute basics of CSS and aimed at those that would like to learn about CSS but already have an understanding of HTML.
CSS isn’t a web markup language like HTML, XHTML, MathML and so on. CSS is a Cascading Style Sheet and is the backbone for styling web pages. CSS assumes that are you already have prior knowledge of HTML and understand how HTML works so it is critical that an understanding of HTML is present.
What and Why CSS?
Perhaps one might find themselves asking, “what is CSS and why do we need it?” The answer lies in technology. Perhaps you have made a website before using tables in HTML. Yes, this works but it is, however, deprecated (meaning it’s not generally practiced any more). Websites composed of HTML tables are a thing of the past because we now have rich client-side applications and complex server-side applications acting as blogging software, content management systems and online stores. Without CSS, these applications would be extremely difficult to update and maintain.
How to CSS?
Luckily for us, CSS is pretty straight forward and easy to learn! Let us get started with the basics!
CSS has the following structure:
1 2 3 4 5 6 7 8 9
selector {property:value;} single-line statement
selector { multi-line statement
property:value;
property:value;
}
Both examples follow the same general format. We have our selector, property and value.
- Selector – Is the part of the CSS that is used to specify what to style
- Property – Is the part of the CSS that states which method should be used to style the Selector
- Value – Is the part of the CSS that states how much to style or how specifically to style the Selector
Selectors
Selectors can have three different basic forms:
- HTML (Type) Selectors – “Global” Styles that apply to specific HTML elements
- Class Selectors – Can be used multiple times on a web page
- ID Selectors – Mostly used to indicate major sections of a web page
Note: Neither the Class or ID selector can start with a number or a special character, A-Z,a-z only for the first character!
1 2 3 4 5 6 7 8 9 10 11 12
.1bad-selector {property:value;}
.!bad-selector {property:value;}
.good-selector {property:value;}
#1bad-selector {property:value;}
#!bad-selector {property:value;}
#good-selector {property:value;}
HTML selectors, otherwise known as by Type selectors, are literally just HTML tags without angled brackets. For example,
1 2 3 4 5 6 7
a {
color:#ff9300; Controls color of anchor element
text-decoration:underline; controls how the text appears for the anchor
}
“a” represents it html tag to style, that is, <a href=”#”>Link</a> e.g. This is a link.
That link entitled, “This is a link” has two different properties that are controlling the behavior of the link. One property is controlling the color and a separate property is controlling how the text appears. For example:
We have a link here. The code that makes this link work is like the following CSS:
1 2 3 4 5 6 7
a {
color:#0071BB;
text-decoration:unerline;
}
We have our color (color:#0071BB) and we have the underline (text-decoration:unerline;).
We are choosing to type the a tag. We are changing the default color of the anchor and we are changing how the anchor will appear on a page by adding an underline to the anchor.
A breakdown of this would reveal the following relationship: Selector > Property > Value
The selector relies on the property and value to change how the selector will look.
Another example using HTML selectors would be the following:
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
ul {
list-style-type:disc;
padding-left:20px;
}
ul li {
float:left;
margin-left:10px;
}
ul li a {
padding:5px 10px;
background-color:black;
color:white;
}
The CSS above styles the HTML below:
1 2 3 4 5 6 7 8 9
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 1</a></li>
</ul>
Although this example is a little longer and contains more code, there is still the relationship between the selectors, properties, and values. We still are choosing which HTML elements to style and we are using properties and values to style them.
Class Selectors
Class selectors are different than HTML selectors. We can use class selectors multiple times on a web page. Class selectors can be used on any HTML element that allows for the use of the class attribute in HTML. Class selectors are detonated by an end stop (.) before the name of the selector.
For instance,
1 2 3 4 5 6 7 8 9 10 11
<ul>
<li class="active"><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
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 35 36 37 38 39 40 41 42 43
/*"Global" Styles*/
ul {
list-style-type:disc;
padding-left:20px;
}
ul li {
float:left;
margin-left:10px;
}
ul li a {
padding:5px 10px;
background-color:black;
color:white;
}
/*Class Selector*/
.active {
padding:5px 10px;
background-color:black;
color:white;
}
On the first li element we have <li class=”active”>. The class attribute is looking for the class selector named “active” and applying those styles to that element. We will discuss class selectors in greater detail in a later tutorial. The main idea for now is that they can be used multiple times in a web page and the selector can be called by using the “class” attribute on virtually any HTML element.
ID Selectors
ID selectors are traditionally used to indicate the major divisions between markup and are mostly used on div (or other block-level element) tags. ID selectors are denotated by the use of a pound (#) symbol.
For example:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<div id="header">
<div id="nav">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
</div>
</div>
<div id="sidebar">
<h2>Joe Smith</h2>
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
</ul>
</div>
<div id="content">
<p>Some text here</p>
</div>
<div class="clearfix"></div>
<div id="footer">
<p>Copyright © AtomicPages.net 2010. All Rights Reserved.</p>
</div>
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
body {
margin:0 auto;
width:1000px;
font:11px sans-serif;
color:#fff;
}
.clearfix {clear:both;}
#header {
margin:0 auto;
display:block;
}
#nav {display:table;}
#nav ul {list-style-type:none;}
#nav ul li {
float:left;
padding-left:8px;
}
#sidebar {
width:200px;
float:left;
}
#content {
width:800px;
float:right;
}
#footer {display:table;}
Notice how the ID attribute for HTML works the same way as the class attribute. The ID attribute calls for the id selector with the given name and applies the styles to it. The <div id=”nav”>, for instance, is calling for the id selector names nav and applying the styles to it. The divs and the ids are also creating logical divisions on our web page e.g. header, nav[igation], sidebar, content and footer.
Comments
Comments are essential to creating any website or program. This allows us to understand what we are thinking or to make additional notes on a web page or program. This also allows for other people to easily see what we our intent is without having to guess.
CSS comments are similar to most multi-line comments in PHP and other programming languages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*This is a single line comment*/
/*
*This document was created by AtomicPages.net
*/
body {
margin:0 auto; /*sets top + bottom margin to 0 and left + right margins to auto*/
width:1000px;
font:11px sans-serif; /*keep sans-serif for continuity across the site*/
color:#fff; /*do NOT change this value!!*/
}
Comments are useful for making annotations for programmers who don’t deal with the design of website very much, making your code easier to understand, and giving yourself or whoever created the style sheet credit!
Think you got it? Take the quiz and find out!
CSS Attribute Selectors
Aug 16th
CSS Attribute selectors are used to select specific attributes in HTML. For example,
1 2 3 4 5 6 7
<body>
<h2 class="title">Welcome!</h2>
<p class="foo" rel="newText">Some text here</p>
</body>
We have two class attributes and on rel attribute labeled, “newText”. We could use the attribute selector like the following:
1 2 3 4 5 6 7 8 9 10 11 12
.title {font-size:2em;}
.foo {color:#ccc;}
p[rel=newText] { /*attribute selector*/
font-size:1.15em;
font-style:italic;
}
Using this rel attribute and stating what its value is, we can add styles to that exact element even though it has other inherited styles.
Breakdown
Attribute selectors can be somewhat strange at first. But fret not! They’re quite easy to learn and can be useful in tricky situations.
[attrib=value]
This means the attribute will equals a certain value. For example:
1 2 3 4 5 6 7 8 9 10 11
<div id="form">
<form action="process.php" method="post">
<input class="button" type="button" name="button"
value="Click Me" />
</form>
</div>
Since this button already has a class attribute, it’s already being styled independently. For the sake of argument, let us assume this button is used multiple times on a website and it would be a pain for us to add a new class value. We could simply use an attribute selector to style the button with the value of “Click Me!”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
input.button {
padding:3px;
background:#3b3b3b url(images/button.png) repeat-x;
width:50px;
height:25px;
color:#ccc;
}
input.button[value=Click Me] {
background:#4c4c4c url(images/new-button.png) repeat-x;
color:#999;
}
We have our class called “button” which is styled a certain way. Assuming it was a pain for us to create a new class, we can have the attribute selector get the exact value of “Click Me” and then style it differently.
[attrib*=value]
This one is a little bit more strange. The “*” in this situation kind of acts as a wildcard. This “*=” will search for the the following value anywhere in the attribute value. For example:
1
<h3 rel="foobarfoo">Text here</h3>
Using this attribute selector we could do the following:
1 2 3 4 5 6 7
h3[rel*=bar] {
text-shadow:1px 1px 1px #000;
color:#fff1d8;
}
This will search the attribute for the word bar and add the styles you want to it. We can also look at this from a different angle:
1 2 3 4 5
<div class="item1">Content here</div>
<div class="item_2">Content here</div>
<div class="item-3">Content here</div>
This would be considered poor coding on any level. But let us assume there was a situation like this and you wanted to create a style that would apply to all three of these class selectors. Instead of editing each one individually, we could do the following:
1
div[class*=post] {font-family:monospace;}
[attrib^=value]
This allows us to choose an attribute based on how it starts. If we have several attributes that start with the same string of text with multiple id and class styles added to the elements already, this can make our life easier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<div class="foo bar" rel="hello-world">Content Here</div>
<div id="world" class="foo">
<ul class="bar" rel="hello-world">
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li rel="hello-world">Item</li>
<ul>
With a little CSS…
1
*[rel^=hello-world] {font-style:italic;}
Note: The * in this instance is a wildcard which will automatically put whatever element the attribute and value applies to.
Here is an alternative example:
1 2 3 4 5 6 7
<a href="http://www.atomicpages.net/blog/2010/05/04/css3-opacity/">CSS3 Opacity</a>
<a href="http://www.atomicpages.net/blog/2010/04/09/mmf2-beginning-video-tutorial-series/">MMF2 Tutorial Series</a>
<a href="http://www.w3.org/standards/xml/core">W3C XML Info</a>
<a href="http://www.whatwg.org/">WHATWG</a>
1
a[href^=http://www.aomicpages.net/] {color:#ff9300;}
[attrib$=value]
This will search for the value but at the end of the string.
1 2 3 4 5 6 7 8 9 10
<div class="foo bar">
<!--content here-->
</div>
<div class="bar"></div>
<div class="foo"></div>
1
div[class$=bar] {text-decoration:underline;}
[attrib~=value]
A typical HTML element that has multiple classes styling it would look like the following:
1
<div class="foo bar"></div>
Notice that the values are separated by a space. What if we had a different attribute that had multiple values that were separated by a space? Could we use *=? Probably, but the issue with *= is that it can be too picky since this does not require spaces. For example,
1
<div class="red" rel="foo bar"></div>
1 2 3
div.red {color:red;}
div[rel~=foo] {color:#470b0b;}
Using ~= would require the attribute to be separated by spaces if there were multiple values.
[attrib|=value]
This attribute selector allows us to styles attribute values separated by a dash. This is an alternative to using *=. See the following code:
1
<div class="blue" rel="bar-foo-bar"></div>
1 2 3
div.blue {background-color:blue;}
div[rel|=bar] {background-color:rgba(50, 50, 50, 0.6);}
Multiple Attribute Selectors
We can use multiple attribute selectors if we want. Consider the following code:
1
<div title="AtomicPages Blog" rel="example-link" class="blog img"> </div>
1
div[title=AtomicPages Blog][rel|=link] {color:#ccc;}
Is my browser supported?
The only browser that isn’t supported it Internet Explorer 6.
Basics of CSS – Part #10
Jul 6th
Today we’re going to talk about tables and how they can look significantly better when we add a little bit of CSS to them. If you need a quick refresher on tables, please click here.
Styling Tables
As mentioned above, styling tables is very useful and can instantly make a webpage come to life. The HTML default table is like the following:
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
Pretty boring if you ask me. Notice how the table has a background of transparent so it will take the color of any background element. The table has that border by default and it definitely could use some tweaking to make it look better.
We’re going to use some key properties:
- border-collapse
- border
The border property allows us to style all four corners of a border at once, or each side individually. There are no arbitrary shapes with borders. All elements have a clearly defined left, right, bottom, and top side to the element.

Notice how the square has an irregular shape and doesn’t appear to be a conventional square. We would call this a diamond shape or something along those lines. It’s actually a perfect square that was rotated 45° on a canvas. Notice how the diamond has a background since it is an image and that background has four sides: top, right, bottom, and left.
To see the border tutorial click here
Now that we have a firm understanding and we have refreshed our minds on the border property, we can fully style our tables!
If we add a little bit of CSS and tweak the table to our liking then it could very well look like this:
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
Although this dives into the world of pseudo-classes, which is discussed in the advanced css tutorial series, we know what our tables can potentially look like with a little bit of work.
Styling
Consider the following code:
1
table, td {border:1px solid #ff9300;}
This code would add a 1px border that is solid with the color #ff9300 (AtomicPages Orange) around the table and td (table cell) elements. The reason why we chose these elements is because the tr (table row) element does not have a border around it be default. (Usually applying a border color to a table would only mean applying it to the table element only and not the td element.)
This code will outline the table and td elements with a border that is 1px in width, that is solid and the color #ff9300. This can be useful if you want to quickly style a table quickly and easily.
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
border-collapse
The border-collapse property is a very useful property that collapses the default double border into a single border. For example:
1 2 3 4 5 6 7
table {
border-collapse:collapse;
border:1px solid #ff9300;
}
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
Notice how the border collapse property instantly gives the table a sharper and less “busy” look. The default border around the table and td elements ceases to exist and we are given a sharper look.
With a little padding (for spacing) for the td elements we can easily space out the table like the following:
1 2 3
th, td {padding:3px;}
/*use as an alternative for cellpadding*/
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
Using that same principle, we can apply background images and colors to the table, tr, th, and/or the td elements.
For example:
1 2 3 4 5 6 7 8 9
table {
border-collapse:collapse;
border:1px solid #ccc;
background-color:#dbdbdb;
}
| Item 1 | Item 2 |
|---|---|
| Item 1 | Item 2 |
| Item 1 | Item 2 |
We’ve seen how tables can look and we know what they look like by default — boring. Styling tables can be a great addition to any website whether it is made from tables itself or from a tableless markup using CSS.

Styling Tables
Size: 8.36 kB
Real Hosting
Jun 11th
Real hosting is something much more than what meets the eye. It is more than a place to merely store files and have a space on the Internet. It’s more than just unlimited this and unlimited that; it involves real space, real deals, real support, and real guarantees.
What you REALLY pay for
Ever heard of the Myth of Unlimited Hosting? Aside from being technically impossible, it is highly unlikely that a web hosting company will charge you $4.95 a month if you agree to stay for 60 months. This includes unlimited disk space, a free domain name, unlimited bandwidth, unlimited databases, unlimited FTP accounts, unlimited emails, and unlimited everything else.
If you happen to break the 60 month agreement you are slapped with a termination fee and other hidden fees. This can quickly become a major hassle, especially when you receive poor support and service when you just want out of a bad hosting situation.
Often, in these situations, the hosting companies will begin to nag at you when too much space is taken up on a shared server, you’re taking up too much CPU, or taking up too much RAM on the server. This renders the promise of unlimited features as invalid and not a real guarantee and not real, honest hosting.
These types of hosting companies will go into your account and begin changing things if you have too many files on the server, if the files are taking up too much space, or too many “unrelated files”. They will disable the website and then it becomes a hassle to get your website back online. While they’re breaking promises, you’re losing traffic, clients, and/or money. Whether it is a business website or a personal blog, it is embarrassing when you have to explain to clients and friends why your website is down in the first place.
While you’re banging your head against a wall wondering why your website was suspended, they will be helping other people and not replying to your support tickets, emails, or phone calls. Some hosts will treat you like a second-class citizen if your account is suspended.
What you get with real hosting from AtomicPages
AtomicPages Real Hosting is different; we do not make promises we cannot keep. We will never claim to have unlimited features and go back on our word later on. The amount of features you pay for is the amount of features you will actually receive and nothing less; no questions asked.
This is what defines real hosting from impostors. We are honest, backup our guarantees, and have real morals. You will never hear that we are suspending your account due to too much space, taking up too many resources on the server, or any other made-up excuse. We will not impose upon your website unless it is breaking the law. AtomicPages real hosting will never leave you in the dark about your website.
Helping people with websites and delivering good quality hosting while keeping a promise is not all smoke and mirrors. There is no mystery to keeping a promise.
CSS3 Opacity
May 4th
The Opacity Property is slightly different then RGBA and HSLA which was discussed in CSS3 Colors.
Opacity v. RGBA & HSLA
Indeed RGBA has the addition of the “alpha” or opacity value like so:
1 2 3
background-color:rgba(127, 60, 87, 0.4);
background-color:hsla(68, 100%, 50%, 0.8);
Either of these examples will have a color that is opaque in some fashion. Consider the following:
If you’re using IE see below:
1 2 3 4 5 6 7 8 9
background-color:rgba(0, 0, 255, 1);
background-color:rgba(0, 0, 255, 0.8);
background-color:rgba(0, 0, 255, 0.6);
background-color:rgba(0, 0, 255, 0.4);
background-color:rgba(0, 0, 255, 0.2);
This code using rgba allows us to create our desired effect.
Allows us to use these opaque colors, however, we can reach the same effect using the standard rgb color space or by using hexadecimal values.
Consider the following example:
We have the same effect using slightly different code in fact. We used the opacity property to create the fading squares.
1 2 3 4 5 6 7 8 9
background-color:rgb(0, 0, 255); opacity:1.0;
background-color:rgb(0, 0, 255); opacity:0.8;
background-color:rgb(0, 0, 255); opacity:0.6;
background-color:rgb(0, 0, 255); opacity:0.4;
background-color:rgb(0, 0, 255); opacity:0.2;
Main difference
The main difference between rgba + hsla and opacity is that we can apply opacity to any element we want instead of just backgrounds. This includes, but is not limited to, images and text.
This is some more text
As we can see, the text is fading with word. The first word is at 100% opacity, the second at 80%, third at 60%, etc… We denote these values in terms of decimals so 1 = 100%, 0.8 = 80%, etc…
Opacity
One really great thing about the opacity property is that you don’t need to create an image sprite if you want an image to be slightly translucent before roll over and fully opaque during roll over. Here is an example of opacity:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
.chrome-opacity {
background:url (images/chrome.png) center center no-repeat;
height:64px;
width:64px;
opacity:0.8;
}
.chrome-opacity:hover {
background:url (images/chrome.png) center center no-repeat;
height:64px;
width:64px;
opacity:1.0;
}
Using method above allows us to easily create semi-opaque images or text and allow them to become fully opaque on roll over or vice versa.
Note: IE 6 only supports the :hover pseudo-class on <a> tags only. Also, IE does not natively support this property where all of the other major browsers do.
To use this property with IE we’ll need to create a conditional comment for all versions of IE like the following:
1 2 3 4 5 6 7 8 9 10 11
<!--[if IE]>
<style type="text/css">
.chrome {filter:alpha(opacity=80);}
.chrome:hover {filter:alpha(opacity=100);}
</style>
<![endif]-->
Note: that IE 6 and 7 do NOT extend support to the pseudo-class :hover on anything but <a> tags and therefore the hover will not work.
If you want to see working examples of the opacity property then please download the file!

opacity.zip
Size: 170.97 KB
