You do not have to draw a border on all four sides. Each side has its own property: border-top, border-right, border-bottom and border-left.
<style>
h2 { border-bottom: 3px solid #d94a00; padding-bottom: 6px; }
.quote { border-left: 5px solid #1a5276; padding-left: 14px; color: #444; }
.row { border-top: 1px solid #ddd; padding: 8px 0; }
</style>
<h2>Heading with an underline</h2>
<p class="quote">A quote with a colored bar on the left side.</p>
<div class="row">First row</div>
<div class="row">Second row</div>
Common patterns
- Heading underline:
border-bottom. - Quote or note bar:
border-leftwith somepadding-left. - Dividers between list items:
border-topon every item, orborder-bottomon all but the last. - Active tab marker: a thick
border-bottomin the brand color.
Longhands for exact control
Each side also has width, style and color properties: border-bottom-width, border-left-color and so on. You can combine a general rule with an exception:
.card {
border: 1px solid #ddd;
border-top: 4px solid #d94a00;
}
Order matters here. The border-top line comes after border, so it replaces the top side only.
Putting the shorthand last
border: 1px solid #ddd; comes after border-top: 4px ..., it resets all four sides and your thick top border disappears. Write the general rule first and the exceptions after it.