Search code examples
htmlcsshovermousehover

How to align object below hovered menu


Under my posts I have a read more button along with a few buttons. My last button is a social share button, and when you hover over it a social share menu appears below it. The problem is that the buttons are all aligned next to each other which I want, however when you hover over the share button the share button moves up and the social share menu appears aligned with the other buttons. How could I make it so that the social share menu appears below all of the buttons and my share button always stays aligned with the other buttons? Thanks in advance. Here is a fiddle - https://jsfiddle.net/5mgoktLs/2/

*I also want the share menu to be centered under the share button

Buttons before hover...

enter image description here

when you hover over the share button... ( I want the share button to always stay aligned with the other buttons)

enter image description here

html

    <img class="abother-reply" src="http://amandoblogs.com/wp-content/uploads/2014/08/share-e1408475480528.png" />
  <img class="reply" src="http://amandoblogs.com/wp-content/uploads/2014/08/share-e1408475480528.png" />
<div class="wrap">

  <img class="main-share button" src="http://amandoblogs.com/wp-content/uploads/2014/08/share-e1408475480528.png" />

  <div class="share-buttons">

    <a href="http://twitter.com/home/?status=Love this post by @ <?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="https://www.theclimategroup.org/sites/all/modules/custom/tcg_social_media_icons/icons/black/16x16/twitter.png"></a>

    <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
      <img src="http://www.shipwreckmuseum.com/wp-content/themes/shipwreckmuseum/assets/facebook-icon.png" alt="Facebook" />
    </a>

    <a href="javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());">
      <img src="https://lh4.googleusercontent.com/-FaD4j4FL1Bc/TuEf9aN1gEI/AAAAAAAABek/kVqztZRwJ1w/s128/Pinterest_Favicon.png" alt="Pinterest" />
    </a>

    <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
      <img src="http://www.ihatestevensinger.com/osafe_theme/images/user_content/images/icon-heart.png" alt="Heart" />
    </a>

  </div>
</div>

css

.wrap:hover .share-buttons {
  display:block;
}
.share-buttons {
  display: none;
    letter-spacing: 5px;
}
.wrap {
    display: inline-block;
}
.reply {
    display: inline-block;
}
.another-reply {
    display: inline-block;
}


Solution

  • This fixed it for me:

    .wrap:hover .share-buttons {
      display:block;
      position: absolute;
    }
    

    Updated: If you want it centered, this is a bit hacky but it works!

    .wrap:hover .share-buttons {
     display: block;
     position: absolute;
     top: 50%;
     left: 50%;
     transform: translate(-50%, 30%);
     white-space: nowrap;
    }
    
    .wrap {
     position: relative;
     display: inline-block;
    }