One side shadow in CSS3

As You may suppose, there isn’t a standard way to set the box shadow for only one side of the box or leave one side of the element without a shadow. But You can reach it by using simple CSS tricks. Here You can analyze two examples.

In the first example, we will set box-shadow for only one side of the box.

In the second sample, only one side of the element will be without a shadow.

I hope everybody will understand this CSS so I won’t provide any other description. More code, less water)

Let’s start:

One side shadow

<div></div>
div {
  margin: 30px;
  height: 100px;
  width: 100px;
  position: relative;
  overflow: hidden;
  padding: 0 7px 0 0;
}
div:before {
  position: absolute; 
  content: ' '; 
  top: 0px; 
  right: 7px; 
  bottom: 0;
  left: 0; 
  background-color: transparent; 
  box-shadow: 0 0 5px black;
  border: 1px solid red;
}

One side without shadow

<div></div>
div {
  margin: 30px;
  height: 100px;
  width: 100px;
  position:relative;
  overflow: hidden;
  padding: 7px 7px 0 7px;
}
div:before {
  position: absolute; 
  content: ' '; 
  top: 7px; 
  right: 7px; 
  bottom: -7px;
  left: 7px; 
  background-color: transparent; 
  box-shadow: 0 0 5px black;
  border: 1px solid red;
}

6 Responses to “One side shadow in CSS3”

Leave a Reply