Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Box shadow to half of the div

Tags:

html

css

I want to apply the box shadow to just half of the div. I searched a lot in Google but failed. Here is the code for simple box shadow.

<style type="text/css">
    div{
        width: 200px;
        height: 200px;
        text-align: center;
        background-color: gray;
        margin: auto;
        font-size: 30px;
        box-shadow: 0 100px 5px 5px;
    }
</style>

<div>Sometimes by losing a battle you find a new way to win the war.</div>

Coded:

enter image description here

Required:

enter image description here

Barrels of thanks in advance...

like image 582
Hanzallah Afgan Avatar asked Dec 17 '14 03:12

Hanzallah Afgan


1 Answers

You could apply the box-shadow to its :after :pseudo-element to achieve this.

div {
  width: 200px;
  height: 200px;
  text-align: center;
  background-color: gray;
  margin: auto;
  font-size: 30px;
  position: relative;
}
div:after {
  position: absolute;
  content: '';
  width: 100%;
  height: 50%; /* Half of the original height */
  top: 0;
  left:0;
  box-shadow: 0 100px 5px 5px;
  z-index: -1;
}
<div>Sometimes by losing a battle you find a new way to win the war.</div>
like image 150
Weafs.py Avatar answered Oct 23 '22 00:10

Weafs.py