Page is a not externally linkable
SuzyUK - 11:03 am on Sep 13, 2004 (gmt 0)
2. Shorthand Properties continued.. Background Shorthand background {<background-color> <background-image> <background-repeat> <background-attachment> <background-position>;} the individual properties are not seperated by commas, all parts are optional and can be used in any order but if one or more of the choices are not declared they are still understood to be there and each "unset" property will be assumed to have been set (implicitly set) to the individual default instead. Example: is the equivalent of: Example 2: is the equivalent of: Note: setting a If you only require to override one part of a setting the has been set using shorthand earlier in the cascade you should use the long hand backgrund property as this will only affect that particular property. Example: p.repeat {background-repeat: repeat;} <p class="repeat">this now has a repeating background image</p> The p with the class of repeat will still be take on the properties specified in the first rule and the second rule just targets the background-repeat property. Note: Quotes around Note: the path to a normally this needs 2 x values set and these can be percentages, lengths or keywords. The default when no values are set is 0% 0% which equates to top left of the element. e.g. the percentage and length values are applied in the order: the keywords ~ the two values have three choices: if one value only is given: keywords You can use combinations of keyword, length and percentage values Note: when using combinations of keyword and non-keyword values, 'left' and 'right' can only be used as the first value, and 'top' and 'bottom' can only be used as the second value, keeping the {x, y} order in place as required by the length / percentage values. ... more to follow ....
Tips 'n'Tricks: Part 4
p {
background: #fff url(mybgimage.gif) no-repeat fixed 0% 50%;
}
p {
background-color: #fff;
background-image: url(mybgimage.gif);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 0% 50%;
}
p {
background: url{mybgimage.gif);
}
p {
background-color: transparent;
background-image: url(mybgimage.gif);
background-repeat: repeat;
background-attachment: scroll;
background-position: 0% 0%;
} background using a shorthand property later in the cascade will override more explicit settings from earlier on. e.g. the second example if used after the first will reset values (back to default) from the first even though they're not declared.
p {
background: #fff url(mybgimage.gif) no-repeat fixed 0% 50%;
} background-image names should not be used, they are not required and older browsers will choke (especially on single quotes) background-image should be relative to your stylesheet, watch this while testing with an embedded stylesheet then transferring the CSS to an external file within it's own folder. Relative paths within the stylesheet may need to adjusted or it may be better to use absolute paths depending on your site structure. background-position
background-position: 50% 50%;
background-position: 14px 54px;
background-position: top center;
horizontal(x) ~ from the left,
vertical(y) ~ from the top
<top ¦ center ¦ bottom> <left ¦ center ¦ right>
~ can be applied in any order. e. g.
top left = left top
percentages and lengths will take it that the horizontal (from the left) position has been set and the vertical (from the top) will default to 50% (note: not the 0% original default!)
if either top, right, bottom, left, center is set the other will default to center (again not the 0% original).
Examples: {50% 20px} or {center 20px} or {center 10%}.
Brought to you by WebmasterWorld: http://www.webmasterworld.com