Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Border and Events 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello, using CSS I'd like to turn on the Image border omMouseOver and turn it off when the mouse is no longer over the image?

How can I do this - what is the CSS syntax?

Thanks
 
this is done in CSS with a combination of JavaScript.
<html>
<head>
<title>CSS example</title>
<style>
.borderOn { border : 1px solid black ; }
.borderOff { border : none ; }
</style>
</head>
<body>

<table>
<tr>
<td class=borderOff onMouseOver=&quot;this.className='borderOn'&quot; onMouseOut=&quot;this.className='borderOff'&quot;>Put your mouse over me</td>
</tr>
</table>

</body>
</html>

I recommend however that you use this instead for the CSS :

.borderOn { border : 1px solid black ; }
.borderOff { border : 1px solid white ; }

Hope this helps. Gary Haran
 
It's possible to do without JavaScript, but support is spotty. The
Code:
:hover
pseudo-class is used like this:
Code:
<style type=&quot;text/css&quot;>
  .myImg
  {
    border:2px solid transparent;
  }
  .myImg:hover
  {
    border:2px solid blue;
  }
</style>
The only element that reliably supports the :hover pseudo-class is the <a> element, but if you're enclosing your <img> tag in a link, it should work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top