Home > Web Front-end > CSS Tutorial > How Can I Create a Box-Shadow Only on the Horizontal Sides of an Element?

How Can I Create a Box-Shadow Only on the Horizontal Sides of an Element?

Barbara Streisand
Release: 2024-11-28 06:39:10
Original
723 people have browsed it

How Can I Create a Box-Shadow Only on the Horizontal Sides of an Element?

Creating Box-Shadows Solely on Horizontal Sides

To achieve a box-shadow that spans only the left and right (horizontal) sides of an element, consider leveraging multiple box-shadow definitions.

The initial box-shadow property,

box-shadow: 0 0 15px 5px rgba(31, 73, 125, 0.8);
Copy after login

produces a shadow on all sides of the element. To target just the left and right sides, add two separate box-shadows:

box-shadow: 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 8px -4px rgba(31, 73, 125, 0.8);
Copy after login

This will create a shadow that extends 12 pixels to the right and -12 pixels to the left, achieving the desired effect.

You may also encounter a slight bleed-through of the shadow on the top and bottom sides. To mitigate this, add two additional box-shadows to mask out the bleed-through:

box-shadow: 0 9px 0px 0px white, 0 -9px 0px 0px white, 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 15px -4px rgba(31, 73, 125, 0.8);
Copy after login

This updated definition will mask the bleeding and confine the shadow to the left and right sides of the element without the use of hacks or images.

The above is the detailed content of How Can I Create a Box-Shadow Only on the Horizontal Sides of an Element?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template