-2

I have a div with an image and a small favorites button over it that people can click, but I'd like it to show only if they :hover over the div. How would I do that?

The structure is like this:

<a href="">
  <li class="mainpage">
    <article class="item mainpage">
      <div class="image">
        <div class="favorites-button" style="display: none;"><span class="icon-fav"></span></div>
      </div>
    </article>
  </li>
</a>

So basically, when somebody does a :hover on <article class="item mainpage"> then the <div class="favorites-button"> should show.

user1227914
  • 3,446
  • 10
  • 42
  • 76
  • `.mainpage:hover .favorites-button { display: block; }` Really a simple search would have given you the answer. – TylerH Mar 11 '15 at 19:44

1 Answers1

0

Here is a pure CSS solution. Firstly you want to remove the style attribute from your favourites button as this will override any CSS applied.

<a href="">
    <li class="mainpage">
        <article class="item mainpage">
            <div class="image">
                <div class="favorites-button"><span class="icon-fav"></span></div>
            </div>
        </article>
    </li>
</a>

Then in your CSS by default hide the favourites button but display it when it is the child of a hovered parent element like so...

.favourites-button {
    display: none;
}

.item.mainpage:hover .favourites-button {
    display: block;
}

Hope that helps Dan

danbahrami
  • 1,014
  • 1
  • 9
  • 14