Lombric
Lombric

Reputation: 840

Middle bottom box-shadow

I'm tying to create an H2 with a box-show below the bottom border

here is my "base" code :

<div class="bloc-principal">
<h2 id="toto">My H2</h2>
</div>
<style type="text/css">
   #toto{
     box-shadow: 0 4px 2px -2px gray;
    }
</style>

But i want to get this result : http://www.hostingpics.net/viewer.php?id=275479boxshadow.png

There are no border on the other side, just this little shadow on the middle of bottom side.

I tried to find tutorials but i didn't get the same result AT ALL....

Upvotes: 0

Views: 996

Answers (2)

jorisx
jorisx

Reputation: 11

Add a clipping to the shadow layer so you can make your box also semi transparant

#toto {
   position:relative;
   background: rgba(8,55,81,0.8);
   height:100px;
}

#toto:after {
   position: absolute;
   width: 90%;
   height: 5%;
   left: 5%;
   border-radius: 50%;
   z-index: -1;
   bottom: 0%;
   content: "";
   box-shadow: 0 4px 12px rgba(0,0,0,0.8);
   clip:rect(8px,auto,40px,auto);
}

Upvotes: 0

TreeTree
TreeTree

Reputation: 3230

I think a multi-color/fading shadow is beyond the capabilities of the box-shadow property. I used an absolute positioned element with that gradient and placed it on top of the text.

http://jsfiddle.net/efdJA/

#toto {
    position:relative;
    background-color:white;
    height:100px;
    border:1px solid red;
}

#toto:before {
background: rgb(255,255,255);
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2UyZTJlMiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left,  rgba(255,255,255,1) 0%, rgba(226,226,226,1) 50%, rgba(255,255,255,1) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,1)), color-stop(50%,rgba(226,226,226,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(226,226,226,1) 50%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(226,226,226,1) 50%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(226,226,226,1) 50%,rgba(255,255,255,1) 100%);
background: linear-gradient(to right,  rgba(255,255,255,1) 0%,rgba(226,226,226,1) 50%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ffffff',GradientType=1 );

    position:absolute;
    bottom:0;
    left:0;
    width:100%;
    height:10px;
    content:'';
}

Sorry for the horrendous background gibberish, I used the amazing CSS Gradient Generator.

Upvotes: 1

Related Questions