How to get box-shadow on left & right sides only
To get a shadow on the left and right sides only, use the box-shadow
CSS property. Apply negative offsets for the left shadow and positive offsets for the right, with large spreads and no vertical offset.
Tweak RGBA values for custom color and opacity, and pixels for adjusting the shadow's spread and intensity.
Hacks for target precision
Multiple shadows for clean edges
To avoid the unintended top and bottom shadows, you can apply extra box-shadow
layers with negative spreads that eat away the undesired part, like a code-ninja 🐱💻:
This assures clean edges by matching the background color with the shadow color, basically the shadow is hiding in plain sight! 😎
Pseudo-elements for shadow isolation
Using the ::before
and ::after
pseudo-elements can give you an extra level of control over your shadows, it's like having shadow mini-me(s)! 👥:
Clip-path for shadow molding
The clip-path
property shapes up our shadow like a barber trimming hair. It cuts off unwanted parts while also being able to give a unique silhouette.
Leveling up with shadows
Cross-browser harmony
Your shadow might not look the same across various browsers. So, make sure your chosen shadow calibrates well with your design objectives and withstands the acid tests of browser compatibility.
Image-based solutions: The dark side
While they might serve a purpose, they turn out to be the slow turtles of the web. Stick to CSS solutions for snappy, adaptable, and hi-perf results.
Experiment. Fail. Learn.Repeat
Stay creative. Discover extraordinary designs through tinkering with values and methods. A daring departure can sometimes beget the most stunning visual results!
Was this article helpful?