How to Create a Left and Right Only Box-Shadow in CSS?

Patricia Arquette
Release: 2024-11-28 03:55:19
Original
868 people have browsed it

How to Create a Left and Right Only Box-Shadow in CSS?

How to Apply Box-Shadow to Only the Left and Right Sides

To achieve a box-shadow effect on only the left and right sides without using hacks or images, you can take advantage of multiple box-shadows to simulate the desired result. Here's how:

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 code creates two box-shadows: one for the left side (-12px offset) and one for the right side (12px offset). The negative offset for the left shadow and the use of -4px pushes the shadow inward, ensuring it only appears on the left and right edges.

Note: As the provided solution involves "masking" to hide the shadow from other sides, consider exploring alternative approaches, such as the one suggested by @Hamish in the reference answer, which offers a more robust solution without masking.

To enhance the effect further, you can add additional box-shadows to mask out any shadow that may still bleed through on the top and bottom:

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 code effectively masks out the shadow on the top and bottom, providing a more polished and desired effect.

The above is the detailed content of How to Create a Left and Right Only Box-Shadow in CSS?. 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