How to style a link with CSS to change border color of image, but not add border around text?

Brad Bansner
Brad Bansner used Ask the Experts™
on
I have CSS like this:

.videothumb{border:2px solid #2e2e2d;padding:4px;}
a.videolink,a.videolink:visited{color:#7d7c7b;text-decoration:none;}
a.videolink:hover{color:#7d7c7b;text-decoration:underline;border:2px solid #676765;}

Open in new window


My HTML link looks like this:

<a href="#"><img class="videothumb" src="img/img.jpg"><br />
Some text here</a>

Open in new window


So, I want a hover event to change the color of the border around the image but not add a border around the text part of the link, which is what it is doing currently.

I had also tried this:

.videothumb:hover{border:2px solid #676765}

Open in new window


That worked nicely for the image, but if you took the mouse off the image and just on the text part of the link, the border highlight would go away.

There must be some compromise between these two methods that will do what I want? Thank you!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kyle HamiltonData Scientist
Most Valuable Expert 2014

Commented:
give the link a class:
<a href="#" class="thumblink"><img class="videothumb" src="img/img.jpg"><br />
Some text here</a>

Open in new window


then in css:
.thumblink:hover .videothumb{border:2px solid #676765}

Open in new window




is this what you're looking for?
Brad BansnerWeb Developer

Author

Commented:
That didn't quite do it. Lets make this easier, here is my test page:
http://www.partnersdesign.net/lieverhymanpotter/videos.php

Here is the HTML and CSS I tried adding, based on your suggestion:

.videolink:hover{
		.videothumb{border:2px solid #676765;}
	}

<a class="videolink" href="videos.php?v=1"><img class="videothumb videospaceright" src="img/gr_video-1.jpg" width="149" height="84" border="0" /><br />
				John Badal speaks...</a>

Open in new window

Data Scientist
Most Valuable Expert 2014
Commented:
your style rule revised. it was incorrect.

.videolink:hover .videothumb{
   border:2px solid #676765;
      }

<a class="videolink" href="videos.php?v=1"><img class="videothumb videospaceright" src="img/gr_video-1.jpg" width="149" height="84" border="0" /><br />
                        John Badal speaks...</a>
Brad BansnerWeb Developer

Author

Commented:
Perfect, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial