10.07.2017 Views

246996016-HTML5-Step-by-Step

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

132 Chapter 8<br />

To apply the same formatting to an individual instance of a tag, use this:<br />

<br />

Note The default border style is none—and that doesn’t change just because you specify a<br />

border width and color. Don’t forget to turn a border on <strong>by</strong> including the border-style attribute<br />

in addition to specifying the border’s color and width.<br />

Formatting Border Sides Individually<br />

By default, border attributes apply to all four sides of the border unless you specify<br />

otherwise. To specify that a certain side of the border has special formatting, include the<br />

-top, -right, -left, or -bottom argument between the word border and the property being<br />

set. For example, to set a color other than black for the top border using a style sheet,<br />

use the following:<br />

p {border-style: solid; border-top-color: blue}<br />

To apply the same formatting to an individual instance of a tag, use this:<br />

<br />

You can use this technique not only with border-color, but with style, padding, and width<br />

attributes as well. For example, the following rule applies a dotted line and 15 pixels of<br />

padding to only the top and bottom of a paragraph:<br />

<br />

Here’s how the rendered paragraph looks:<br />

There’s a shortcut for specifying arguments for each side of the border. Rather than writing<br />

each one out individually, you can simply include four different settings for the argument.<br />

Specify them in clockwise order, starting at the top: top, right, bottom, left. Using<br />

this method, the example you just saw could be written like this:<br />

<br />

Specifying fewer than four arguments applies the formatting differently. Specifying two<br />

arguments sets the top and bottom border attributes, while specifying three arguments<br />

sets the top, bottom, and left/right (same settings for both) border attributes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!