Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using the <STYLE> Tag

As you can see in Listing 9.1, embedded style information is placed between the <STYLE> and </STYLE> tags. When the W3C released HTML 3.2, it reserved the use of these tags specifically for the purpose of embedded style information. The HTML 4.0 recommendation now formalizes the use of the <STYLE> tag.

The TYPE attribute tells a browser what type of style information setup is used and is most often set equal to “text/css.” Specifying other types allows for some flexibility in the implementation of other style information specification schemes in the future. This also makes it easier for browsers that do not support style sheets to ignore the style information between the two tags.

Style information of the MIME type text/css is set up the same way that style information is set up in a linked style sheet file. The first entry on each line is the keyword from an HTML tag, followed by a list of characteristic/value pairs enclosed in curly braces. You can use any of the characteristics shown in Tables 9.1 or 9.2 when specifying your embedded style information.


NOTE:  Note that the style information you see in Listing 9.1 is enclosed in comment tags (<!-- and -->) so that browsers that do not understand style sheets will ignore the style information rather than presenting it onscreen.

Style information that is specified in the head of a document by using the <STYLE> tag will only apply for that document. If you want to use the same styles in another document, you need to embed the style information in the head of that document as well.
Only use embedded style information for page-specific styles. If you have global style elements you want to implement, place them in a file and link the file as a style sheet in all your documents. Centralizing as much style information as possible is the best way to ensure a consistent implementation.

Inline Style Information

You can specify inline styles inside an HTML tag. The style information given applies to the document content up until the defining tag’s companion closing tag is encountered. Consider the following <TABLE> tag used on the American Boxer Club’s home page (see Figure 9.3):

<TABLE BORDER=“5” WIDTH=“600” STYLE=“float: none; padding-left: 10px;
 padding-right: 10px; padding-top: 5px; padding-bottom: 5px”
BORDERCOLOR=“#800080” CELLSPACING=“0” CELLPADDING=“10”
BORDERCOLORLIGHT=“#800080” BORDERCOLORDARK=“#800080” BGCOLOR=“#EAEAEA”>

The STYLE attribute in the tag suppresses floating and pads the table with 10 pixels on the left and right sides and 5 pixels on the top and bottom. This gives the table that contains the page’s content a little bit of breathing room on all sides.


CAUTION:  

Don’t forget the closing tag when embedding style information in an HTML tag. Otherwise, the effects of the style may extend beyond the point in the document where you wanted them to stop.



FIGURE 9.3  Many HTML tags now accept a STYLE attribute that specifies style information to apply along with the effect of the tag.

Other Tags That Take the STYLE Attribute

You saw in the preceding example that the <P> tag can take the STYLE attribute to define an inline style. Many other tags can take the style attribute as well, including the following:

  Physical style tags: <TT>, <I>, <B>, <U>, <S>, <STRIKE>, <BIG>, <SMALL>, <SUB>, <SUP>
  Logical style tags: <EM>, <STRONG>, <DFN>, <CODE>, <SAMP>, <KBD>, <VAR>, <CITE>, <ACRONYM>, <INS>, <DEL>, <Q>
  Block formatting tags: <BODY>, <BR>, <BLOCKQUOTE>, <ADDRESS>, <DIV>, <HR>, <CENTER>, <H1>, <H2>, <H3>, <H4>, <H5>, <H6>
  List tags: <UL>, <OL>, <LI>, <DL>, <DT>, <DD>, <DIR>, <MENU>
  Image and linking tags: <IMG>, <MAP>, <A>
  Form tags: <FORM>, <LABEL>, <INPUT>, <SELECT>, <TEXTAREA>, <FIELDSET>, <LEGEND>, <BUTTON>, <ISINDEX>
  Table tags: <TABLE>, <CAPTION>, <COLGROUP>, <COL>, <THEAD>, <TBODY>, <TFOOT>, <TR>, <TH>, <TD>

The <SPAN> Tag

For those times when you want to apply a style to part of a document that is not nicely contained between two tags, you can use the <SPAN> and </SPAN> tags to set up the part of the document that is to have the style applied. You assign style characteristics to the area set up by the <SPAN> tag by using the STYLE attribute, as in the previous example with the <P> tag.

As an example of how you might use the <SPAN> tag, consider the following HTML from the W3C’s style sheets home page:

<P ID=p1><A HREF=“#new”><SPAN ID=s1>What’s new?</SPAN></A>
<P ID=p2><A HREF=“#what”><SPAN ID=s2>What are style sheets?</SPAN></A>
<P ID=p3><A HREF=“#press”><SPAN ID=s3>Press clippings</SPAN></A>
<P ID=p5><A HREF=“./CSS”><SPAN ID=s5>CSS</SPAN></A>
<P ID=p6><A HREF=“#dsssl”><SPAN ID=s6>DSSSL</SPAN></A>
<P ID=p7><A HREF=“XSL”><SPAN ID=s7>XSL</SPAN></A>


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.