0

I am building new website and I've run into a little problem. When I added <a href="about.php"> next to my div and </a> after the div end, but the hover does not work on the div. When I delete <a href"about.php"> and </a> the hover works.

Here is HTML code:

<div id="centerbox">
    <div class="profile"></div>
        <a style="display:block" href="about.php"><div class="about"></div></a>
     </div>
</div>

And here is CSS Code

#centerbox {
    width:988px;
    height:462px;
    margin-top:8.7%;
    margin-right:auto;
    margin-left:auto;
}

.about {
    width: 150px;
    height: 150px;
    display: block;
    margin-left:15.8%;
    margin-top:-150px;
    background:url(/images/about1.png);
    background-repeat:no-repeat;
}
brenjt
  • 15,997
  • 13
  • 77
  • 118

4 Answers4

1

This problem is that the div is a block element and the a tag is an inline element. A block element cannot go inside of an inline. You'll need to change your <div> to a <span> or something that is inline.

When an block element is inside the inline the browser will usually try to fix it by moving it out of the inline element.

If you need the effect of the block element on say the <span> mentioned above you could add display:block to the span.

See this post for further clarification

Community
  • 1
  • 1
brenjt
  • 15,997
  • 13
  • 77
  • 118
0

Make the .hover on your (a) tag rather then the class you are applying it to that should probably work :)

RyanM
  • 751
  • 5
  • 20
0

I solved it. I changed the <a style="display:block" href="about.php"><div class="about"></div></a> to <div class="about" onclick="window.location = 'about.php';">

-1

You don't want to store a div inside of an ref tag. You can give that ref tag a class though which will give it styling for that class

pwilmot
  • 586
  • 2
  • 8