--- title: Propriedades de taquigrafia slug: Web/CSS/Shorthand_properties tags: - CSS - Guía - Referencia translation_of: Web/CSS/Shorthand_properties ---
Propriedades de taquigrafia são propriedades de CSS que lhe permitem definir simultaneamente os valores de várias outras propriedades de CSS. Ao utilizar uma propriedade de taquigrafia, pode escrever folhas de estilo mais concisas (e muitas vezes mais legíveis), poupando tempo e energia .
The CSS specification defines shorthand properties to group the definition of common properties acting on the same theme. For instance, the CSS {{cssxref("background")}} property is a shorthand property that's able to define the values of {{cssxref("background-color")}}, {{cssxref("background-image")}}, {{cssxref("background-repeat")}}, and {{cssxref("background-position")}}. Similarly, the most common font-related properties can be defined using the shorthand {{cssxref("font")}}, and the different margins around a box can be defined using the {{cssxref("margin")}} shorthand.
Even if they are very convenient to use, there are a few edge cases to keep in mind when using them:
background-color: red; background: url(images/bg.gif) no-repeat left top;will not set the color of the background to
red
but to {{cssxref("background-color")}}'s default, transparent
, as the second rule has precedence.inherit
can be applied to a property, but only as a whole, not as a keyword for one value or another. That means that the only way to make some specific value to be inherited is to use the longhand property with the keyword inherit
.The 1-value syntax: border-width: 1em — The unique value represents all edges |
|
The 2-value syntax: border-width: 1em 2em — The first value represents the vertical, that is top and bottom, edges, the second the horizontal ones, that is the left and right ones. |
|
The 3-value syntax: border-width: 1em 2em 3em — The first value represents the top edge, the second, the horizontal, that is left and right, ones, and the third value the bottom edge |
|
The 4-value syntax: |
The 1-value syntax: border-radius: 1em — The unique value represents all corners |
|
The 2-value syntax: border-radius: 1em 2em — The first value represents the top left and bottom right corner, the second the top right and bottom left ones. |
|
The 3-value syntax: border-radius: 1em 2em 3em — The first value represents the top left corner, the second the top right and bottom left ones, and the third value the bottom right corner |
|
The 4-value syntax: |
A background with the following properties ...
background-color: #000; background-image: url(images/bg.gif); background-repeat: no-repeat; background-position: left top;
... can be shortened to just one declaration:
background: #000 url(images/bg.gif) no-repeat left top;
(The shorthand form is actually the equivalent of the longhand properties above plus background-attachment: scroll
and, in CSS3, some additional properties.)
The following declarations ...
font-style: italic; font-weight: bold; font-size: .8em; line-height: 1.2; font-family: Arial, sans-serif;
... can be shortened to the following:
font: italic bold .8em/1.2 Arial, sans-serif;
This shorthand declaration is actually equivalent to the longhand declarations above plus font-variant: normal
and font-size-adjust: none
(CSS2.0 / CSS3), font-stretch: normal
(CSS3).
With borders, the width, color, and style can be simplified into one declaration. For example, the following CSS ...
border-width: 1px; border-style: solid; border-color: #000;
... can be simplified as:
border: 1px solid #000;
Shorthand versions of margin and padding values work the same way. The following CSS declarations ...
margin-top: 10px; margin-right: 5px; margin-bottom: 10px; margin-left: 5px;
... are the same as the following declaration. Note that the values are in clockwise order, beginning at the top: top, right, bottom, then left (TRBL, the consonants in "trouble").
margin: 10px 5px 10px 5px;