Style-Sheets
  Home arrow Style-Sheets arrow Page 5 - Understanding Style Sheets (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE-SHEETS

Understanding Style Sheets (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 25
    2000-10-04


    Table of Contents:
  • Understanding Style Sheets (part 2)
  • Bringing Out The Decorations
  • Gimme My Space!
  • Reclining Every Which Way
  • Above The Watermark
  • Going Shopping
  • The View From The Top
  • The Z-Factor

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Understanding Style Sheets (part 2) - Above The Watermark
    ( Page 5 of 8 )

    CSS also comes with a bunch of properties that allow you to define the manner in which your page background is displayed. First, the "background-image" property allows you to specify a background image for any HTML element.
    .question {background-image: url("http://www.mysite.com/back.gif")} /*
    display 
    background image from url */
    
    If you need this background to work as a watermark, which does not scroll when you scroll down the page, you need the "background-attachment" property - it accepts the values "fixed" and "scroll".

    You can also control whether or not your image tiles across the page with the "background-repeat" property. This property can take one of four values: "repeat" (tile horizontally and vertically), "repeat-x" (tile horizontally only), "repeat-y" (tile vertically only), and "no-repeat" (no tiling).

    The following example demonstrates the "repeat-y" keyword:
    <HTML>
    <HEAD>
    <STYLE TYPE="text/css">
    .question {font-size: 20pt; background-image:
    url("http://www.mysite.com/back.gif"); 
    background-repeat: repeat-y}
    </STYLE>
    </HEAD>
    
    <BODY>
    
    <P CLASS="question">
    Q. 
    How many doctors does it take to change a light bulb?
    A. It depends on what kind 
    of insurance you have
    
    </BODY>
    </HTML>
    
    And you can also specify the location of the background image with the all-powerful "background-position" property, which can be used in combination with the simple keywords "left", "right", "center", "top", "middle" and "bottom". For example, this would position the image in the top right corner:
    <HTML>
    <HEAD>
    <STYLE TYPE="text/css">
    .question {font-size: 20pt; background-image:
    url("http://www.mysite.com/back.gif"); 
    background-position: top right;
    background-repeat: no-repeat}
    </STYLE>
    </HEAD>
    
    <BODY>
    
    <P 
    CLASS="question">
    Q. How many doctors does it take to change a light bulb?
    A. 
    It depends on what kind of insurance you have
    
    </BODY>
    </HTML>
    
    You can also specify the position of the image in terms of percentages or absolute units - for example,

    {background-position: 100%,0%}

    would position the image in the top right corner, while

    {background-position: 100%,100%}

    would position it in the bottom right corner.{mospagebreak title=Padding Things Out} The CSS formatting model assumes that every element is surrounded by three different areas. Starting from the inside out, these areas are padding, border and margin. Each of these entities can be controlled through special CSS properties, allowing developers to precisely adjust the appearance and position of each HTML element.

    Margin widths can be controlled via the "margin-top", "margin-bottom", "margin-right", and "margin-left" properties, and are specified like this:

    DIV {margin-top: 10px; margin-bottom: 10px; margin-right: 5px; margin-left:
    5px} 
    /* 10px width for horizontal margins, 5px width for vertical margins */
    
    You can 
    also use the catch-all "margin" property
    
    DIV {margin: 10px 5px 5px 10px} /* specify 
    widths clockwise */
    
    or set a uniform margin width with
    
    DIV {margin: 10px} /* 
    equal width for all margins  */
    
    You can adjust border widths with the self-explanatory properties "border-top-width", "border-bottom-width","border-left-width", and "border-right-width", or set a uniform border with the shortcut "border-width" property.
    DIV {border-top-width: 50px; border-right-width: 100px;
    border-bottom-width: 
    75px; border-left-width: 125px} /* different width for
    each border */
    
    DIV {border-width: 
    50px} /* equal width for all borders  */
    
    You can also specify border widths with 
    the keywords "thick", "medium",
    "thin" and "none", like this:
    
    DIV {border-top-width: 
    thick; border-right-width: medium;
    border-bottom-width: thin; border-left-width: 
    none}
    
    DIV {border-width: thick}
    
    And finally, padding can be controlled with the...you guessed it!... "padding-top", "padding-bottom", "padding-right", and "padding-left" properties, or the shortcut "padding" property. Try this one out yourself!

    CSS also lets you control the colour of your borders with the "border-color" properties. The following example will demonstrate how this works.
    <HTML>
    <HEAD>
    <STYLE TYPE="text/css">
    .question {border-color: black; 
    border-width: thick}
    </STYLE>
    </HEAD>
    
    <BODY>
    
    <P CLASS="question">
    Q. 
    How many doctors does it take to change a light bulb?
    A. It depends on what kind 
    of insurance you have
    
    </BODY>
    </HTML>
    


     
     
    >>> More Style-Sheets Articles          >>> More By icarus, (c) Melonfire
     

       

    STYLE-SHEETS ARTICLES

    - What is CSS?
    - The Power of CSS
    - Understanding Style Sheets (part 2)
    - Understanding Style Sheets (Part 1)





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT