Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, December 7, 2010

Useful link,article and source code directories

Millions of peoples are trying to get traffic to their websites and spending lots of money in this. Submit article to article directory is a good and popular way of getting SEO and traffic to website.There are lots of paid article directories available in web but a very few free. This software give you chance to submit your article to world's best free article directory article.ognilab.com totally free of cost.

Submit Your article to world's best free article directory

This softwre can help you to find your most needed C,C++ source code from the C,C++ source code directory cprogram.org.You can also submit your source code in web to spread and test your knowledge on programming.Submit C,C++ source code to this directory to make it rich with source code and welfare of other programmers.


Millions of peoples are trying to get traffic to their websites and spending lots of money in this. Submit website link to Web directory is a good and popular way of getting SEO and traffic to website.There are lots of paid web directories available in web but a very few free. This software give you chance to submit your website link to world's best free web directory dir.ognilab.com totally free of cost.

Sunday, September 26, 2010

The :focus pseudo-class

Rarely used due to a lack of browser support, the :focus pseudo-class is worth being
mindful of. It enables you to define the link state of a focused link. Focusing usually occurs
when tabbing to a link, and so the :focus pseudo-class can be a handy usability aid. At the
time of writing, it works in Firefox and Safari, but is ignored in Opera and Internet
Explorer, although Microsoft’s browser does at least surround any focused links with a
dotted line. (Note that Firefox and Safari also surround focused links with a dotted line
and aqua border, respectively.)
The following example, used in editing-link-styles-using-css.css, turns the background
of focused links yellow in compliant browsers:
1 : 
a:focus {
background: yellow;
}
<a href="index.html">Homepage</a> | <a href="products.html">
åProducts</a> | <a href="contact-details.html">Contact
å details</a>
</div>

2. Add some padding to the existing body rule in the CSS to add some spacing around
the page content:
body {
font: 62.5%/1.5 Verdana, Arial, Helvetica, sans-serif;
padding: 30px;
}

3. Add some rules to define the main states for links on the web page. The following
rules color links orange, change them to red on the hover state, make them gray
on the visited state, and make them black on the active state.
a:link {
color: #f26522;
}
a:visited {
color: #8a8a8a;
}
a:hover {
color: #f22222;
}
a:active {
color: #000000;
}

4. Next, style the navigation links. Contextual selectors are used to style the links
within the navigation div.
#navigation a, #navigation a:visited {
text-decoration: none;
font-weight: bold;
color: #666666;
text-transform: uppercase;
}
#navigation a:hover {
text-decoration: underline;
}
The first rule removes the underline from all links within the navigation div, renders
them in bold and uppercase, and colors them a medium gray. The second rule
brings back the underline on the hover state.

5. Style the footer links. Add another contextual selector to style the footer links,
making them smaller than links elsewhere on the page:
#footer a:link, #footer a:visited {
font-size: 0.8em;
}
And there we have it: three different link styles on the same page, without messing around
with classes.

The difference between a and a:link

Many designers don’t realize the difference between the selectors a and a:link in CSS.
Essentially, the a selector styles all anchors, but a:link styles only those that are clickable
links (i.e., those that include an href attribute) that have not yet been visited. This means
that, should you have a site with a number of fragment identifiers, you can use the a:link
selector to style clickable links only, avoiding styling fragment identifiers, too. (This prevents
the problem of fragment identifiers taking on underlines, and also prevents the
potential problem of user-defined style sheets overriding the a rule.) However, if you
define a:link instead of a, you then must define the visited, hover, and active states,
otherwise they will be displayed in their default appearances. This is particularly important
when it comes to visited, because that state is mutually exclusive to link, and doesn’t
take on any of its styling. Therefore, if you set font-weight to bold via a:link alone, visited
links will not appear bold (although the hover and active states will for unvisited
links—upon the links being visited, they will become hover and active states for visited
links and will be displayed accordingly).

Correctly ordering link states

The various states have been defined in a specific order in the previous example: link,
visited, hover, focus, active. This is because certain states override others, and those
“closest” to the link on the web page take precedence.
There is debate regarding which order the various states should be in, so I can only provide
my reasoning for this particular example. It makes sense for the link to be a certain
color when you hover over it, and then a different color on the active state (when
clicked), to confirm the click action. However, if you put the hover and active states in
the other order (active, hover), you may not see the active one when the link is clicked.
This is because you’re still hovering over the link when you click it.
The focus state is probably primarily use keyboard users, and so they won’t typically see
hover anyway. However, for mouse users, it makes logical sense to place focus after hover,
because it’s a more direct action—in other words, the link is selected, ready for activation
during the focus state; but if you ordered the states focus, hover, a link the cursor is
hovering over would not change appearance when focused, which from a user standpoint
is unhelpful.
However, there is a counter argument that recommends putting focus before hover, so
that when an already focused link (or potentially any other focused element for non-IE
browsers) is hovered over, it will change from the focused state to indicate that it is now
being hovered over. Ultimately, this is a chicken-and-egg scenario—do you want a hovered
link to change from hover to focus to active? The focus will get lost somewhere in there
until the link is depressed (and the active state removed), by which time the link will be
in the process of being followed.
In the end, the decision should perhaps rest with how you’re styling states and what information
you want to present to the user, and often the focus state is a duplication of hover
anyway, for the benefit of keyboard users. And on some occasions, it doesn’t matter too
much where it’s put, if the styling method is much different from that for other states—
for example, when a border is applied to focus, but a change of color or removal of
underlines is used for the other states. However, if you decide on LVFHA or some other
order, you’ll have to make your own way of remembering the state order!

Defining link states with CSS

CSS has advantages over the obsolete HTML method of defining link states. You gain control
over the hover and focus states and can do far more than just edit the state colors—
although that’s what we’re going to do first.
Anchors can be styled by using a tag selector:
a {
color: #3366cc;
}
In this example, all anchors on the page—including links—are turned to a medium blue.
However, individual states can be defined by using pseudo-class selectors (so called
because they have the same effect as applying a class, even though no class is applied to
the element):
a:link {
color: #3366cc;
}
a:visited {
color: #666699;
}
a:hover {
color: #0066ff;
}
a:focus {
background-color: #ffff00;
}
a:active {
color: #cc00ff;
}

Top-of-page links

Internal page links are sometimes used to create a top-of-page/back-to-top link. This is
particularly handy for websites that have lengthy pages—when a user has scrolled to the
bottom of the page, they can click the link to return to the top of the document, which
usually houses the navigation. The problem here is that the most common internal linking
method—targeting a link at #top—fails in many browsers, including Firefox and Opera.
<a href="#top">Back to top</a>
You’ve likely seen the previous sort of link countless times, but unless you’re using Internet
Explorer or Safari, it’s as dead as a dodo. There are various workarounds, though, one of
which is to include a fragment identifier at the top of the document. At the foot of the
web page is the Back to top link shown previously, and the fragment identifier is placed
at the top of the web page:
<a id="top" name="top"></a>
This technique isn’t without its problems, though. Some browsers ignore empty elements
such as this (some web designers therefore populate the element with a single space); it’s
tricky to get the element right at the top of the page and not to interfere with subsequent
content; and, if you’re working with XHTML Strict, it’s not valid to have an inline element
on its own, outside of a block element, such as p or div.
Two potential solutions are on offer. The simplest is to link the top-of-page link to your
containing div—the one within which your web page’s content is housed. For sites I
create—as you’ll see in Chapter 7—I typically house all content within a div that has an id
value of wrapper. This enables me to easily control the width of the layout, among other
things. In the context of this section of this chapter, the wrapper div also provides something
for a top-of-page link to jump to. Clicking the link in the following code block would
enable a user to jump to the top of the wrapper div, at (or very near to) the top of the
web page.
<a href="#wrapper">Top of page</a>
Note that since standalone inline elements aren’t valid in XHTML Strict, the preceding
would either be housed within a paragraph or a footer div, depending on the site.
Another solution is to nest a fragment identifier within a div and then style the div to sit
at the top left of the web page. The HTML for this is the following:
<div id="topOfPageAnchor">
<a id="top" name="top"> </a>
</div>
In CSS, you would then add the following:
div#topOfPageAnchor {
position: absolute;
top: 0;
left: 0;
height: 0;
}
Setting the div’s height to 0 means it takes up no space and is therefore not displayed; setting
its positioning to absolute means it’s outside the normal flow of the document, so it
doesn’t affect subsequent page content. You can test this by setting the background color
of a following element to something vivid—it should sit tight to the edge of the browser
window edges.

Web Navigation types

Inline navigation: General links within web page content areas
Site navigation: The primary navigation area of a website, commonly referred to as
a navigation bar
Search-based navigation: A search box that enables you to search a site via terms
you input yourself


Inline navigation
Inline navigation used to be the primary way of navigating the Web, which, many moons
ago, largely consisted of technical documentation. Oddly, inline navigation—links within a
web page’s body copy—is less popular than it once was. Perhaps this is due to the increasing
popularity of visually oriented web design tools, leading designers to concentrate more
on visuals than usability. Maybe it’s because designers have collectively forgotten that links
can be made anywhere and not just in navigation bars. In any case, links—inline links in
particular—are the main thing that differentiates the Web from other media, making it
unique. For instance, you can make specific words within a document link directly to
related content. A great example of this is Wikipedia (www.wikipedia.org), the free encyclopedia.


Site navigation
Wikipedia showcases navigation types other than inline. To the left, underneath the logo,
is a navigation bar that is present on every page of the site, allowing users to quickly access
each section. This kind of thing is essential for most websites—long gone are the days
when users often expected to have to keep returning to a homepage to navigate to new
content.
As Wikipedia proves, just because you have a global navigation bar, that doesn’t mean you
should skimp on inline navigation. In recent times, I’ve seen a rash of sites that say things
like, “Thank you for visiting our website. If you have any questions, you can contact us byclicking the contact details link on our navigation bar.” Quite frankly, this is bizarre. A better
solution is to say, “Thank you for visiting our website. If you have any questions, please
contact us,” and to turn “contact us” into a link to the contact details page. This might
seem like common sense, but not every web designer thinks in this way.

Search-based navigation
Wikipedia has a search box within its navigation sidebar. It’s said there are two types of
web users: those who eschew search boxes and those who head straight for them. The
thing is, search boxes are not always needed, despite the claims of middle managers the
world over. Indeed, most sites get by with well-structured and coherent navigation.
However, sites sometimes grow very large (typically those that are heavy on information
and that have hundreds or thousands of pages, such as technical repositories, review
archives, or large online stores, such as Amazon and eBay). In such cases, it’s often not feasible
to use standard navigation elements to access information. Attempting to do so leads
to users getting lost trying to navigate a huge navigation tree.
Unlike other types of navigation, search boxes aren’t entirely straightforward to set up,
requiring server-side scripting for their functionality. However, a quick trawl through
a search engine provides many options, including Google Custom Search Engine
(www.google.com/coop/cse/) and Yahoo Search Builder (http://builder.search.yahoo.
com/m/promo).

Backward compatibility with fragment identifiers

In older websites, you may see a slightly different system for accessing content within a
web page, and this largely involves obsolete browsers such as Netscape 4 not understanding
how to deal with links that solely use the id attribute. Instead, you’ll see a fragment
identifier, which is an anchor tag with a name attribute, but no href attribute. For instance,
a fragment identifier for the first answer is as follows:
<p><a id="answer1" name="answer1">Answer 1!</a></p>
The reason for the doubling up, here—using both the name and id attributes, is because
the former is on borrowed time in web specifications, and it should therefore only be used
for backward compatibility.

Internal page links

Along with linking to other documents, it’s possible to link to another point in the same
web page. This is handy for things like a FAQ (frequently asked questions) list, enabling the
visitor to jump directly to an answer and then back to the list of questions; or for top-ofpage
links, enabling a user single-click access to return to the likely location of a page’s
masthead and navigation, if they’ve scrolled to the bottom of a long document.
When linking to other elements on a web page, you start by providing an id value for any
element you want to be able to jump to. To link to that, you use a standard anchor element
(<a>) with an href value equal to that of your defined id value, preceded by a hash
symbol (#).
For a list of questions, you can have something like this:
<ul id="questions">
<li><a href="#answer1">Question one</a></li>
<li><a href="#answer2">Question two</a></li>
<li><a href="#answer3">Question three</a></li>
</ul>
Later on in the document, the first two answers might look like this:
<p id="answer1">The answer to question 1!</p>
<p><a href="#questions">Back to questions</a></p>
<p id="answer2">The answer to question 2!</p>
<p><a href="#questions">Back to questions</a></p>
As you can see, each link’s href value is prefixed by a hash sign. When the link is clicked,
the web page jumps to the element with the relevant id value. Therefore, clicking the
Question one link, which has an href value of #answer1, jumps to the paragraph with the
id value of answer1. Clicking the Back to questions link, which has an id value of
#questions, jumps back to the list, because the unordered list element has an id of
questions.

**NOTE : It’s worth bearing in mind that the page only jumps directly to the linked element if
there’s enough room underneath it. If the target element is at the bottom of the web
page, you’ll see it plus a browser window height of content above.

Creating and styling web page links

With the exception of search boxes, which are forms based on and driven by server-side
scripting, online navigation relies on anchor elements. In its simplest form, an anchor element
looks like this:
<a href="http://www.friendsofed.com/">A link to the friends of ED
å website</a>

The href attribute value is the URL of the destination document, which is often another
web page, but can in fact be any file type (MP3, PDF, JPEG, and so on). If the browser can
display the document type (either directly or via a plug-in), it does so; otherwise, it downloads
the file (or brings up some kind of download prompt).
There are three ways of linking to a file: absolute links, relative links, and root-relative
links. We’ll cover these in the sections that follow, and you’ll see how to create internal
page links, style link states in CSS, and work with links and images. We’ll also discuss
enhanced link accessibility and usability, and link targeting.

Absolute links
The preceding example shows an absolute link, sometimes called a full URL, which is typically
used when linking to external files (i.e., those on other websites). This type of link
provides the entire path to a destination file, including the file transfer protocol, domain
name, any directory names, and the file name itself. A longer example is
<a href="http://www.wireviews.com/lyrics/instar.html">Instar lyrics</a>
In this case, the file transfer protocol is http://, the domain is wireviews.com, the directory
is lyrics, and the file name is instar.html.
If you’re linking to a website’s homepage, you can usually leave off the file name, as in the
earlier link to the friends of ED site, and the server will automatically pick up the default
document—assuming one exists—which can be index.html, default.htm, index.php,
index.asp, or some other name, depending on the server type. However, adding a trailing
slash after the domain is beneficial (such as http://www.wireviews.com/). If no default
document exists, you’ll be returned a directory listing or an error message, depending on
whether the server’s permissions settings enable users to browse directories.

Relative links
A relative link is one that locates a file in relation to the current document. Taking the
Wireviews example, if you were on the instar.html page, located inside the lyrics directory,
and you wanted to link back to the homepage via a relative link, you would use the
following code:
<a href="../index.html">Wireviews homepage</a>
The index.html file name is preceded by ../, which tells the web browser to move up one
directory prior to looking for index.html. Moving in the other direction is done in the
same way as with absolute links: by preceding the file name with the path. Therefore, to
get from the homepage back to the instar.html page, you would write the following:
<a href="lyrics/instar.html">Instar lyrics</a>
In some cases, you need to combine both methods. For instance, this website has HTML
documents in both the lyrics and reviews folders. To get from the instar.html lyrics
page to a review, you have to go up one level, and then down into the relevant directory
to locate the file:
<a href="../reviews/alloy.html">Alloy review</a>

Root-relative links
Root-relative links work in a similar way to absolute links, but from the root of the website.
These links begin with a forward slash, which tells the browser to start the path to the file
from the root of the current website. Therefore, regardless of how many directories deep
you are in the Wireviews website, a root-relative link to the homepage always looks
like this:
<a href="/index.html">Homepage</a>
And a link to the instar.html page within the lyrics directory always looks like this:
<a href="/lyrics/instar.html">Instar lyrics</a>
This type of link therefore ensures you point to the relevant document without your
having to type an absolute link or mess around with relative links, and is, in my opinion,
the safest type of link to use for linking to documents elsewhere on a website. Should a
page be moved from one directory to one higher or lower in the hierarchy, none of the
links (including links to style sheets and script documents) would require changing.
Relative links, on the other hand, would require changing; and although absolute links
wouldn’t require changing, they take up more space and are less modular from a testing
standpoint; if you’re testing a site, you don’t want to be restricted to the domain in
question—you may wish to host the site locally or on a temporary domain online so that
clients can access the work-in-progress creation.
All paths in href attributes must contain forward slashes only. Some software—
notably older releases from Microsoft—creates and permits backward slashes (e.g.,
lyrics\wire\154.html), but this is nonstandard and does not work in non-Microsoft
web browsers.

Monday, September 20, 2010

Using CSS to wrap text around images

You can use the float and margin properties to enable body copy to wrap around an
image. The method is similar to the pull quote example in the previous chapter, so we
won’t dwell too much on this. Suffice to say that images can be floated left or right, and
margins can be set around edges facing body copy in order to provide some whitespace.
For example, expanding on the previous example, you could add the following rules to
ensure that the surrounding body copy doesn’t hug the image:
.photo {
border-width: 8px 8px 20px 8px;
border-style: solid;
border-color: #ffffff;
float: right;
margin-left: 20px;
margin-bottom: 20px;
}
This results in the following effect shown in the following image.
 
See using-css-to-wrap-around-images.html, using-css-to-wrap-around-images.css,
and sunset.jpg in the chapter 4 folder for a working example of this page.

Using CSS when working with images

Applying CSS borders to images
Alternatively, you could set borders to be on by default, and override them in specific
areas of the website via a rule using grouped contextual selectors:
img {
border: 1px solid #000000;
}
#masthead img, #footer img, #sidebar img {
border: 0;
}
Finally, you could override a global border setting by creating a noBorder class and then
assigning it to relevant images. In CSS, you’d write the following:
.noBorder {
border: 0;
}
And in HTML, you’d add the noBorder class to any image that you didn’t want to have a
border:
<img class="noBorder" src="sunset.jpg" height="200" width="400"
å alt="A photo of a sunset" />
Clearly, this could be reversed (turning off borders by default and overriding this with, say,
an addBorder style that could be used to add borders to specific images). Obviously, you
should go for whichever system provides you with the greatest flexibility when it comes to
rapidly updating styles across the site and keeping things consistent when any changes
occur. Generally, the contextual method is superior for achieving this.
Although it’s most common to apply borders using the shorthand shown earlier, it’s possible
to define borders on a per-side basis, as demonstrated in the “Using classes and CSS
overrides to create an alternate pull quote” exercise in Chapter 3. If you wanted to style a
specific image to resemble a Polaroid photograph, you could set equal borders on the top,
left, and right, and a larger one on the bottom. In HTML, you would add a class attribute
to the relevant image:
<img class="photo" src="sunset.jpg" height="300" width="300"
å alt="Sunset photo" />
In CSS, you would write the following:
.photo {
border-width: 8px 8px 20px;
border-style: solid;
border-color: #ffffff;
}The results of this are shown in the image to the
right. (Obviously, the white border only shows if
you have a contrasting background—you wouldn’t
see a white border on a white background!)
Should you want to, you can also reduce the declaration’s
size by amalgamating the border-style
and border-color definitions:
.photo {
border: solid #ffffff;
border-width : 8px 8px 20px;
}

You may have noticed earlier that I didn’t mention the border attribute when working
through the img element. This is because the border attribute is deprecated; adding borders
to images is best achieved and controlled by using CSS. (Also, because of the flexibility
of CSS, this means that if you only want a simple surrounding border composed of flat
color, you no longer have to add borders directly to your image files.) Should you want to
add a border to every image on your website, you could do so with the following CSS:
img {
border: 1px solid #000000;
}
In this case, a 1-pixel solid border, colored black (#000000 in hex), would surround every
image on the site. Using contextual selectors, this can be further refined. For instance,
should you only want the images within a content area (marked up as a div with an id
value of content) to be displayed with a border, you could write the following CSS:
div#content img {
border: 1px solid #000000;
}

Choosing formats for images

n order to present images online in the best possible way, it’s essential to choose the best
file format when exporting and saving them. Although the save dialogs in most graphics
editors present a bewildering list of possible formats, the Web typically uses just two: JPEG
and GIF (along with the GIF89, or transparent GIF, variant), although a third, PNG, is finally
gaining popularity, largely due to Internet Explorer 7 finally offering full support for it.

JPEG

The JPEG (Joint Photographic Experts Group) format is used primarily for images that
require smooth color transitions and continuous tones, such as photographs. JPEG supports
millions of colors, and relatively little image detail is lost—at least when compression
settings aren’t too high. This is because the format uses lossy compression, which removes
information that the eye doesn’t need. As the compression level increases, this information
loss becomes increasingly obvious, as shown in the following images. As you can see
from the image on the right, which is much more compressed than the one on the left,
nasty artifacts become increasingly dominant as the compression level increases. At
extreme levels of compression, an image will appear to be composed of linked blocks (see
the following two images, the originals of which are in the chapter 4 folder as tree.jpg
and tree-compressed.jpg).
 

Although it’s tricky to define a cutoff point, it’s safe to say that for photographic work
where it’s important to retain quality and detail, 50 to 60% compression (40 to 50% quality)
is the highest you should go for. Higher compression is sometimes OK in specific circumstances,
such as for very small image thumbnails, but even then, it’s best not to go over
70% compression.
If the download time for an image is unacceptably high, you could always try reducing the
dimensions rather than the quality—a small, detailed image usually looks better than a
large, heavily compressed image. Also, bear in mind that common elements—that is,
images that appear on every page of a website, perhaps as part of the interface—will be
cached and therefore only need to be downloaded once. Because of this, you can get away
with less compression and higher file sizes.
Some applications have the option to save progressive JPEGs. Typically, this format results
in larger file sizes, but it’s useful because it enables your image to download in multiple
passes. This means that a low-resolution version will display rapidly and gradually progress
to the quality you saved it at, allowing viewers to get a look at a simplified version of the
image without having to wait for it to load completely.

GIF

GIF (Graphics Interchange Format) is in many ways the polar opposite of JPEG—it’s lossless,
meaning that there’s no color degradation when images are compressed. However,
the format is restricted to a maximum of 256 colors, thereby rendering it ineffective for
color photographic images. Using GIF for such images tends to produce banding, in which
colors are reduced to the nearest equivalent. A fairly extreme example of this is shown in
the following illustration.
 

GIF is useful for displaying images with large areas of flat color, such as logos, line art, and
type. As I mentioned in the previous chapter, you should generally avoid using graphics for
text on your web pages, but if you do, GIF is the best choice of format.
Although GIF is restricted to 256 colors, it’s worth noting that you don’t have to use the
same 256 colors every time. Most graphics applications provide a number of palette
options, such as perceptual, selective, and Web. The first of those, perceptual, tends to prioritize
colors that the human eye is most sensitive to, thereby providing the best color
integrity. Selective works in a similar fashion, but balances its color choices with web-safe
colors, thereby creating results more likely to be safe across platforms. Web refers to the
216-color web-safe palette discussed earlier. Additionally, you often have the option to
lock colors, which forces your graphics application to use only the colors within the
palette you choose.
Images can also be dithered, which prevents continuous tones from becoming bands of
color. Dithering simulates continuous tones, using the available (restricted) palette. Most
graphics editors allow for three different types of dithering: diffusion, pattern, and noise—
all of which have markedly different effects on an image. Diffusion applies a random pattern
across adjacent pixels, whereas pattern applies a half-tone pattern rather like that
seen in low-quality print publications. Noise works rather like diffusion, but without diffusing
the pattern across adjacent pixels. Following are four examples of the effects of
dithering on an image that began life as a smooth gradient. The first image (1) has no
dither, and the gradient has been turned into a series of solid, vertical stripes. The second
image (2) shows the effects of diffusion dithering; the third (3), pattern; and the fourth (4),
GIF89: The transparent GIF
The GIF89 file format is identical to GIF, with one important exception: you can remove
colors, which provides a very basic means of transparency and enables the background to
show through. Because this is not alpha transparency (a type of transparency that enables
a smooth transition from solid to transparent, allowing for many levels of opacity), it doesn’t
work in the way many graphic designers expect. You cannot, for instance, fade an
image’s background from color to transparent and expect the web page’s background to
show through—instead, GIF89’s transparency is akin to cutting a hole with a pair of scissors:
the background shows through the removed colors only. This is fine when the “hole”
has flat horizontal or vertical edges. But if you try this with irregular shapes—such as in the
following image of the cloud with drop shadow—you’ll end up with ragged edges. In the
example, the idea was to have the cloud casting a shadow onto the gray background.
However, because GIFs can’t deal with alpha transparency, we instead end up with an
unwanted white outline. (One way around this is to export the image with the same background
color as that of the web page, but this is only possible if the web page’s
background is a plain, flat color.)
Because of these restrictions, GIF89s are not used all that much these days. They do cling
on in one area of web design, though: as spacers for stretching table cells, in order to lay
out a page. However, in these enlightened times, that type of technique should be
avoided, since you can lay out precisely spaced pages much more easily using CSS.
PNG
For years, PNG (pronounced ping, and short for Portable Network Graphics) lurked in the
wilderness as a capable yet unloved and unused format for web design. Designed primarily
as a replacement for GIF, the format has plenty to offer, including a far more flexible
palette than GIF and true alpha transparency. Some have mooted PNG as a JPEG replacement,
too, but this isn’t recommended—PNGs tend to be much larger than JPEGs for photographic
images. For imagery with sharp lines, areas of flat color, or where alpha
transparency is required, it is, however, a good choice.

The reason PNG is still less common than GIF or JPEG primarily has to do with Internet
Explorer. Prior to version 7, Microsoft’s browser didn’t offer support for PNG alpha transparency,
instead replacing transparent areas with white or gray. Although a proprietary
workaround exists (see Chapter 9’s “Dealing with Internet Explorer bugs” section), it isn’t
intuitive, and it requires extra code. With post–version 6 releases of Internet Explorer
finally supporting alpha transparency (and Internet Explorer’s share of the market decreasing
somewhat, primarily due to competition from Firefox), it’s worth looking into PNG
when creating layouts.
The three adjacent images highlight the benefit of
PNG over GIF, as shown in a web browser. The first
illustration shows two PNGs on a white background.
The second illustration shows this background replaced
by a grid. Note how the button’s drop shadow is partially
see-through, while the circle’s center is revealed
as being partially transparent, increasing in opacity
toward its edge. The third illustration shows the closest
equivalent when using GIFs—the drop shadow is
surrounded by an ugly cutout, and the circle’s central
area loses its transparency. Upon closer inspection,
the circle is also surrounded by a jagged edge, and the
colors are far less smooth than those of the PNG.
Other image formats
You may have worked on pages in the past and added the odd BMP or TIFF file, or seen
another site do the same. These are not standard formats for the Web, though, and while
they may work fine in some cases, they require additional software in order to render in
some browsers (in many cases, they won’t render at all, or they’ll render inconsistently
across browsers). Furthermore
noise.