tags:

views:

445

answers:

7

background:#777777 none repeat scroll 0 0;

the 5 attributes it includes are background-color,background-image,background-repeat,background-attachment and background-position.

But I don't understand what background-attachment and background-position mean?

Can someone give an explanation?

EDIT:are background-repeat,background-attachment and background-position useless if background-image is none?

+1  A: 
drdaeman
+1  A: 

W3Schools has a pretty good explanation of these elements:

background-attachment: determines whether the background is fixed or scrolls with the page.

background-position: determines the position of the background in relation to the page (values like top center, bottom right, pixel values, etc.)

Matthew Jones
+3  A: 

If you've ever seen a web page where the text on the page scrolls with the scrollbar, but the background remains stationary, that's

background-attachment: fixed;

Background-position defines how you position the image inside of the background of the element. For instance, if you have a small drop shadow image that should only repeat along the bottom edge of your element, you could use:

background-repeat: repeat-x;
background-position: bottom left;

Or if you had an image you only wanted displayed in the bottom, right hand corner of your element:

background-position: bottom right;

background-position also accepts pixel values in the format:

background-position: xpos ypos

for finer grain control.

Justin Niessner
And to answer the edit in the question: Yes, these two properties do nothing if background-image is not used.
T Pops
+1  A: 

The background-attachment property sets whether a background image is fixed or scrolls with the rest of the page.

  • scroll
    • The background image scrolls with the rest of the page. This is default
  • fixed
    • The background image is fixed
  • inherit
    • Specifies that the setting of the background-attachment property should be inherited from the parent element

The background-position property sets the starting position of a background image.

Note: For this to work in Firefox and Opera, the background-attachment property must be set to "fixed".

PatrikAkerstrand
+1  A: 

The background attachment specifies if the background scrolls along with the webpage.

background-attachment: fixed; would fix the background so even if a user scrolls down the webpage for example, the background wouldn't move.

background-attachment: scroll; would make the background scroll with the page.

More info here: http://www.w3schools.com/Css/pr_background-attachment.asp

The background position takes 2 arguments; the x position and the y position. It specifies where the original background image will start to be displayed. The origin is on the top-left of the container.

More info here: http://www.w3schools.com/css/pr_background-position.asp

Guillaume Flandre
so background position is useless if background-image is none?
Shore
yes, it only applies to background images.
Guillaume Flandre
+1  A: 

From W3 background-attachment

The background-attachment property sets whether a background image is fixed or scrolls with the rest of the page.

Lets say you have a background picture, like here (look at the pretty mountains.)

When the background-attachment property is set to "fixed", then when you scroll the page, the background remains, uh, fixed. The contents of the page scroll, but the background picture does not.

Compare to this page. See the background doodling on the sides? When you scroll down, then those drawings also scroll with the page. This is an example of the "scroll" choice - which is what you have in the CSS snippet you posted.

rascher
background-attachment controls fixed or scrolls with the rest of the page or with the rest of the container?BTW,is this attribute useless if background-image is not specified?
Shore
A: 
background-position: is used to define the anchor point of the image on the screen like top left  or bottom right

background-attachment defines whether the background image will scroll with the contents
Rony
Thanks,I've updated my post.
Shore