Course Technology logoCourse Technology
Tutorial 7

*
 Online 
    Companion 
 Home 

directory folder
Documents 

 HTML: 
 Tutorial 1 
 Tutorial 2 
 Tutorial 3 
 Tutorial 4 
 Tutorial 5 
 Tutorial 6 
 Tutorial 7 
 Tutorial 8 
 Tutorial 9 
 Tutorial 10 


DHTML: 
 Tutorial 1 
 Tutorial 2 
 Tutorial 3 
 Tutorial 4 
 Tutorial 5 


directory folder
Gallery 

directory folder
Software 


directory folder
Data Files 


directory folder
Reference: 

HTML Tags 

 Appendix D: 
 JavaScript 
 Objects, 
 Properties, 
 Methods, 
 Event 
 Handlers 

 Appendix E: 
JavaScript 
 Operators, 
 Elements, 
 Keywords 
  
 Appendix F: 
 Cascading 
 Style Sheets 



Web Pages and HTML icon

Working  with
Cascading Style Sheets

Designing a Style for a Web Site at Maxwell Scientific

Additional Topics

*Other Selector Forms
*WebFonts
*Netscape's Background Blues
*The Resizing Bug
*Internet Explorer's Floating Bug
*Controlling Printing with CSS2



Other Selector Forms

----
In addition to the selector forms discussed in Tutorial 7, you can the following forms:
E1 > E2

This selector is used for an element, E2, that is a direct descendant of the parent element, E1.

E1 + E2

This selector is used for an element, E2, that directly follows the element, E1, in the Web page.

E[attribute]

This selector is used for an element, E, that contains the specified style attribute.

E[attribute = value]

This selector is used for an element, E, that contains a specified style attribute, with a specified value.

E[attribute ~= value]

This selector is used for an element, E, that contains a specified style attribute, that contains part of a specified value (used only for text strings.)

Note that all browsers do not support some of these selector forms. You should always test your page against various browser versions.

To the top

WebFonts

----
A specification introduced with CSS2, but not implemented in current browsers, is WebFonts. WebFonts are fonts stored on the Web server, and downloadable to the browser along with the Web page. By using WebFonts, Web page authors will have greater control and flexibility in their Web page's typography. Three things must happen before WebFonts become a standard part of the Web:
  1. Browsers must support the CSS2 standard.
  2. A common format for WebFonts must be determined that all browsers can read.
  3. Font designers have to create the WebFont files in sufficient quantities to make their use practical on the Web, and there must be a way of legally protecting the font designers work.

To access a Web font, the syntax is:

@font-face {font-family: "font_name"; src: url(URL) }

where font_name is the name assigned to the font, and URL is the URL of the WebFont file. For example, the following style declarations:

<STYLE>

@font-face {font-family: "Broadway"; src:=url(http://www.WebFonts.com/broadway) }
H1 {font-family: Broadway, Arial, serif}
will cause the Web browser to retrieve the Broadway font from the http://www.WebFonts.com/broadway and then use it to display all H1 header text.

To the top

Netscape's Background Blues

----
One area that Netscape is not CSS1 compliant is in how it handles background colors. If you specify a background color to any other element besides the <BODY> tag, the color is only visible behind the text in the element and not the entire element box. To get around this problem, set the width of the element's border to 0. Once you do this, the background of the entire element box will be filled with color.

A similar problem occurs with the padding space around the box content. If you set a background color for the box, the padding space will not acquire that background color in Netscape. To get around this problem, you have to specify the following style declaration for the element:

border: 1px solid none;

This will have no visual effect on the element, but Netscape will now draw a transparent border around the element 1 pixel in width. More importantly, the padding space will now acquire the background color.

To the top

The Resizing Bug

----
Another Netscape bug with respect to styles is the resizing bug. If you use styles in a Web page and view the document in Netscape, all will be well until you resize the browser window. Once you do this, the styles disappear. You can get the styles back using the Reload button from the Netscape toolbar, but it is still troublesome.

One workaround is to create a JavaScript program to do this reloading for you automatically whenever the browser window is resized in Netscape. A simple program to do this is:

<SCRIPT>
  <! Hide from older browsers
   isNS = document.layers;
   if (isNS) {
      saveWidth = innerWidth;
      saveHeight = innerHeight;
   }
 function reStyle() {
   if (innerWidth != saveWidth || innerHeight != saveHeight)
     location.reload();
   }
   if (isNS) onresize = reStyle;
   // Stop hiding>
  </SCRIPT>

You can insert this program in any Web page that uses styles if you want to avoid this problem for Netscape users.

To the top

Internet Explorer's Floating Bug

----
If you use the float attribute with Internet Explorer 4.0, you may have troubles, unless you also specify the width of the element using the width attribute. Failure to include the width of the element may cause the float attribute to be ignored in Internet Explorer 4.0.

To the top

Controlling Printing with CSS2

----
Generally printing a Web page will often result in unsatisfactory output. CSS2 improves this situation by giving Web page authors more control over printing. Note that these style attributes haven't been fully supported by all browsers yet. The selector for the page is:
@page

Before printing the page, the browser needs to know the page dimensions, including the width of the margins and the orientation of the page. To specify the page dimensions, use the attribute:

size: values

where value can be either the width and height of the page, the value "portrait" (for portrait-oriented output), the value "landscape" (for landscape-oriented output) or "auto" (to leave the printing size to the operating system. For example, to specify a page size of 8.5 inches wide by 11 inches high, use the attribute:

@page {size: 8.5in 11in}

or to specify landscape orientation for the printout, use the attribute:

@page {size: landscape)

To control the size of the page margins, use the margin attribute, as follows:

@page {margin: 1in}

to create a 1 inch margin around the page content. If you want to specify different margin sizes, use the following attributes:

@page {margin-top: 0.5in; margin-right: 1in; margin-bottom: 1in; margin-left: 0.5in}

to create a top and left margin of 1/2 inch, and right and bottom margins of 1 inch.

One common problem in printing a Web page is the lack of control over the page breaks. Often the page break will occur at the least convenient spot. You can control this using the following attributes:

  • page-break-before
  • page-break-after
  • page-break-inside

The page-break-before attribute indicates that a page break should occur before the element. This attribute can have the values: auto, always, avoid, left, right, or inherit. The "auto" value allows the operating system to determine the page breaks. The "always" value will always create a page break before the element, while the "avoid" value will always prevent a page break before the element. The "left" and "right" value create page breaks that result in the page in printed as a "left" page or as a "right" page (a "left" page is one that appears on the left size of the fold when printing pages that are to be bound in a book.) The "inherit" value cause the element to inherit whatever page-break-before settings are used for the parent element.

The page-break-after attribute operates the same way, except that it controls the placement of page breaks after the element.

The page-break-inside attribute controls whether a page break can occur within the element's contents. The three values for the page-break-inside attribute are: avoid (to prevent a page break), inherit (to inherit the page-break-inside settings from the parent element), or auto (to leave the page break settings to the operating system.) For example, to keep paragraphs all on one page, use the style:

P {page-break-inside: avoid}

Another way to control page breaks is through widows and orphans. A widow is a typographical term for an isolated line (or lines) at the top of a page. For example, if a page break occurs within a paragraph, the lines placed at the top of the page are called widows or widow lines. The widow attribute can be used to specify the maximum number of widow lines. To set the maximum value to two lines for every paragraph, use the style:

P {widow: 2}

Similarly, orphans are lines left at the bottom of a page. To control the size of the orphan or orphan lines, use the orphan attribute. For example, the style:

P {orphans: 2}

will limit the size of the orphan lines to two lines for every paragraph in the document.

You can learn more about the different CSS2 styles for controlling printed pages by visiting the W3C page at http://www.w3.org/. Once again, be aware that these styles are not yet supported by all browsers.


To the top


*Online Companion Home  
*Software  *Gallery  directory folderData Files  
*Documents: HTML: Tutorial 1 | Tutorial 2 | Tutorial 3 | Tutorial 4
Tutorial 5 | Tutorial 6 | Tutorial 7 | Tutorial 8 | Tutorial 9 | Tutorial 10
DHTML: Tutorial 1 | Tutorial 2 | Tutorial 3 | Tutorial 4 | Tutorial 5

*Reference:  HTML Tags, Properties | Appendix D:Web Pages and HTML icon
JavaScript Objects, Properties, Methods, Event Handlers
Appendix E:  JavaScript Operators, Elements, Keywords
Appendix F:  Cascading Style Sheets

To the top

*
Website design by SKDesigns.Course Technology © 2000*
*