Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript
Megnut

Web Topics
All Articles
Browsers
ColdFusion
CSS
Database
Flash
Graphics
HTML/XHTML/DHTML
Scripting Languages
Tools
Weblogs

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab






Hacking eBay
Pages: 1, 2, 3

Hack #43. Overriding eBay's Fonts and Styles

Use Cascading Style Sheets to change the look of more than just the description.



The <font> tag, introduced in Hack #40, allows you to set the font for any block of text. But it won't have any effect on text outside the <font></font> structure, which means you can never control the appearance of any text outside the description area (e.g., the rest of the auction page). Instead, you'll have to use Cascading Style Sheets (CSS) if you want to apply your styles to the entire page.

The following code, for instance, will turn all text on the page green:

<style>     &callout1;
body,font,td,a {     &callout2;
  font-size: 10pt !important;
  font-family: Verdana,Arial,Helvetica !important;
  color: green !important;     &callout3;
}
</style>

Here's how it works. First, the <style></style> structure &callout1; sets apart our CSS definitions, which will take effect regardless of where the code is placed on the page. Next, a single CSS definition &callout2; lists the HTML tags to modify with our new styles. In this case, we are applying our styles to all <body> text, as well as to any text inside <font></font> tags, <td></td> tags (used for tables), and <a></a> tags (used for links). If you don't want to modify link colors, for instance, just remove ,a from line &callout2;.

The actual styles applied are listed between the curly braces { }, separated one per line for clarity. This includes the font size, the typeface, and, of course, our glorious green color &callout3;. The !important keywords ensure that our styles override any other styles defined elsewhere in the page, which is why even the section headers and the light gray text in the "Time left" section are overpowered by our choice.

If you feel that making all text the same color is a little drastic, you can customize it further:

<style>
body,font,td {
  font-family: Verdana,Arial,Helvetica !important;
  color: blue !important;
}
a {
  font-family: Verdana,Arial,Helvetica !important;
  color: orange !important;
}
</style>

This sets all ordinary text blue, except for links, which will appear orange (this will look pretty awful, by the way). Note the absence of font-size style, which will ensure that the original size of all text is preserved.

TIP: For a complete list of all the CSS styles you can use, you'll need dedicated CSS documentation such as Cascading Style Sheets: The Definitive Guide (O'Reilly), or the official W3C CSS specification (www.w3.org/Style/CSS/).

You can also use this technique to alter other aspects of the page. Don't like the blue shading section headers? Well, you can do something like this:

<style>
td { background-color: white !important; }
</style>

You may find this particular solution somewhat extreme, since it removes the shading used in every table on the page. But it will give you a taste of the power of CSS.

See Hack #41 for further auction-page hacking.

Override Other Sellers' Hacks

You'll eventually encounter an auction that has been hacked up pretty well, possibly by a seller with even worse taste than you. Fortunately, you may still have some control over the pages you view with your own browser.

TIP: Have you ever opened a page with a text/background combination that rendered the page nearly impossible to read? Here's a quick fix: just press Ctrl-A to highlight all text on the page. This will make all text appear white on a dark blue background, which will likely be a significant improvement.

You can set your browser preferences to favor your own color choices over those made by web site designers, but this can be a pain to turn on and off as needed. Instead, you may wish to set up a user stylesheet, a set of carefully constructed preferences and rules that will trump any crazy code like the stuff at the beginning of this hack. User stylesheets are supported by Netscape 6.x/Mozilla 1.x and later, and Internet Explorer 5.x and later.

See Also

Probably the best source for information about user stylesheets is Eric Meyer's CSS Anarchist's Cookbook. There, you'll find ways to "wreck" tables, disable banner ads, and render font coding pretty much useless, all worthwhile pursuits for the anarchist in each of us.

Pages: 1, 2, 3

Next Pagearrow