4

I have this HTML Code

<a href="test.html">
<div class=" menubox mcolor1">
<h3>go to test page</h3>
</div>
</a>

and this is the css

.menubox {
    height: 150px;
    width: 100%;
    font-size: 14px;
    color: #777;
    margin: 0 0 0 0;
    padding: 0; 
    -moz-border-radius: 10px;
    border-radius: 10px; 
    position: relative;}

.mcolor1 { background: #3A89BF url(../images/prod2.png) no-repeat center center; }

on mouse hover this div, the text shows the hyperlink line, how can I hide it?

Robinlolo
  • 131
  • 1
  • 3
  • 10

3 Answers3

8

As others have suggested, it's easy to remove the underline from links. However, if you need to target just this specific link, try giving it a class. Example:

.no-underline:hover {
    text-decoration: none;
}
<a href="test.html" class="no-underline">
  <div class=" menubox mcolor1">
    <h3>go to test page</h3>
  </div>
</a>
John Slegers
  • 45,213
  • 22
  • 199
  • 169
Nix
  • 5,746
  • 4
  • 30
  • 51
2

If you want to remove the underline on hover, use this CSS:

a:hover {
   text-decoration: none;
}

Note :

Unless your page uses the HTML5 doctype (<!doctype html>), your HTML structure is invalid. Divs can't be nested inside a element before HMTL5.

Community
  • 1
  • 1
Morpheus
  • 8,829
  • 13
  • 51
  • 77
  • Thank you for your reply, But I can apply the href on the full div – Robinlolo Apr 23 '13 at 08:29
  • @Morpheus: They can in the current version of HTML (HTML5). Try it: http://validator.w3.org/ – Paul D. Waite Apr 23 '13 at 08:30
  • 1
    Actually, in HTML5, you may nest block elements inside links. If it's anything other than HTML5, like XHTML or whatever, then it will be invalid, yes. http://html5doctor.com/block-level-links-in-html-5/ – Nix Apr 23 '13 at 08:30
1

With the HTML as it stands, you can’t hide the link underline just for this link.

The following CSS will remove the underline for all links:

a:hover {
    text-decoration: none;
}

To remove it for just this link, you could move the link inside the <div>:

.menubox > a {
    display: block;
    height: 100%;
}

.menubox > a:hover {
    text-decoration: none;
}
<div class="menubox mcolor1">
    <a href="test.html">
        <h3>go to test page</h3>
    </a>
</div>
John Slegers
  • 45,213
  • 22
  • 199
  • 169
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270