Jump to content

Selector syntax confusion


Lucy

Recommended Posts

I've got a class called .portfoliotext and have styled images inside that like so:

.portfoliotext img	{		max-width:80%;		border:.5rem #95B0B2 solid;		margin:3% auto 3% auto;		display:block;	}

I want the border colour (ONLY for hyperlinked images) to change on hover, which should be simple, but I don't think I'm getting the syntax right. Here's what I've tried:

.portfoliotext img a:hover	{		border:.5rem #FFFFFF solid;	}

and

.portfoliotext img:a:hover	{		border:.5rem #FFFFFF solid;	}

Help? :)

 

 

 

EDIT:

Okay, apparantly it needs to be

.portfoliotext a:hover img

Though I don't understand why. Surely

.portfoliotext img a:hover

Or similar, should mean hovered linked images within the div? :/

Edited by Lucy
Link to comment
Share on other sites

Selectors are ordered by the HTML tree.

This structure is ordered .portfoliotext a img

<div class="portfoliotext">    <a href="">        <img>    </a></div>

If you used the selector .portfoliotext img a

Then you're assuming a structure like this:

<div class="portfoliotext">    <img>        <a></a>    </img></div>

:hover is a pseudo-class that you can put on any element. a:hover checks that the mouse is over an <a> element, img:hover would check that the mouse is over an <img> element.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...