Results 1 to 6 of 6

Thread: Fixed backgroung

  1. #1
    Join Date
    Nov 2004
    Posts
    10

    Default Fixed backgroung

    This short tutorial will show you how use a fixed background image. With a fixed background, the background image doesn't move as the page is scrolled.


    Place the following code in the head section of you page.(between <head> and </head>)


    Code:


    <style type="text/css">
    body
    {
    background-image:
    url("/images/image.gif");
    background-repeat:
    no-repeat;
    background-attachment:
    fixed
    }
    </style>


    background-image- Sets the image to be used for the background
    backgroud-repeat- Sets the behavior of the background. To repeat the background as needed, change no-repeat to repeat.
    background-attachment- Sets whether a background image is fixed or scrolls with the rest of the page.

    The background image can also be positioned on the page by using the background-position property.

    Code:
    background-position: center
    Other values besides center can be used with background-position.

    top right, center left, bottom center, etc.
    x% y%- Sets the relative postion of the image. The first value is the horizontal position and the second value is the vertical.
    x-pos y-pos- Set the position using pixels. (ex. 200px 300px) The first value is the horizontal position and the second value is the vertical.

  2. #2
    Join Date
    Nov 2004
    Location
    Bryan, TX
    Posts
    14

    Default Re: Fixed backgroung

    Quote Originally Posted by bsproductions
    This short tutorial will show you how use a fixed background image. With a fixed background, the background image doesn't move as the page is scrolled.


    Place the following code in the head section of you page.(between <head> and </head>)


    Code:


    <style type="text/css">
    body
    {
    background-image:
    url("/images/image.gif");
    background-repeat:
    no-repeat;
    background-attachment:
    fixed
    }
    </style>


    background-image- Sets the image to be used for the background
    backgroud-repeat- Sets the behavior of the background. To repeat the background as needed, change no-repeat to repeat.
    background-attachment- Sets whether a background image is fixed or scrolls with the rest of the page.

    The background image can also be positioned on the page by using the background-position property.

    Code:
    background-position: center
    Other values besides center can be used with background-position.

    top right, center left, bottom center, etc.
    x% y%- Sets the relative postion of the image. The first value is the horizontal position and the second value is the vertical.
    x-pos y-pos- Set the position using pixels. (ex. 200px 300px) The first value is the horizontal position and the second value is the vertical.
    An even easier way to do it is like this:

    <body bgproperties="fixed" background="/images/image.jpg">

  3. #3
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default

    Only if you have a small website. Using an external stylesheet is the best way to do it if you have a larger website, because you can change the background on every page of your website by editting a single line in one file. Just put the following code in a file with a .css extension and link to it from every site. You can also summarise the code by putting all the properties into one. The #000 is the background color visitors will see if the background image is too small or doesn't load. You should always define a background color in case a problem occurs (white text on a white background annoys visitors, for some reason). Put the second code into the head section of your HTML file.

    Quote Originally Posted by stylesheet.css
    body {background: url('/images/images.gif') no-repeat fixed #000;}
    Quote Originally Posted by index.html
    <link rel="stylesheet" type="text/css" href="stylesheet.css">

  4. #4
    Join Date
    Nov 2004
    Location
    Bryan, TX
    Posts
    14

    Default

    Quote Originally Posted by Pathoschild
    Only if you have a small website. Using an external stylesheet is the best way to do it if you have a larger website, because you can change the background on every page of your website by editting a single line in one file. Just put the following code in a file with a .css extension and link to it from every site. You can also summarise the code by putting all the properties into one. The #000 is the background color visitors will see if the background image is too small or doesn't load. You should always define a background color in case a problem occurs (white text on a white background annoys visitors, for some reason). Put the second code into the head section of your HTML file.

    Quote Originally Posted by stylesheet.css
    body {background: url('/images/images.gif') no-repeat fixed #000;}
    Quote Originally Posted by index.html
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    I didn't even think about that.... That is a very easy way to do it....

    And the really good thing about it is, you only have to change 1 line of code to change the appearance of all pages that are linked to the stylesheet....

  5. #5
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default

    CSS is beautiful.

  6. #6
    Join Date
    Mar 2005
    Location
    Norfolk
    Posts
    44

    Default

    Pathoschild I definitely think just like you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •