Usage Tips


Even though you have spent hours finely tuning your CSS style sheet, the webpage will not display correctly. You have even gone as far as defining a unique style the piece of text you are trying to format. What is the problem? It probably lies with the cascading order.

The primary sort of the declarations is by weight and origin

  • !important declarations override normal declarations.
  • For !important declarations, User style sheets override Author style sheets which override the Default style sheet.
  • For normal declarations, Author style sheets override User style sheets which override the Default style sheet.

Note. This is a semantic change since CSS1. In CSS1, author "!important" rules took precedence over user "!important" rules.

The secondary sort is by specificity of selector. A selector's specificity is calculated by concatenating the three numbers a-b-c:

  • count the number of ID attributes in the selector (= a)
  • count the number of other attributes and pseudo-classes in the selector (= b)
  • count the number of element names in the selector (= c)
  • ignore pseudo-elements.

(Use the same number of digits for each parameter, eg 031023 if you have more than nine of a, b or c)

Some examples:

*             {}  /* a=0 b=0 c=0 -> specificity =   0 */
LI            {}  /* a=0 b=0 c=1 -> specificity =   1 */
UL LI         {}  /* a=0 b=0 c=2 -> specificity =   2 */
UL OL+LI      {}  /* a=0 b=0 c=3 -> specificity =   3 */
H1 + *[REL=up]{}  /* a=0 b=1 c=1 -> specificity =  11 */
UL OL LI.red  {}  /* a=0 b=1 c=3 -> specificity =  13 */ 
LI.red.level  {}  /* a=0 b=2 c=1 -> specificity =  21 */
#x34y         {}  /* a=1 b=0 c=0 -> specificity = 100 */ 

Inline style declarations (Example: <li style="color:red;">) are considered to have an ID selector (specifity of a=1, b=0, c=0) and to have been defined last, so will take priority.

If you want to override a certain property, you can force it by specifying !important to the definition. For example

CODE:
  1. li.geshi {
  2.         background-image:none !important;
  3.         border:none;
  4.         padding: 0px;
  5. )
  6. #content ul li {
  7.     background: url(img/bullet.gif) no-repeat 0 7px;
  8. }

will force background-image to be none for any <li class="geshi"> elements even if they are within an element with an ID of #content. The #content ID style would otherwise take precedence.

Bookmark this article

At first glance Cascading Style Sheets (CSS) are the panacea for our formatting woes. If I want a paragraph to be highlighted in yellow, then I would just have to define a class, apply this to the element and away we go.

But there is the knub. It appears that while properties are inherited, classes are not. Thus a paragraph element <p> will inherit the properties from its generic block container <div> but not the class.

For example, the code

HTML:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3.   <style type="text/css">
  4.     #first { color: blue; }
  5.    .two { color: red; text-indent: 4em; }
  6.    p.three{ color:green; }
  7.   </style>
  8.  </head>
  9.  
  10.   <div id="first">
  11.    <p>This paragraph will inherit its properties from ID first and therefore be in blue</p>
  12.   </div>
  13.   <div class="two">
  14.    <p>This paragraph will be formatted using class two and be in red, indented 4 em because the style is inherited from the div element to which the style has been applied</p>
  15.   </div>
  16.   <div class="three">
  17.    <p>This paragraph will not be formatted using style three because the style definition only applies to the paragraph element with a class of three and classes are not inherited</p>
  18.    <p class="three">so the style is not applied unless the class is explicitly stated</p>
  19.   </div>
  20.  </body>
  21.  
  22. </html>

produces the following output

This paragraph will inherit its properties from ID first and therefore be in blue

This paragraph will be formatted using class two and be in red, indented 4 em because the style is inherited from the div element to which the style has been applied

This paragraph will not be formatted using style three because the style definition only applies to the paragraph element with a class of three and classes are not inherited

so the style is not applied unless the class is explicitly stated

Bookmark this article

I could not even assemble a simple Hello World program today :( , must be too tired. I kept getting the error

parse error before `('
`main' declared as function returning a function

The answer should of course be to use curly braces { } on lines 3 and 6

Wrong

C:
  1. #include <stdio.h>
  2. int main (void)
  3.    (
  4.        printf ("Hello World!\n");
  5.        return 0;
  6.    )

$ gcc -c -o test2.o test2.c --save-temps
test2.c:4: parse error before `('
test2.c:4: `main' declared as function returning a function

Right

C:
  1. #include <stdio.h>
  2. int main (void)
  3.    {
  4.        printf ("Hello World!\n");
  5.        return 0;
  6.    }

$ gcc -c -o test2.o test2.c --save-temps
$ echo $?
0

Bookmark this article

Some files have been signed by their author to prove that nobody else has tampered with them. This is particularly true of source code or appllications you have downloaded off the web.

For example the antivirus package clamav can be downloaded from Sourceforge. There will be two files for you to download clamav-x.x.x.tar.gz and clamav-x.x.x.tar.gz.sig. The first file is the source code in a compressed format and the second is the signature for the format. In order to verify the signature, you will need GnuPG or PGP installed on the computer you are going to download the file to. I have given details of how to compile GnuPG elsewhere in this blog.

In order to verify the signature, we use the command gpg --verify clamav-x.x.x.tar.gz.sig

[mylogin][~]$ gpg --verify clamav-x.x.x.tar.gz.sig
gpg: keyring `/home/mylogin/.gnupg/secring.gpg' created
gpg: keyring `/home/mylogin/.gnupg/pubring.gpg' created
gpg: Signature made Mon Mar 13 17:44:03 2006 MST using DSA key ID 985A444B
gpg: Can't check signature: public key not found

The trouble is that we do not have yet the public key for the person who signed the file. We can get this from a public keyserver such as keyserver.pgp.com or pgp.mit.edu. You will need the key ID printed in the penultimate (last but one) line above. In this case 985A444B.

We should be able to use the command gpg --keyserver pgp.mit.edu --recv-keys 0x985A444B to retrieve the key automatically, but get the error
[mylogin][~]$ gpg --keyserver pgp.mit.edu --recv-keys 0x985A444B
gpg: requesting key 985A444B from hkp server pgp.mit.edu
/usr/mylocal/libexec/gnupg/gpgkeys_hkp: error while loading shared libraries: libcurl.so.3: cannot open shared object file: No such file or directory
gpg: no handler for keyserver scheme `hkp'
gpg: keyserver receive failed: keyserver error

So we downloaded the public key from pgp.mit.edu instead and saved it to the file clamav.key. NOTE: In order to lookup the public key, you will need to add '0x' (zero x) to the front of the key ID, so 985A444B becomes 0x985A444B. The public key can be a large file, so copy and paste it rather than trying to type it.
[mylogin][~]$ gpg --import clamav.key
gpg: key 985A444B: public key "Tomasz Kojm " imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: no ultimately trusted keys found

Once we have added the key to our public keyring, we can verify the signature [mylogin][~]$ gpg --verify clamav-0.90RC1.1.tar.gz.sig
gpg: Signature made Mon Oct 16 02:56:15 2006 MDT using DSA key ID 985A444B
gpg: Good signature from "Tomasz Kojm "
gpg: aka "Tomasz Kojm "
gpg: aka "Tomasz Kojm "
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 0DCA 5A08 407D 5288 279D B434 5482 2DC8 985A 444B

Note that we still do not trust this key - we have just proven that the downloaded file has not been tampered with.

Bookmark this article

Most of the time this is a painless task. You just set up your email client and hit the Send/Receive button and away you go. But what happens when things go wrong? How do you troubleshoot the problem? Our Knight in shining armour is telnet. You can use this program to manually perform the sequence of commands as shown below.

telnet mail.xxx.com 25

A typical conversation goes something like this (your entry in bold)

Sending Email

telnet mail.mydomain.com 25
220 mydomain.com ESMTP Sendmail 8.11.6/8.11.6; Thu, 26 Oct 2006 11:18:07 -0600
HELO fromme.com
250 mydomain.com Hello [xxx.xxx.xxx.xxx], pleased to meet you
MAIL FROM: test@
250 2.1.0 test@ Sender ok
RCPT TO: validuser@mydomain.com
250 2.1.5 validuser@mydomain.com... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Date: Sun,17 Aug 1997 18:48:15 +0200
From: Me <forged@dummy.com>
To: "You@Yours.com" <You@Yours.com>
Subject: This is a test message

This is the message body
.

250 2.0.0 k9QHLHX00862 Message accepted for delivery
QUIT
221 2.0.0 mydomain.com closing connection

Connection to host lost.

If your server supports ESMTP, it is also possible to start the conversation with EHLO instead of HELO. ESMTP allows for delivery status notifications and multiple attachment encodings

220 mydomain.com ESMTP Sendmail 8.11.6/8.11.6; Thu, 26 Oct 2006 16:11:25 -0600
EHLO fromme.com
250-mydomain.com Hello [xxx.xxx.xxx.xxx], pleased to meet you
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE
250-DSN
250-ONEX
250-ETRN
250-XUSR
250-AUTH PLAIN LOGIN
250 HELP

Receiving EMail

A typical POP3 (receiving) conversation is

telnet mail.mydomain.com 110
+OK AVG POP3 Proxy Server <9397.1161883939@mydomain.com> 7.1.400/7.1.408 [268.13.11/494]
USER validuser
+OK Password required for validuser
PASS xxxxxxxx
+OK validuser has 10 visible messages (0 hidden) in 1275592 octets.
STAT
+OK 10 1275592
LIST
+OK 10 visible messages (1275592 octets)
1 20018
2 19726
........
9 18883
10 519
.
RETR 10
+OK 519 octets
Return-Path: <test>test@
Received: from fromme.com ([xxx.xxx.xxx.xxx])
by mydomain.com (8.11.6/8.11.6) with SMTP id k9QHLHX00862
for validuser@mydomain.com; Thu, 26 Oct 2006 11:21:48 -0600
Message-Id: <200610261721.k9QHLHX00862@mydomain.com>
X-Envelope-From: test@
X-Envelope-To: validuser@mydomain.com
X-Protocol: SMTP
Date: Sun,17 Aug 1997 18:48:15 +0200
From: Me <forged@dummy.com>
To: "You@yours.com" <You@Yours.com>
Subject: This is a test message
X-UIDL: O*5!!PS:"!7Jk"!~+="!
X-Antivirus: AVG for E-mail 7.1.408 [268.13.11/494]
Mime-Version: 1.0
Content-Type: text/plain

This is the message body

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.11/494 - Release Date: 24/10/2006

.
QUIT
+OK Pop server at mydomain.com signing off.

Connection to host lost.

You can see how easy it is for spammers to send fake or phishing emails - the only genuine piece of information in this header is my IP Address, which I have blanked out [xxx.xxx.xxx.xxx]

Other Tests

The other thing to do is to go to http://www.dnsstuff.com and fill out the DNS Lookup for the MX records of your domain in the top right box

Bookmark this article

Next Page »