Web Design Stuff
HTML Tutorials    CSS Tutorials    Web Hosting   Resources
Create a Web Page 101
Making Web Pages Intro What is a Web Page? Why Make a Web Page? The History of HTML Learn HTML or XHTML?
Basic HTML
Basic HTML Tutorials Basic HTML Necessities How to Make a Web Page How to Edit a Web Page The Basics of HTML Tags Basic HTML Page Structure HTML Attributes
HTML Font Codes
HTML Font Codes Intro HTML Font Color Codes HTML Font Size Codes HTML Font Style Codes HTML Bold/Italic Codes Combining Font Codes
Formatting Text
Formatting Text Intro Making Paragraphs Miscellaneous Formatting Headings & Subheadings Creating Hyperlinks
Using Graphics
Using Graphics on the Web Add Graphics to Your Pages Graphics and Accessibility How to Align Graphics Page Color & Background Graphics as Hyperlinks Horizontal Rules
Creating Tables
HTML Tables Tutorials HTML Table Fundamentals Background & Border Color Table Frames & Rules Table Width and Alignment Cells 1 -Space & Alignment Cells 2 -Row Column Span Cells 3 -Width & Height
Making Lists
HTML Lists Tutorials Bulleted Lists Numbered Lists Definition Lists
HTML Frames
HTML Frames Tutorials Using Frames for Layout Advanced Frame Layouts Putting Hyperlinks in Frames Frame Border Width Color, Margin and Control Problems with Frames SmartFrames: A Solution SSI: An Alternative to Frames
Web Page Forms
Making Feedback Forms A Simple Feedback Form Installing NMS FormMail Debugging Your Setup My Web Host is Out to Lunch User Input Components Text Fields Checkboxes & Radio Buttons Dropdown Menus Push Buttons Layout and Presentation
Basic CSS
Basic CSS Tutorials What is CSS? Why You Should Use CSS How to Use CSS Inline Styles Embedded Style Sheets External Style Sheets Class Selectors ID Selectors Combining Selectors
CSS Properties
CSS Properties Intro Font Styles Width, Height & Spacing Borders Backgrounds Position Float & Alignment Hyperlinks
All About Web Hosting
Hosting Your Own Website What is a Web Host? Your Website's Home Page Building a Website Offline About Free Web Hosting Best Free Web Hosting Commercial Web Hosting How to Get a Domain Name Ecommerce Web Hosting Web Hosting Terminology
Free Web Design Tools
Best Free Website Tools Best Free Text Editors Best Free Graphics Editors Free Website Analysis Tools
Setting Up HTML Kit
HTML Kit Introduction How to install HTML Kit Screenshot Breakdown Basic Configuration Overall Appearance Shortcuts and Startup Editing Window Customizing Toolbars Using the Favorites Tab Making a New Actions Bar Odds and Ends
Free Templates
Free Website Templates Two Column Fixed Width Three Column Liquid Layout Miscellaneous Templates Dynamic Menu Effects Two Column Experimental Terms of Use About These Templates
Website Templates Help
Getting Started Template Zip File Download How to Edit Your Template What to Edit in the HTML How to Add Your Logo Making a Website
Web Design Tips
Web Design Basics Tables vs. Tableless Using Tables for Layout Example Table Layouts World's Crappiest Web Page
Twitter Backgrounds
Twitter Backgrounds Intro Cool Twitter Backgrounds Cool Twitter Backgrounds 2 Plain Twitter Backgrounds Dark Twitter Backgrounds Best Twitter Backgrounds Cute Twitter Backgrounds Music Twitter Backgrounds Music Twitter Backgrounds 2 Twitter Backgrounds 101 TERMS OF USE
All About Web Browsers
What is a Web Browser? Mozilla Firefox Internet Explorer Opera How to Set Up Firefox Top 5 Firefox Extensions
 
Contact
Post Some Feedback Send Me An Email Iron Spider Blog About Iron Spider... Site Conventions
 
 
 

 

CSS Properties - Backgrounds

 
The CSS properties in the table below can be used to define background colors and images on various components on your web page. These properties are typically applied to block elements but you can also apply them to some form elements. These include the following:

body, p, div, blockquote, table, td, ul, ol, li, form, input, textarea, select,


CSS Properties List 4 - Backgrounds
Property NameSome Possible ValuesWhat It Does
background(All background properties at once)Sets background
background-color(Any color)Background color
background-imageurl('example.jpg')Background image
background-repeatrepeat-x | repeat-y | no-repeatTile background?
background-positiontop left | 50% 100%Position?
background-attachmentfixed | scrollFixed or scroll?


NOTES:
  • Background ~ This is CSS shorthand property that allows you to set five different background related properties at once. The shorthand syntax for background is written as follows:

    background: color image repeat position attachment;

    In the above:

    1. color = Any named color or hexadecimal color code.
      Possible values: red | green | navy | #ffffcc | #000000
    2. image = Path to any background image file.
      Syntax example: url("background.jpg")
    3. repeat = A value that defines how the background image is repeated.
      Possible values: repeat-x | repeat-y | no-repeat
    4. position = A pair of values that set the background image's position.
      Possible values: left top | center center | right bottom
    5. attachment = Any value(s) applicable to background-attachment.
      Possible values: fixed | scroll
    Hence, the background property is declared and then followed by a space-separated list of values pertaining to any one or more of the above.

    Here's an example:

    background: orange url("test.jpg") no-repeat center center fixed;

    In the above example, the background color is orange and the background image is 'test.jpg'. The background image is only displayed once in the center of the web page and is fixed in place such that when the user scrolls, it always remains within the browser viewport.

    All the values set using the background shorthand property can be set individually using the following CSS properties:

    • Background-color ~ This CSS property defines the background color. Any named color or hexadecimal color code may be used, e.g., red, green, blue, #ffffcc, etc. (Please see font color for more about what colors you can use for any HTML or CSS code.)

      Example: background-color: silver;
    • Background-image ~ This CSS property defines the background image. The syntax to use is url("path to any image file") where path to any image file equals any relative or absolute path to the image file you wish to display as a background.

      Examples:

      background-image: url("mycoolpic.gif");
      background-image: url("pics/mycoolpic.gif");
      background-image: url("http://www.example.com/mycoolpic.gif");
    • Background-repeat ~ By default, background images (when declared) are repeated horizontally and vertically until the entire element is filled. You can use the background-repeat property to control this behaviour. The value can be any one of the following:

      • repeat-x - The background image is only repeated horizontally.
      • repeat-y - The background image is only repeated vertically.
      • no-repeat - The background image is only displayed once.
      Example: background-repeat: repeat-x;
    • Background-position ~ If a background image is declared and it is set to repeat only horizontally or vertically or not at all (see background-repeat) then you can use background-position to define exactly where the background image is displayed on your web page.

      Typically, two values are used — the first defining the horizontal position and the second defining the vertical position. Some of the values you may use are named positions, percentages or pixels (px).

      NAMED POSITIONS

      Named positions for horizontal positioning are: left | center | right
      Named positions for vertical positioning are: top | center | bottom


      PERCENTAGES AND PIXELS

      When using percentages or pixels, the first value defines the horizontal distance from the left border while the second value defines the vertical distance from the top border.

      Examples:

      background-position: 0% 50%;
      (The background image is displayed flush with the left border and in the vertical center.)

      background-position: 50% 100%;
      (The background image is displayed in the horizontal center and flush with the bottom border.)

      background-position: 20px 40px;
      (The background image is displayed 20 pixels from the left border and 40 pixels from the top border.)

      background-position: right bottom;
      (The background image is displayed in the bottom right corner.)

    • Background-attachment ~ If you're starting to become concerned about cross-browser compatibility and you've discovered that using bgproperties="fixed" in the <body> tag doesn't work in Firefox (or any Gecko-based browser for that matter) then here comes the CSS property background-attachment to the rescue. This can be used to make the background image remain fixed in place while the rest of the web page content scrolls over it.

      Possible values are: fixed | scroll

      Example:

      <body style="background-attachment: fixed;"   background="example.jpg">
MORE EXAMPLES:

Below is an example of an inline style applied to a paragraph tag using background shorthand property described above (height and padding are also defined for demonstrational purposes):


Example 1 - INLINE STYLE

<p style='background: orange url("sunset.jpg") no-repeat 0px 20px; height: 100px; padding: 20px;'>It was a beautiful sunset...</p>


Note that in the inline style above, we're obliged to nest one set of quotation marks within another to declare the path to the background image within the style attribute. If we used double quotation marks for both style="..." and url("..."), the web page would get messed up because the style attribute would end prematurely. Hence we'll opt to use single quotation marks for the style attribute [ style=' ' ] and double quotation marks for the path to the background image [ url(" ") ].

The same inline style above could be declared as an embedded stylesheet in the document head:


Example 2 - EMBEDDED STYLE SHEET

<style type="text/css">
<!--
p {
   background: orange url("sunset.jpg") no-repeat 0px 20px;
   height: 100px;
   padding: 20px;

}
-->
</style>



...and in the document body, you would simply put this:


<p>It was a beautiful sunset...</p>



Both Example 1 and Example 2 will produce the following effect:

It was a beautiful sunset...

And the lowdown on what's happening here is:
  • The height of the paragraph is 100 pixels.
  • The padding on all sides of the paragraph is 20 pixels.
  • The background color is orange.
  • The background image is "sunset.jpg" and is:
    • Not repeated (only displayed once).
    • Set flush with the left border (0 pixels).
    • Set 20 pixels from the top border.

*   *   *


Next we'll cover how to apply relative and absolute positioning to your web page elements...





Best Free Stuff
for webmasters

Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates

See also:

Best Free Web Hosting
How to Make a Web Page

 

If you need a .COM web address, you can get one quick and easy at...

www.GoDaddy.com
<~ BACK TOP NEXT ~>
 
HTML Tutorials |  CSS Tutorials |  Web Hosting |  Domain Names |  Web Design Resources
Iron Spider © Copyright 2004-2011 Robert Darrell