Outline on only one border
To float a single-side outline, harness the power of ::before
or ::after
pseudo-elements in CSS. Below is a lean code snippet for a right-side outline:
Position your outline to your desired side by adjusting the top
, bottom
, or both width
and height
values.
box-shadow: the border's secret agent
At times, you may find the border
property a tad stiff. Enter the box-shadow
, a more dexterous substitute. Watch it put on an impressive performance of a single-side outline with the use of inset
keyword and some stacked shadows:
There's no need to dread shadows, they won't bite into your box model size, which means you can add or subtract outlines to your heart's content without any layout disruptions.
Pseudo-elements, assemble!
Pseudo-elements can do more than just "appear" on the scene. The ::before
pseudo-element can create a custom top border:
Don't forget to make room for the ::before
or ::after
elements to strut their stuff at the block-level stage.
Padding and colors: best friends of your borders
Increase the appeal of your borders with thoughtful adjustments of padding
and background
. You can also streamline color management with variables in CSS preprocessors such as Sass or Less.
Your border's journey to exceptionality
The 3D flirt
Tweak box-shadow
spreads and colors to create a realistic 3D illusion:
The power of focus
You're never fully dressed without a :focus
style:
Embrace the transparency
Do the unexpected: paint your borders transparent
, and let outlines take center stage:
Testing, testing… 1, 2, 3
Always ensure your cross-browser compatibility. After all, a border enjoyed by all is a border well made.
Was this article helpful?