Creating a CSS3 box-shadow on all sides but one
To create a box-shadow on all sides except one, tweak the shadow offsets and spread radius. Here's a concise CSS snippet for creating a shadow on all sides, excluding the top:
The horizontal offset (0
) and the negative spread (-5px
) essentially nullify the top shadow. Control the opacity of the shadow using the RGBA alpha value.
The anatomy of box-shadow
Playing with negative spread
You could utilize a negative spread radius to contract the shadow towards the box hence removing the shadow from a specific side:
Shadows that respect personal space
Via :before
or :after
pseudo-elements, you can add shadows without messing up your layout. Style up your shadow without touching the element's content:
Juggling shadows with tabs
With tabs, we can apply the box-shadow to each tab individually, and make the active tab shadow-less by using overflow: hidden
on the tab container:
Leveling up your shadow game
Crafting shadows with clip-path
The clip-path
property allows you to shape your shadow specifically. Use inset()
without commas for precision, but remember to check the browser's compatibility:
Shadow positioning with pseudo-elements
Through absolute
positioning of pseudo-elements, you can influence a very specific shadow effect. Customize their size to control the area of the desired shadow:
Outsmarting dynamic interactions
Hovering on the edge of shadow
Incorporate dynamic shadows for interactive elements. Add shadow to an element upon interaction with the :hover
selector:
Avoiding content overlapping
Prevent the shadow from overlapping active content. Adjust the height of your content area as needed:
Misplace a shadow? Use margins, paddings
To fine-tune your shadow placements utilize margin
and padding
properties. Especially handy when styling navigation bars or tabbed interfaces:
Was this article helpful?