The Wayback Machine - https://web.archive.org/web/20081204102052/http://www.webreference.com:80/html/tutorial5/2.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

The Style Attribute and CSS Declarations

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Remember Acme's front page? When I introduced it in the first tutorial I mentioned it was ugly as heck, and unlikely to attract anyone's attention. Let's have a look at it one more time:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
 "http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>
 <HEAD>
  <TITLE>Acme Computer Corp.: Who We Are</TITLE>
 </HEAD>
 <BODY>

<H1>Acme Computer Corp.</H1>

<P>Acme Computer Corporation is a technology-based
company that seeks to offer its customers the 
latest in technological innovation. Our products
are created using the latest breakthroughs in
computers and are designed by a team of top-notch
experts.</P>

<P>We are based in Acmetown, USA, and have offices in 
most major cities around the world. Our goal is to
have a global approach to the future of computing.
Have a look at our product catalog for some 
examples of our innovative approach.</P>

 </BODY>
</HTML>

We have a heading and two paragraphs. Hmm. Let's see how our browser would render this. Have a look here. If you're using Netscape Navigator, Internet Explorer or any browser that has similar behavior, you will see a solid background that is probably gray or something equally disgusting and black text, probably something like Times or Garamond. The heading is probably in large, bold letters. Not much variety here.

Now try this: Replace the heading with the following.

<H1 STYLE="text-align: center; color: red; font: bold
italic 150% sans-serif">Acme Computer Corp.</H1>

Now hold your horses. Before you take a look at what this did to your document, let's explain what's going on.

You just used the STYLE attribute for the first time (congratulations!). The STYLE attribute is a bit different from the other attributes we have seen so far since it can be used on practically every element that can be rendered. This means, more or less, the BODY element and everything it contains. As you might have guessed, the STYLE attribute specifies the preferred rendering style of the element when rendered on visual media. In English, that means you say what you want it to look like.

The value of the style attribute should be pretty self- explanatory. The example above can be broken into three parts:

  1. text-align: center
  2. color: red
  3. font: bold italic 150% sans-serif

Each of these consists of a word, a colon (:) and some more stuff. The three parts are themselves separated by semicolons.

These three things are called CSS declarations. They are the basic foundation of CSS syntax. The part before the colon is called a CSS property. CSS properties are a lot like HTML attributes. Each property, such as "text-align", accepts a specific type of values. These values are the stuff after the colon in each declaration.

So what does it mean? Well, it should be pretty simple to figure out! What you're telling the computer is to center the element's text, display it in red, and use a bold italic sans-serif font at 150% of the default size.

And what will happen? Well, it depends. It depends, mostly, on your browser. You see, CSS is pretty new stuff, and just when we were getting the HTML specification down pat and starting to get browsers to adopt it, out came CSS and ruined the whole thing by starting the joke all over again.

Front Page11345678910

http://www.internet.com

Produced by Stephanos Piperoglou

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
  Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Review: Lenovo ThinkPad SL300 · OCZ PC3-10666 Gold 2x1GB Review · Apple Recommends Antivirus for Macs


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial5/2.html
Created: August 20, 1998
Revised: August 20, 1998

Morty Proxy This is a proxified and sanitized view of the page, visit original site.