How to stop shadow effect from moving using pure css?


Tags: html,css

Problem :

I have a hover effect on an image, in which 'floats' upwards on hover.

However, I've been trying to implement it in such a way that the shadow remains static during this hover effect (i.e. make the image look like it's hovering off the ground.

So far my jsfiddle looks like this.

It's using the

-webkit-box-shadow: 0px 0px 8px 2px #000000;
   -moz-box-shadow: 0px 0px 8px 2px #000000;
        box-shadow: 0px 0px 8px 2px #000000;

in order to generate the shadow.

So, the image should look like (when unhovered):

+------+
|      |
|      |
+------+
________     <-- shadow/hover

                                                 /\
Hovered:                                        /||\
                                                 ||
                                                 ||
+------+                                         ||
|      |                                     floor level
|      |                                         ||
+------+                                         ||
                                                \||/
 ______      <-- shadow/hover                    \/

   ^
   |

the shadow should also 'shink' in size (but that shouldn't be too bad to implement.

So the 'shadow' shouldn't move, and the img should raise.

.threeWidget {
  float: left;
  width: 30%;
  height: 25%;
  background-color: AppWorkspace;
  margin: 2px;
}
.topMenImg {
  transition: 0.5s;
}
.topMenImg:hover {
  -moz-transform: translate(0, -8px);
  -ms-transform: translate(0, -8px);
  -o-transform: translate(0, -8px);
  -webkit-transform: translate(0, -8px);
  transform: translate(0, -8px);
  -webkit-transform: translateY(-10px);
  transform: translateY(-10px);
}
.TopMenu {
  background-color: #808080;
  border-style: inset solid;
  border-width: 5px;
}
.topMenImg:hover::after {
  content: "";
  -webkit-transform: translateY(10px);
  transform: translateY(10px);
  width: 100%;
  display: block;
  position: absolute;
  z-index: -1;
  -webkit-box-shadow: 0px 0px 8px 2px #000000;
  -moz-box-shadow: 0px 0px 8px 2px #000000;
  box-shadow: 0px 0px 8px 2px #000000;
}
.topMenImg::after {
  -webkit-transform: translateY(10px);
  transform: translateY(10px);
  -webkit-box-shadow: 0px 0px 8px 2px #000000;
  -moz-box-shadow: 0px 0px 8px 2px #000000;
  box-shadow: 0px 0px 8px 2px #000000;
}
<div class="topMenImg" style="float:left ;margin-left:8%">
  <img src="http://www.clker.com/cliparts/a/1/8/b/1264830175321493735blue-marble-globe-md.png" />
</div>

Any help would be much appreciated.

As you can tell, i'm not css genius, but I have dreams :)

Edit

Something like the Floating shadow shown here is what i'm looking/aiming for



Solution :

input[type="text"], input[type="button"], .search{
border-radius: 40px 40px 40px 40px;
-moz-border-radius: 40px 40px 40px 40px;
-webkit-border-radius: 40px 40px 40px 40px;
padding-left:2px;
}

input[type="button"]:hover, input[type="text"]:focus,input[type="text"] {
    -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3), inset 0px 1px 2px rgba(0, 0, 0, 0.3), 0 0 5px 1px rgba(16, 216, 252, 0.8);
  -moz-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3), inset 0px 1px 2px rgba(0, 0, 0, 0.3), 0 0 5px 1px rgba(16, 216, 252, 0.8);
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3), inset 0px 1px 2px rgba(0, 0, 0, 0.3), 0 0 5px 1px rgba(16, 216, 252, 0.8);
}



.TopMenu{
    width:100%;
   background-color:darkgray;

   -webkit-box-shadow: inset 0px 0px 131px 25px rgba(0,0,0,0.55);
-moz-box-shadow: inset 0px 0px 131px 25px rgba(0,0,0,0.55);
box-shadow: inset 0px 0px 131px 25px rgba(0,0,0,0.55);

float:left;
border-radius: 40px 40px 40px 40px;
-moz-border-radius: 40px 40px 40px 40px;
-webkit-border-radius: 40px 40px 40px 40px;
}

.search {
margin-right:2%;
width:auto;
margin-left:0;
display:flexbox;
margin:auto;
}
.searchTextBox{
    width:auto;
    overflow:hidden;
    clear:both;
}
.searchButtonSubmit{
    width:auto;
    margin-right:1%;
    clear:both;
    overflow:hidden;
}

.topMenuImg{
    margin-left:5%;
    float:left;
    transition: 0.2s;
    position: relative;
    display:table-cell;
    z-index:10;
}

.topMenuImg:first-child{
    margin-left:20%;
}

.topMenuImg:hover{
     -moz-transform: translate(0, -8px);
    -ms-transform: translate(0, -8px);
    -o-transform: translate(0, -8px);
    -webkit-transform: translate(0, -8px);
    transform: translate(0, -8px);
    -webkit-transform: translateY(-10px);
    transform: translateY(-10px);
}

.topMenuImg:after{ /*This is the shadow effect*/
        content: '';
    position: absolute;
    bottom: -1%;
    left: 3%;
    z-index:0;
    width: 90%;
    height: 8%;

    border-radius: 50%;
    box-shadow: 0px 10px 0px rgba(14, 14, 14, 0.10);
        transition: 0.2s;
         -moz-transform: translate(0, -8px);
    -ms-transform: translate(0, -8px);
    -o-transform: translate(0, -8px);
    -webkit-transform: translate(0, -8px);
    transform: translate(0, -8px);
    -webkit-transform: translateY(-10px);
    transform: translateY(-10px);
      box-shadow: 0px 10px 0px rgba(14, 14, 14, 0.80);
}
    
.topMenuImg:hover:after{ /*Also shadow effect*/
          content: '';
    position: absolute;
    z-index:0;
    bottom: 0%;
    left: 18%;
    width: 60%;
    height: 8%;
    border-radius: 50%;
  box-shadow: 0px 10px 0px rgba(14, 14, 14, 0.40);
  transform: scale(0.2);

    -moz-transform: translate(0, 4px);
    -ms-transform: translate(0, 4px);
    -o-transform: translate(0, 4px);
    -webkit-transform: translate(0, 4px);
    transform: translate(0, 4px);
    -webkit-transform: translateY(0px);
    transform: translateY(0px);

}
  <div id="TopMenu" class="">
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Add.png" /></div>
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Delete.png" /></div>
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Edit.png" /></div>
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Save.png" /></div>
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Print.png" /></div>
                        <div class="topMenuImg"><img src="~/Content/Images/TopMenu/Search.png" /></div>
                    </div>

I managed to edit my css (quite a bit) of fiddling with a LOT of the values, finally coming up with this:

In terms of the example fiddle, I have altered it to become this


    CSS Howto..

    How to align div elements while using css tables

    How to add physics to CSS animations?

    How do you tell which css class to modify?[Example inside]

    How to select attribute value for a selected element with wombat

    How to avoid overlapping text using CSS?

    How to convert template from table to div

    How to fit img into div circle ?

    How to center my navigation using .css

    How can I modify a CSS class using JavaScript?

    CSS Help - How can a DIV ignore css previously set on the page?

    Slideshow with specific Text on each Image

    How to only make the text of a link go down by 1px when active and not the whole line/paragraph?

    How to use CSS property position:fixed with top:50px and height:100%?

    How can I get two buttons and textareas from separate forms to display inline?

    How to get the position of element transformed with css rotate

    How to overlay a play button over a YouTube thumbnail image

    CSS Overflow: overlay. Is it deprecated? How can I replace it?

    How to partly color the border with css [closed]

    Visual studio 2013 crash when editing a css file. How do I troubleshoot?

    How to persist checking the screen width in Javascript

    how to identify if a css class has property in extjs

    How to move “+” to right i n css?

    how to reduce the size of all component in sencha application

    How to CSS two vertical cylinders

    how to give margin between li using css?

    Hover img to show an absolutely positioned div isn't working

    How to create automatic image gallery slideshow by using HTML,CSS and JavaScript

    How to prevent the background image from getting blurry

    How do I wrap several buttons inside a TD element

    How to detect whether a browser has tap highlighting?