element.Still with me? Excellent. Let’s focus on another useful CSS shorthand property: individual borders.Border-top, border-right, border-bottom and border-left shorthand propertyThe syntax for this shorthand property is:[code] border-top: border-width | border-style | color; border-right: border-width | border-style | color; border-bottom: border-width | border-style | color; border-left: border-width | border-style | color;[/code]These properties work identically to those defined for \"border.\" However, the \"border\" property itself is not capable of discerning between the four sides of an element. These are specifically aimed to let you set a style to a specific border.Take a look at the following examples:[code] p { border-top: 1px solid red; } p { border-right: solid blue; } p { border-bottom: 1px dotted red; } p { border-left: 2px solid #ffc; }[/code]The first case will display a solid red line of 1px for the \"border-top\" of the
element.The second case will show a solid blue line for the \"border-right\" of the element.The third and fourth examples will display a
element with a red dotted line of 1px for the \"border-bottom,\" and a 2px yellow solid line for the \"border-left\" of the paragraph, respectively.For the next section, we’ll see another handy shorthand property: list-style.The syntax for the \"list-style\" shorthand property is described below:[code]list-style: | list-style-type | list-style-position | list-style-image;[/code]This shorthand property comes in very handy when we’re styling lists, since they’re commonly used to display content in an appealing fashion. Available types for \"list-style-types\" are circle, disc and square.The \"list-style-position\" property sets whether the list marker (bullet or number) is placed inside or outside the box outlined by the list item text. Another way to look at this property is that a setting of \"inside\" causes the text to wrap to the beginning of the line, whereas a setting of \"outside\" causes the text to wrap to the first character after the list marker on the first line.Finally, the \"list-style-image\" property allows us to define a URL for an image that is to be used for the bullets in a list, or for a particular list item. A setting of \"none\" for a particular list item specifies that the default bullet should be used instead of an image, and can override an image specified for the list as a whole.Let’s see an example for this shorthand property:[code] ul { list-style: square inside url("sqr.gif"); }[/code]In this case, we’re defining an unordered list element to have an image to display list items (\"sqr.gif\"). If it’s not available, then a square bullet will be used instead, which is placed inside the box outlined by the list item text.And that’s all for now. We’ve taken a quick look at the most used CSS shorthand properties, learning a little more about the power of CSS and its properties. Of course, there are many other shortcuts to define styles, but poor or even nonexistent browser support for them makes them impractical for use in websites.SummaryAs we can see, CSS shorthand properties are really easy to implement. In many cases, they’re faster and more efficient to use than standard CSS, making our code a lot tighter and concise. However, we should be aware of browser support, which usually varies significantly. Just make sure you have at hand a good CSS reference that includes information about browser compatibility for every feature discussed. It might be a straight and simple solution for most of your CSS related problems.About The Author:Alejandro Gervasio is a senior system analyst, mainly oriented to PHP programming and client-side technologies. Also, he currently is an active technical writer for Developershed.[url=\"http://www.devarticles.com/c/a/Web-Style-Sheets/CSS-shorthand-at-a-glance/\"]source[/url]
Statistics: Posted by Tami — Wed Feb 09, 2005 9:31 am