Search code examples
htmlcssanimationyui-pure-css

Slide down on pure css image


I would like to make an animation on my menu, instead of the fade animation that you can see on the fist two div, I would like to put as animation a slide down color. As a curtain.

On hover on the image, a "coloured panel" positioned on the image slide down on it. This is my menu:

@import url(http://fonts.googleapis.com/css?family=Lato:400,900);  /* <-- Just for the demo, Yes I like pretty fonts... */

.square {
    float:left;
    position: relative;
    width: 30%;
    padding-bottom : 30%; /* = width for a 1:1 aspect ratio */
    margin: 0;//1.66%;
    background-position:center center;
    background-repeat:no-repeat;
    background-size:cover; /* you change this to "contain" if you don't want the images to be cropped */
}

.img_1-1{background-image:url('https://farm4.staticflickr.com/3766/12953056854_b8cdf14f21.jpg');}
.img_1-2{background-image:url('https://farm7.staticflickr.com/6092/6227418584_d5883b0948.jpg');}
.img_1-3{background-image:url('https://farm8.staticflickr.com/7187/6895047173_d4b1a0d798.jpg');}

.img_2-1{background-image:url('https://farm8.staticflickr.com/7163/6822904141_50277565c3.jpg');}
.img_2-2{background-image:url('https://farm7.staticflickr.com/6139/5986939269_10721b8017.jpg');}
.img_2-3{background-image:url('https://farm4.staticflickr.com/3165/5733278274_2626612c70.jpg');}

.img_3-1{background-image:url('https://farm9.staticflickr.com/8429/7862595906_8f953fd25b.jpg');}
.img_3-2{background-image:url('https://farm7.staticflickr.com/6083/6055581292_d94c2d90e3.jpg');}
.img_3-3{background-image:url('https://farm4.staticflickr.com/3771/13199704015_72aa535bd7.jpg');}




/*  following just for the demo */


body {
    font-size:20px;
    font-family: 'Lato',verdana, sans-serif;
    color: #fff;
    text-align:center;
    background:#ECECEC;
}

#bottom {
    clear:both;
    margin:0 0;//1.66%;
    width:89.68%;
    padding: 0;//3.5%;
    background-color:#1E1E1E;
    color: #fff;
}
#bottom p{
    text-align:center;
    line-height:2em;
}
#bottom a{
    color: #000;
    text-decoration:none;
    border:1px solid #000;
    padding:10px 20px 12px;
    line-height:70px;
    background:#ccc;
    
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}



.fade {
   opacity: 1;
   transition: opacity .25s ease-in-out;
   -moz-transition: opacity .25s ease-in-out;
   -webkit-transition: opacity .25s ease-in-out;
   
   }

   .fade:hover {
      opacity: 0.5;
      } */
      
<div  class="square img_1-1 fade">
</div>

<div class="square img_1-2 fade">
</div>
<div class="square img_1-3 ">
</div>


<div class="square img_2-1 ">
</div>
<div class="square img_2-2 ">
</div>
<div class="square img_2-3 ">
</div>


<div class="square img_3-1 ">
</div>
<div class="square img_3-2 ">
</div>
<div class="square img_3-3 ">
</div>

This is the animation, but I can't figure out how to do this ON the image, just by hover. http://jsfiddle.net/gregmatys/4x9Tf/light/

Thank you in advance.


Solution

  • We need to put the image element right inside the #wrap div and right before the #slide div, then give the #wrap div a position:relative, this is necessary because we need to absolutely position position:absolute the #slider div and give position it to top 0 and left:0 so that it will be above the image and cover it.

    As in this JS Fiddle, add below code to #wrap and #slider:

    CSS:

    #wrap {
      position: relative;
    }
    #slider {
      position: absolute;
      top: 0;
      left: 0;
    }
    

    And change your div#wrap structure into this:

    <div id="wrap">
      <img src="//placehold.it/200x200?text=IMG">
      <div id="slider">
        <p>Blah blah blah blah blah....</p>
      </div>
    </div>