Shadows on sides css

CSS box-shadow Property

The box-shadow property attaches one or more shadows to an element.

Default value: none
Inherited: no
Animatable: yes. Read about animatable Try it
Version: CSS3
JavaScript syntax: object.style.boxShadow=»10px 20px 30px blue» Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Numbers followed by -webkit- or -moz- specify the first version that worked with a prefix.

CSS Syntax

Note: To attach more than one shadow to an element, add a comma-separated list of shadows (see «Try it Yourself» example below).

Property Values

Value Description Demo
none Default value. No shadow is displayed Demo ❯
h-offset Required. The horizontal offset of the shadow. A positive value puts the shadow on the right side of the box, a negative value puts the shadow on the left side of the box Demo ❯
v-offset Required. The vertical offset of the shadow. A positive value puts the shadow below the box, a negative value puts the shadow above the box Demo ❯
blur Optional. The blur radius. The higher the number, the more blurred the shadow will be Demo ❯
spread Optional. The spread radius. A positive value increases the size of the shadow, a negative value decreases the size of the shadow Demo ❯
color Optional. The color of the shadow. The default value is the text color. Look at CSS Color Values for a complete list of possible color values.

More Examples

Example

Add a blur effect to the shadow:

Источник

box-shadow

The box-shadow CSS property adds shadow effects around an element’s frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.

Try it

The box-shadow property enables you to cast a drop shadow from the frame of almost any element. If a border-radius is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple text shadows (the first specified shadow is on top).

Box-shadow generator is an interactive tool allowing you to generate a box-shadow .

Syntax

/* Keyword values */ box-shadow: none; /* offset-x | offset-y | color */ box-shadow: 60px -16px teal; /* offset-x | offset-y | blur-radius | color */ box-shadow: 10px 5px 5px black; /* offset-x | offset-y | blur-radius | spread-radius | color */ box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2); /* inset | offset-x | offset-y | color */ box-shadow: inset 5em 1em gold; /* Any number of shadows, separated by commas */ box-shadow: 3px 3px red, -1em 0 0.4em olive; /* Global values */ box-shadow: inherit; box-shadow: initial; box-shadow: revert; box-shadow: revert-layer; box-shadow: unset; 

Specify a single box-shadow using:

To specify multiple shadows, provide a comma-separated list of shadows.

Values

If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content). The presence of the inset keyword changes the shadow to one inside the frame (as if the content was debossed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content.

If both and are set to 0 , the shadow is placed behind the element (and may generate a blur effect if and/or is set).

…for a long, straight shadow edge, this should create a color transition the length of the blur distance that is perpendicular to and centered on the shadow’s edge, and that ranges from the full shadow color at the radius endpoint inside the shadow to fully transparent at the endpoint outside it.

Interpolation

When animating shadows, such as when multiple shadow values on a box transition to new values on hover, the values are interpolated. Interpolation determines intermediate values of properties, such as the blur radius, spread radius, and color, as shadows transition. For each shadow in a list of shadows, the color, x, y, blur, and spread transition; the color as , and the other values as s.

In interpolating multiple shadows between two comma-separated lists of multiple box shadows, the shadows are paired, in order, with interpolation occurring between paired shadows. If the lists of shadows have different lengths, then the shorter list is padded at the end with shadows whose color is transparent , and X, Y, and blur are 0 , with the inset, or lack of inset, being set to match. If, in any pair of shadows, one has inset set and the other is does not, the entire shadow list is uninterpolated; the shadows will change to the new values without an animating effect.

Formal definition

Initial value none
Applies to all elements. It also applies to ::first-letter .
Inherited no
Computed value any length made absolute; any specified color computed; otherwise as specified
Animation type a shadow list

Formal syntax

Examples

Setting three shadows

In this example, we include three shadows: an inset shadow, a regular drop shadow, and a 2px shadow that creates a border effect (we could have used an outline instead for that third shadow).

HTML

blockquote> q> You may shoot me with your words,br /> You may cut me with your eyes,br /> You may kill me with your hatefulness,br /> But still, like air, I'll rise. q> p> Maya Angeloup> blockquote> 

CSS

blockquote  padding: 20px; box-shadow: inset 0 -3em 3em rgba(0, 0, 0, 0.1), 0 0 0 2px rgb(255, 255, 255), 0.3em 0.3em 1em rgba(0, 0, 0, 0.3); > 

Result

Setting zero for offset and blur

When the x-offset , y-offset , and blur are all zero, the box shadow will be a solid-colored outline of equal-size on all sides. The shadows are drawn back to front, so the first shadow sits on top of subsequent shadows. When the border-radius is set to 0, as is the default, the corners of the shadow will be, well, corners. Had we put in a border-radius of any other value, the corners would have been rounded.

We added a margin the size of the widest box-shadow to ensure the shadow doesn’t overlap adjacent elements or go beyond the border of the containing box. A box-shadow does not impact box model dimensions.

HTML

CSS

p  box-shadow: 0 0 0 2em #f4aab9, 0 0 0 4em #66ccff; margin: 4em; padding: 1em; > 

Result

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

How to Set a Box-Shadow Only on the Left and Right Sides

If you want to add a box-shadow only on the left and right sides of an element, we suggest you consider some methods presented in our snippet.

Probably, the best way is using the CSS box-shadow property with the “inset” value. Also, use the :before and :after pseudo-elements, which are absolutely positioned on the right and left sides of the element.

Example of adding a box-shadow on the left and right sides with the :before and :after pseudo-elements:

html> html> head> title>Title of the document title> style> div:before < box-shadow: -20px 0 20px -20px #001f9c inset; content: " "; height: 100%; left: -20px; position: absolute; top: 0; width: 20px; > div:after < box-shadow: 20px 0 20px -20px #001f9c inset; content: " "; height: 100%; position: absolute; top: 0; right: -20px; width: 20px; > div < background: none repeat scroll 0 0 #f0f1f5; height: 120px; margin: 30px; position: relative; width: 120px; > style> head> body> div> div> body> html>

Result

Let’s see another example without the :before and :after pseudo-elements.

Example of adding a box-shadow on the left and right sides:

html> html> head> title>Title of the document title> style> div < box-shadow: 12px 0 15px -4px rgba(0, 55, 162, 0.97), -12px 0 8px -4px rgba(0, 55, 162, 0.97); width: 120px; height: 120px; margin: 30px; background: #f0f1f5; > style> head> body> div> div> body> html>

Note, that in the example above, we also have a little shadow on the top and bottom of the element. But you can add two more box-shadows to the top and bottom to mask the visible top and bottom shadows.

Example of setting a box-shadow on the left and right sides without any shadow on top and bottom:

html> html> head> title>Title of the document title> style> div < box-shadow: 0 9px 0px 0px #f0f1f5, 0 -9px 0px 0px #f0f1f5, 12px 0 15px -4px rgba(0, 55, 162, 0.97), -12px 0 15px -4px rgba(0, 55, 162, 0.97); width: 120px; height: 120px; margin: 30px; background: #f0f1f5; > style> head> body> div> div> body> html>

Источник

How to Set a Box-Shadow on One Side of the Element

To set a box-shadow on one side of the element, use the box-shadow property. This property has four length parameters and a color.

Using the box-shadow property follow this syntax:

box-shadow: h-offset v-offset blur spread color;

h-offset sets the shadow horizontally. A positive value sets the right shadow, and a negative value sets the left one.

v-shadow sets the shadow vertically. A positive value sets the shadow below the box, and a negative value sets the shadow above the box.

blur is an optional attribute, which blurs the box-shadow.

spread sets the shadow size.

color is an optional attribute that sets the shadow color.

Let’s start by creating a shadow on the left side of the element. Follow the steps below.

Create HTML

html> html> head> title>Title of the document title> head> body> h1>W3Docs h1> body> html>

Add CSS

  • Style the element using the text-align, background, padding-top, color, width and height properties.
  • Add the box-shadow property following the syntax mentioned above.
h1 < text-align: center; background: #c4c4c4; padding-top: 50px; color: #000000; width: 400px; height: 120px; box-shadow: -8px 0px 8px #000000; >

Example of adding a box-shadow on the left side of the element:

html> html> head> title>Title of the document title> style> h1 < text-align: center; background: #c4c4c4; padding-top: 50px; color: #000000; width: 400px; height: 120px; box-shadow: -8px 0px 8px #000000; > style> head> body> h1>W3Docs h1> body> html>

Result

Example of adding a box-shadow on the bottom of the element:

html> html> head> title>Title of the document title> style> h1 < text-align: center; background: #c4c4c4; padding-top: 50px; color: #000000; width: 400px; height: 120px; box-shadow: 0 10px 10px #000000; > style> head> body> h1>W3Docs h1> body> html>

When adding a box-shadow only on one side of an element, the focus must be on the last value (the spread radius). It decreases the overall size of the box-shadow, both horizontally and vertically.

Now, we’ll show another example where we use the «inset» value to create a shadow inside the box as the shadow is placed outside the box by default.

Example of adding a box-shadow inside the element:

html> html> head> title>Title of the document title> style> h1 < text-align: center; background: #c4c4c4; padding-top: 50px; color: #000000; width: 400px; height: 120px; box-shadow: 0px 10px 20px #000000 inset; > style> head> body> h1>W3Docs h1> body> html>

In our last example, we use both outside and inside shadows on one side of each presented element.

Example of adding outside and inside shadows:

html> html> head> title>Title of the document title> style> body < background: #ccc; padding: 20px; > .left < float: left; margin-left: 20px; > .box < width: 110px; height: 110px; background: #fff; color: #9e9e9e; margin: 0 auto; margin-bottom: 20px; text-align: center; line-height: 100px; > .shadow-bottom < box-shadow: 0 8px 10px -6px #000000; > .shadow-top < box-shadow: 0 -8px 10px -6px #000000; > .shadow-left < box-shadow: -8px 0 10px -6px #000000; > .shadow-right < box-shadow: 8px 0 10px -6px #000000; > .inner-shadow-bottom < box-shadow: inset 0 8px 10px -6px #000000; > .inner-shadow-top < box-shadow: inset 0 -8px 10px -6px #000000; > .inner-shadow-left < box-shadow: inset 8px 0 10px -6px #000000; > .inner-shadow-right < box-shadow: inset -8px 0 10px -6px #000000; > style> head> body> div class="left"> div class="shadow-bottom box">bottom div> div class="shadow-top box">top div> div class="shadow-left box">left div> div class="shadow-right box">right div> div> div class="left"> div class="inner-shadow-bottom box">top inset div> div class="inner-shadow-top box">bottom inset div> div class="inner-shadow-left box">left inset div> div class="inner-shadow-right box">right inset div> div> body> html>

Источник

Читайте также:  Javascript return new window
Оцените статью