GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing developer.mozilla.org — Shorthand properties - CSS | MDN Shorthand propertiesShorthand properties are CSS properties that let you set the values of multiple other CSS properties in one declaration. Using a shorthand property, you can write more concise (and often more readable) style sheets, saving time and energy. The CSS specification defines shorthand properties to group the definition of common properties acting on the same theme. For example, the CSS Tricky edge casesThere are a few edge cases to keep in mind when using shorthand properties. Omitting propertiesA value which is not specified is set to a default value defined by the shorthand, which may differ from the property's initial value. That means that it overrides previously set values. For example: css This will not set the color of the background to Only the individual properties values can inherit. As missing values are replaced by their initial value, it is impossible to allow inheritance of individual properties by omitting them. The keyword Ordering propertiesShorthand properties try not to force a specific order for the values of the properties they replace. This works well when these properties use values of different types, as the order has no importance, but this does not work as easily when several properties can have identical values. Two important cases here are:
Sides of the boxShorthands handling properties related to the sides of the box, like
Corners of the boxSimilarly, shorthands handling properties related to the corners of the box, like
Background propertiesConsider a background with the following properties css These four declarations can be shortened to just one: css (The shorthand form is actually the equivalent of the longhand properties above plus See Font propertiesConsider the following declarations: css These 5 statements can be shortened to the following: css This shorthand declaration is actually equivalent to the longhand declarations above plus Border propertiesWith borders, the width, color, and style can be simplified into one declaration. For example, consider the following CSS: css It can be simplified as: css Margin and padding propertiesShorthand versions of margin and padding values work similarly; the margin property allows for shorthand values to be specified using one, two, three, or four values. Consider the following CSS declarations: css They are the same as the following declaration using the four value shorthand. Note that the values are in clockwise order, beginning at the top: top, right, bottom, then left (TRBL, the consonants in "trouble"). css Margin shorthand rules for one, two, three and four value declarations are:
Position propertiesWith position, the shorthand versions of top, right, bottom and left can be simplified into one declaration. For example, consider the following CSS: css It can be simplified as: css Just like margins and paddings, the inset values are ordered clockwise - top, right, bottom, then left (TRBL). The universal shorthand propertyCSS provides a universal shorthand property, See Handling conflicts or Introducing the CSS Cascade for more information about how inheritance works in CSS. Shorthand properties
See also
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |